Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
Magisk
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Magisk
Commits
bc576a96
Commit
bc576a96
authored
Jun 07, 2017
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update uninstall script
parent
19e407fc
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
70 additions
and
49 deletions
+70
-49
magisk_uninstaller.sh
app/src/main/assets/magisk_uninstaller.sh
+70
-49
No files found.
app/src/main/assets/magisk_uninstaller.sh
View file @
bc576a96
[
-z
$BOOTMODE
]
&&
BOOTMODE
=
false
#!/system/bin/sh
##########################################################################################
#
# Magisk Uninstaller
# by topjohnwu
#
# This script can be placed in /cache/magisk_uninstaller.sh
# The Magisk main binary will pick up the script, and uninstall itself, following a reboot
# This script can also be used in flashable zip with the uninstaller_loader.sh
#
# This script will try to do restoration in the following order:
# 1. Find and restore the original stock boot image dump (OTA proof)
# 2. Restore ramdisk from the internal backup (ramdisk fully restored, not OTA friendly)
# 3. Remove added files in ramdisk, modified files are remained intact. By doing so, Magisk
# will not be started at boot, but not removed clean enough
#
# Finally, this uninstaller will remove all Magisk related files
# (The list is LARGE, most likely due to bad decision in early versions
# the latest versions has much less bloat to cleanup)
#
##########################################################################################
# This path should work in any cases
[
-z
$BOOTMODE
]
&&
BOOTMODE
=
false
TMPDIR
=
/dev/tmp
BOOTTMP
=
$TMPDIR
/boottmp
MAGISKBIN
=
/data/magisk
MAGISKBIN
=
/data/magisk
CHROMEDIR
=
$MAGISKBIN
/chromeos
CHROMEDIR
=
$MAGISKBIN
/chromeos
SYSTEMLIB
=
/system/lib
[
-d
/system/lib64
]
&&
SYSTEMLIB
=
/system/lib64
||
SYSTEMLIB
=
/system/lib
[
-d
/system/lib64
]
&&
SYSTEMLIB
=
/system/lib64
# Default permissions
# Default permissions
umask
022
umask
022
ui_print_wrapper
()
{
# Call ui_print_wrap if exists, or else simply use echo
type
ui_print
>
/dev/null
&&
ui_print
"
$1
"
||
echo
"
$1
"
# Useful when wrapped in flashable zip
ui_print_wrap
()
{
type
ui_print
>
/dev/null 2>&1
&&
ui_print
"
$1
"
||
echo
"
$1
"
}
}
grep_prop
()
{
grep_prop
()
{
...
@@ -44,90 +64,91 @@ find_boot_image() {
...
@@ -44,90 +64,91 @@ find_boot_image() {
# Environments
# Environments
# Set permissions
# Set permissions
chmod
-R
755
$CHROMEDIR
/futility
$MAGISKBIN
2>/dev/null
chmod
-R
755
$CHROMEDIR
/futility
$MAGISKBIN
2>/dev/null
# Temporary busybox for installation
mkdir
-p
$TMPDIR
/busybox
$MAGISKBIN
/busybox
--install
-s
$TMPDIR
/busybox
rm
-f
$TMPDIR
/busybox/su
$TMPDIR
/busybox/sh
$TMPDIR
/busybox/reboot
PATH
=
$TMPDIR
/busybox:
$PATH
# Find the boot image
# Find the boot image
find_boot_image
find_boot_image
if
[
-z
"
$BOOTIMAGE
"
]
;
then
if
[
-z
"
$BOOTIMAGE
"
]
;
then
ui_print_wrap
per
"! Unable to detect boot image"
ui_print_wrap
"! Unable to detect boot image"
exit
1
exit
1
fi
fi
ui_print_wrap
per
"- Found Boot Image:
$BOOTIMAGE
"
ui_print_wrap
"- Found Boot Image:
$BOOTIMAGE
"
rm
-rf
$BOOTTMP
2>/dev/null
cd
$MAGISKBIN
mkdir
-p
$BOOTTMP
cd
$BOOTTMP
ui_print_wrap
per
"- Unpacking boot image"
ui_print_wrap
"- Unpacking boot image"
LD_LIBRARY_PATH
=
$SYSTEMLIB
$MAGISKBIN
/magiskboot
--unpack
$BOOTIMAGE
LD_LIBRARY_PATH
=
$SYSTEMLIB
.
/magiskboot
--unpack
$BOOTIMAGE
if
[
$?
-ne
0
]
;
then
if
[
$?
-ne
0
]
;
then
ui_print_wrap
per
"! Unable to unpack boot image"
ui_print_wrap
"! Unable to unpack boot image"
exit
1
exit
1
fi
fi
# Update our previous backup to new format if exists
# Update our previous backup
s
to new format if exists
if
[
-f
/data/stock_boot.img
]
;
then
if
[
-f
/data/stock_boot.img
]
;
then
SHA1
=
`
LD_LIBRARY_PATH
=
$SYSTEMLIB
$MAGISKBIN
/magiskboot
--sha1
/data/stock_boot.img |
tail
-n
1
`
SHA1
=
`
LD_LIBRARY_PATH
=
$SYSTEMLIB
.
/magiskboot
--sha1
/data/stock_boot.img |
tail
-n
1
`
STOCKDUMP
=
/data/stock_boot_
${
SHA1
}
.img
STOCKDUMP
=
/data/stock_boot_
${
SHA1
}
.img
mv
/data/stock_boot.img
$STOCKDUMP
mv
/data/stock_boot.img
$STOCKDUMP
LD_LIBRARY_PATH
=
$SYSTEMLIB
$MAGISKBIN
/magiskboot
--compress
$STOCKDUMP
LD_LIBRARY_PATH
=
$SYSTEMLIB
.
/magiskboot
--compress
$STOCKDUMP
fi
fi
# Detect boot image state
# Detect boot image state
LD_LIBRARY_PATH
=
$SYSTEMLIB
$MAGISKBIN
/magiskboot
--cpio-test
ramdisk.cpio
LD_LIBRARY_PATH
=
$SYSTEMLIB
.
/magiskboot
--cpio-test
ramdisk.cpio
case
$?
in
case
$?
in
0
)
0
)
ui_print_wrap
per
"! Magisk is not install
ed!"
ui_print_wrap
"- Stock boot image detect
ed!"
ui_print_wrap
per
"! Nothing to uninstall
"
ui_print_wrap
"! Magisk is not installed!
"
exit
exit
;;
;;
1
)
1
)
ui_print_wrap
"- Magisk patched image detected!"
# Find SHA1 of stock boot image
# Find SHA1 of stock boot image
if
[
-z
$SHA1
]
;
then
if
[
-z
$SHA1
]
;
then
LD_LIBRARY_PATH
=
$SYSTEMLIB
$MAGISKBIN
/magiskboot
--cpio-extract
ramdisk.cpio init.magisk.rc init.magisk.rc
LD_LIBRARY_PATH
=
$SYSTEMLIB
./magiskboot
--cpio-extract
ramdisk.cpio init.magisk.rc init.magisk.rc.old
SHA1
=
`
grep_prop
"# STOCKSHA1"
init.magisk.rc
`
SHA1
=
`
grep_prop
"# STOCKSHA1"
init.magisk.rc
.old
`
[
!
-z
$SHA1
]
&&
STOCKDUMP
=
/data/stock_boot_
${
SHA1
}
.img
[
!
-z
$SHA1
]
&&
STOCKDUMP
=
/data/stock_boot_
${
SHA1
}
.img
rm
-f
init.magisk.rc
rm
-f
init.magisk.rc
.old
fi
fi
if
[
-f
${
STOCKDUMP
}
.gz
]
;
then
if
[
-f
${
STOCKDUMP
}
.gz
]
;
then
ui_print_wrap
per
"- Boot image backup found!"
ui_print_wrap
"- Boot image backup found!"
LD_LIBRARY_PATH
=
$SYSTEMLIB
$MAGISKBIN
/magiskboot
--decompress
${
STOCKDUMP
}
.gz stock_boot.img
LD_LIBRARY_PATH
=
$SYSTEMLIB
.
/magiskboot
--decompress
${
STOCKDUMP
}
.gz stock_boot.img
else
else
ui_print_wrap
per
"! Boot image backup unavailable"
ui_print_wrap
"! Boot image backup unavailable"
ui_print_wrap
per
"- Restoring ramdisk with backup"
ui_print_wrap
"- Restoring ramdisk with backup"
LD_LIBRARY_PATH
=
$SYSTEMLIB
$MAGISKBIN
/magiskboot
--cpio-restore
ramdisk.cpio
LD_LIBRARY_PATH
=
$SYSTEMLIB
.
/magiskboot
--cpio-restore
ramdisk.cpio
LD_LIBRARY_PATH
=
$SYSTEMLIB
$MAGISKBIN
/magiskboot
--repack
$BOOTIMAGE
stock_boot.img
LD_LIBRARY_PATH
=
$SYSTEMLIB
.
/magiskboot
--repack
$BOOTIMAGE
stock_boot.img
fi
fi
;;
;;
2
)
2
)
# Other patched
ui_print_wrapper
"- SuperSU patched image detected
"
ui_print_wrap
"! Boot image patched by other programs!
"
LD_LIBRARY_PATH
=
$SYSTEMLIB
$MAGISKBIN
/magiskboot
--cpio-restore
ramdisk.cpio
ui_print_wrap
"! Cannot uninstall with this uninstaller"
LD_LIBRARY_PATH
=
$SYSTEMLIB
$MAGISKBIN
/magiskboot
--repack
$BOOTIMAGE
stock_boot.img
exit
1
;;
;;
esac
esac
# Sign chromeos boot
# Sign chromeos boot
if
[
-f
chromeos
]
;
then
if
[
-f
chromeos
]
;
then
echo
>
config
echo
>
empty
echo
>
bootloader
LD_LIBRARY_PATH
=
$SYSTEMLIB
$CHROMEDIR
/futility vbutil_kernel
--pack
stock_boot.img.signed
--keyblock
$CHROMEDIR
/kernel.keyblock
--signprivate
$CHROMEDIR
/kernel_data_key.vbprivk
--version
1
--vmlinuz
stock_boot.img
--config
config
--arch
arm
--bootloader
bootloader
--flags
0x1
LD_LIBRARY_PATH
=
$SYSTEMLIB
$CHROMEDIR
/futility vbutil_kernel
--pack
stock_boot.img.signed
\
rm
-f
stock_boot.img
--keyblock
$CHROMEDIR
/kernel.keyblock
--signprivate
$CHROMEDIR
/kernel_data_key.vbprivk
\
--version
1
--vmlinuz
stock_boot.img
--config
empty
--arch
arm
--bootloader
empty
--flags
0x1
rm
-f
empty stock_boot.img
mv
stock_boot.img.signed stock_boot.img
mv
stock_boot.img.signed stock_boot.img
fi
fi
ui_print_wrapper
"- Flashing stock/reverted image"
ui_print_wrap
"- Flashing stock/reverted image"
[
!
-L
"
$BOOTIMAGE
"
]
&&
dd
if
=
/dev/zero
of
=
$BOOTIMAGE
bs
=
4096 2>/dev/null
if
[
-L
$BOOTIMAGE
]
;
then
dd
if
=
stock_boot.img
of
=
$BOOTIMAGE
bs
=
4096
dd
if
=
stock_boot.img
of
=
$BOOTIMAGE
bs
=
4096
else
cat
stock_boot.img /dev/zero |
dd
of
=
$BOOTIMAGE
bs
=
4096
fi
rm
-f
stock_boot.img
ui_print_wrap
per
"- Removing Magisk files"
ui_print_wrap
"- Removing Magisk files"
rm
-rf
/cache/magisk.log /cache/last_magisk.log /cache/magiskhide.log /cache/.disable_magisk
\
rm
-rf
/cache/magisk.log /cache/last_magisk.log /cache/magiskhide.log /cache/.disable_magisk
\
/cache/magisk /cache/magisk_merge /cache/magisk_mount /cache/unblock /cache/magisk_uninstaller.sh
\
/cache/magisk /cache/magisk_merge /cache/magisk_mount /cache/unblock /cache/magisk_uninstaller.sh
\
/data/Magisk.apk /data/magisk.apk /data/magisk.img /data/magisk_merge.img
\
/data/Magisk.apk /data/magisk.apk /data/magisk.img /data/magisk_merge.img
/data/magisk_debug.log
\
/data/busybox /data/magisk /data/custom_ramdisk_patch.sh 2>/dev/null
/data/busybox /data/magisk /data/custom_ramdisk_patch.sh 2>/dev/null
$BOOTMODE
&&
reboot
$BOOTMODE
&&
reboot
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment