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
2a86bc86
Commit
2a86bc86
authored
Jun 24, 2017
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update scripts
parent
04538372
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
74 additions
and
82 deletions
+74
-82
addon.d.sh
scripts/addon.d.sh
+3
-9
boot_patch.sh
scripts/boot_patch.sh
+41
-20
flash_script.sh
scripts/flash_script.sh
+21
-30
util_functions.sh
scripts/util_functions.sh
+9
-23
No files found.
scripts/addon.d.sh
View file @
2a86bc86
...
@@ -20,6 +20,7 @@ main() {
...
@@ -20,6 +20,7 @@ main() {
sleep
5
sleep
5
mount
-o
ro /system 2>/dev/null
mount
-o
ro /system 2>/dev/null
mount
-o
ro /vendor 2>/dev/null
mount /data 2>/dev/null
mount /data 2>/dev/null
if
[
!
-d
$MAGISKBIN
]
;
then
if
[
!
-d
$MAGISKBIN
]
;
then
...
@@ -36,14 +37,7 @@ main() {
...
@@ -36,14 +37,7 @@ main() {
ui_print
"* MAGISK_VERSION_STUB"
ui_print
"* MAGISK_VERSION_STUB"
ui_print
"************************"
ui_print
"************************"
# Check if system root is installed and remove
recovery_actions
remove_system_su
# Prefer bin in /system
export
PATH
=
/system/bin:/system/xbin
# Clear out possible lib paths, let the binary find them itself
export
LD_LIBRARY_PATH
=
# Temporarily block out all custom recovery binaries/libs
mv
/sbin /sbin_tmp
find_boot_image
find_boot_image
[
-z
$BOOTIMAGE
]
&&
abort
"! Unable to detect boot image"
[
-z
$BOOTIMAGE
]
&&
abort
"! Unable to detect boot image"
...
@@ -53,7 +47,7 @@ main() {
...
@@ -53,7 +47,7 @@ main() {
cd
$MAGISKBIN
cd
$MAGISKBIN
# Source the boot patcher
# Source the boot patcher
.
$MAGISKBIN
/boot_patch.sh
$BOOTIMAGE
.
$MAGISKBIN
/boot_patch.sh
"
$BOOTIMAGE
"
[
-f
stock_boot
*
]
&&
rm
-f
/data/stock_boot
*
2>/dev/null
[
-f
stock_boot
*
]
&&
rm
-f
/data/stock_boot
*
2>/dev/null
...
...
scripts/boot_patch.sh
View file @
2a86bc86
...
@@ -23,24 +23,9 @@
...
@@ -23,24 +23,9 @@
# image placed under /data we've created when previously installing
# image placed under /data we've created when previously installing
#
#
##########################################################################################
##########################################################################################
##########################################################################################
# Workaround for getting the full path of BOOTIMAGE
# Functions
CWD
=
`
pwd
`
##########################################################################################
cd
`
dirname
$1
`
BOOTIMAGE
=
"
`
pwd
`
/
`
basename
$1
`
"
cd
"
$CWD
"
if
[
-z
"
$BOOTIMAGE
"
]
;
then
ui_print_wrap
"This script requires a boot image as a parameter"
exit
1
fi
# Presets
[
-z
$KEEPVERITY
]
&&
KEEPVERITY
=
false
[
-z
$KEEPFORCEENCRYPT
]
&&
KEEPFORCEENCRYPT
=
false
# Detect whether running as root
[
`
id
-u
`
-eq
0
]
&&
ROOT
=
true
||
ROOT
=
false
# Call ui_print_wrap if exists, or else simply use echo
# Call ui_print_wrap if exists, or else simply use echo
# Useful when wrapped in flashable zip
# Useful when wrapped in flashable zip
...
@@ -60,6 +45,21 @@ abort_wrap() {
...
@@ -60,6 +45,21 @@ abort_wrap() {
fi
fi
}
}
# Pure bash dirname implementation
dirname_wrap
()
{
if
echo
$1
|
grep
"/"
>
/dev/null 2>&1
;
then
RES
=
${
1
%/*
}
[
-z
$RES
]
&&
echo
"/"
||
echo
$RES
else
echo
"."
fi
}
# Pure bash basename implementation
basename_wrap
()
{
echo
${
1
##*/
}
}
grep_prop
()
{
grep_prop
()
{
REGEX
=
"s/^
$1
=//p"
REGEX
=
"s/^
$1
=//p"
shift
shift
...
@@ -86,13 +86,34 @@ cpio_mkdir() {
...
@@ -86,13 +86,34 @@ cpio_mkdir() {
}
}
##########################################################################################
##########################################################################################
#
Prework
#
Initialization
##########################################################################################
##########################################################################################
CWD
=
`
pwd
`
cd
"
`
dirname_wrap
$1
`
"
BOOTIMAGE
=
"
`
pwd
`
/
`
basename_wrap
$1
`
"
cd
"
$CWD
"
if
[
-z
"
$BOOTIMAGE
"
]
;
then
ui_print_wrap
"This script requires a boot image as a parameter"
exit
1
fi
# Presets
[
-z
$KEEPVERITY
]
&&
KEEPVERITY
=
false
[
-z
$KEEPFORCEENCRYPT
]
&&
KEEPFORCEENCRYPT
=
false
# Detect whether running as root
[
`
id
-u
`
-eq
0
]
&&
ROOT
=
true
||
ROOT
=
false
# Switch to the location of the script file
# Switch to the location of the script file
[
-z
$SOURCEDMODE
]
&&
cd
"
`
dirname
"
${
BASH_SOURCE
:-
$0
}
"
`
"
[
-z
$SOURCEDMODE
]
&&
cd
"
`
dirname
_wrap
"
${
BASH_SOURCE
:-
$0
}
"
`
"
chmod
+x ./
*
chmod
+x ./
*
##########################################################################################
# Unpack
##########################################################################################
ui_print_wrap
"- Unpacking boot image"
ui_print_wrap
"- Unpacking boot image"
./magiskboot
--unpack
"
$BOOTIMAGE
"
./magiskboot
--unpack
"
$BOOTIMAGE
"
...
...
scripts/flash_script.sh
View file @
2a86bc86
...
@@ -17,7 +17,6 @@ $BOOTMODE || ps -A 2>/dev/null | grep zygote | grep -v grep >/dev/null && BOOTMO
...
@@ -17,7 +17,6 @@ $BOOTMODE || ps -A 2>/dev/null | grep zygote | grep -v grep >/dev/null && BOOTMO
TMPDIR
=
/dev/tmp
TMPDIR
=
/dev/tmp
INSTALLER
=
$TMPDIR
/magisk
INSTALLER
=
$TMPDIR
/magisk
BUSYBOX
=
$TMPDIR
/busybox
COMMONDIR
=
$INSTALLER
/common
COMMONDIR
=
$INSTALLER
/common
CHROMEDIR
=
$INSTALLER
/chromeos
CHROMEDIR
=
$INSTALLER
/chromeos
COREDIR
=
/magisk/.core
COREDIR
=
/magisk/.core
...
@@ -49,13 +48,18 @@ if [ "$?" -eq "0" ]; then
...
@@ -49,13 +48,18 @@ if [ "$?" -eq "0" ]; then
fi
fi
rm
-rf
$TMPDIR
2>/dev/null
rm
-rf
$TMPDIR
2>/dev/null
mkdir
-p
$INSTALLER
$BUSYBOX
mkdir
-p
$INSTALLER
unzip
-o
"
$ZIP
"
-d
$INSTALLER
unzip
-o
"
$ZIP
"
-d
$INSTALLER
##########################################################################################
##########################################################################################
# Detection
# Detection
##########################################################################################
##########################################################################################
if
[
!
-d
"
$COMMONDIR
"
]
;
then
echo
"! Unable to extract zip file!"
exit
1
fi
# Load all fuctions
# Load all fuctions
.
$COMMONDIR
/util_functions.sh
.
$COMMONDIR
/util_functions.sh
...
@@ -63,10 +67,9 @@ ui_print "************************"
...
@@ -63,10 +67,9 @@ ui_print "************************"
ui_print
"* MAGISK_VERSION_STUB"
ui_print
"* MAGISK_VERSION_STUB"
ui_print
"************************"
ui_print
"************************"
[
-d
"
$COMMONDIR
"
]
||
abort
"! Unable to extract zip file!"
ui_print
"- Mounting /system(ro), /vendor(ro), /cache, /data"
ui_print
"- Mounting /system(ro), /cache, /data"
mount
-o
ro /system 2>/dev/null
mount
-o
ro /system 2>/dev/null
mount
-o
ro /vendor 2>/dev/null
mount /cache 2>/dev/null
mount /cache 2>/dev/null
mount /data 2>/dev/null
mount /data 2>/dev/null
...
@@ -87,10 +90,10 @@ ABILONG=`grep_prop ro.product.cpu.abi`
...
@@ -87,10 +90,10 @@ ABILONG=`grep_prop ro.product.cpu.abi`
ARCH
=
arm
ARCH
=
arm
BBPATH
=
armeabi-v7a
BBPATH
=
armeabi-v7a
if
[
"
$ABI
"
=
"x86"
]
;
then
ARCH
=
x86
;
BBPATH
=
x86
;
fi
;
if
[
"
$ABI
"
=
"x86"
]
;
then
ARCH
=
x86
;
fi
;
if
[
"
$ABI2
"
=
"x86"
]
;
then
ARCH
=
x86
;
BBPATH
=
x86
;
fi
;
if
[
"
$ABI2
"
=
"x86"
]
;
then
ARCH
=
x86
;
fi
;
if
[
"
$ABILONG
"
=
"arm64-v8a"
]
;
then
ARCH
=
arm64
;
fi
;
if
[
"
$ABILONG
"
=
"arm64-v8a"
]
;
then
ARCH
=
arm64
;
fi
;
if
[
"
$ABILONG
"
=
"x86_64"
]
;
then
ARCH
=
x64
;
BBPATH
=
x86
;
fi
;
if
[
"
$ABILONG
"
=
"x86_64"
]
;
then
ARCH
=
x64
;
fi
;
[
$API
-lt
21
]
&&
abort
"! Magisk is only for Lollipop 5.0+ (SDK 21+)"
[
$API
-lt
21
]
&&
abort
"! Magisk is only for Lollipop 5.0+ (SDK 21+)"
...
@@ -108,22 +111,8 @@ find_boot_image
...
@@ -108,22 +111,8 @@ find_boot_image
ui_print
"- Constructing environment"
ui_print
"- Constructing environment"
if
!
$BOOTMODE
;
then
$BOOTMODE
||
recovery_actions
# We are in custom recovery, don't trust anything in recovery, use those in /system
# Extract busybox from Magisk Manager, it's pure static binary so there will be no issues
unzip
-o
$COMMONDIR
/magisk.apk lib/
$BBPATH
/libbusybox.so
-d
$BUSYBOX
mv
$BUSYBOX
/lib/
*
/libbusybox.so
$BUSYBOX
/busybox
rm
-rf
$BUSYBOX
/lib
chmod
+x
$BUSYBOX
/busybox
$BUSYBOX
/busybox
--install
-s
$BUSYBOX
# Prefer bin in /system, fallback to bundled busybox if a tool doesn't exist
export
PATH
=
/system/bin:/system/xbin:
$BUSYBOX
# Clear out possible lib paths, let the binary find them itself
export
LD_LIBRARY_PATH
=
# Temporarily block out all custom recovery binaries/libs
mv
/sbin /sbin_tmp
fi
is_mounted /data
&&
MAGISKBIN
=
/data/magisk
||
MAGISKBIN
=
/cache/data_bin
is_mounted /data
&&
MAGISKBIN
=
/data/magisk
||
MAGISKBIN
=
/cache/data_bin
# Copy required files
# Copy required files
...
@@ -147,7 +136,7 @@ fi
...
@@ -147,7 +136,7 @@ fi
##########################################################################################
##########################################################################################
# Fix SuperSU.....
# Fix SuperSU.....
$BOOTMODE
&&
$BINDIR
/magiskpolicy
--live
"allow fsck * * *"
$BOOTMODE
&&
$BINDIR
/magisk
magisk
policy
--live
"allow fsck * * *"
if
(
is_mounted /data
)
;
then
if
(
is_mounted /data
)
;
then
IMG
=
/data/magisk.img
IMG
=
/data/magisk.img
...
@@ -163,9 +152,11 @@ else
...
@@ -163,9 +152,11 @@ else
$BINDIR
/magisk
--createimg
$IMG
64M
$BINDIR
/magisk
--createimg
$IMG
64M
fi
fi
mount_image
$IMG
/magisk
if
!
is_mounted /magisk
;
then
ui_print
"- Mounting
$IMG
to /magisk"
MAGISKLOOP
=
`
$BINDIR
/magisk
--mountimg
$IMG
/magisk
`
fi
is_mounted /magisk
||
abort
"! Magisk image mount failed..."
is_mounted /magisk
||
abort
"! Magisk image mount failed..."
MAGISKLOOP
=
$LOOPDEVICE
# Core folders
# Core folders
mkdir
-p
$COREDIR
/props
$COREDIR
/post-fs-data.d
$COREDIR
/service.d 2>/dev/null
mkdir
-p
$COREDIR
/props
$COREDIR
/post-fs-data.d
$COREDIR
/service.d 2>/dev/null
...
@@ -222,12 +213,12 @@ rm -f new-boot.img
...
@@ -222,12 +213,12 @@ rm -f new-boot.img
cd
/
cd
/
if
!
$BOOTMODE
;
then
if
!
$BOOTMODE
;
then
mv
/sbin_tmp /sbin
ui_print
"- Unmounting partitions"
ui_print
"- Unmounting partitions"
umount /magisk
$BINDIR
/magisk
--umountimg
/magisk
$MAGISKLOOP
losetup
-d
$MAGISKLOOP
2>/dev/null
rmdir
/magisk
rmdir
/magisk
mv
/sbin_tmp /sbin
umount
-l
/system
umount
-l
/system
umount
-l
/vendor 2>/dev/null
fi
fi
ui_print
"- Done"
ui_print
"- Done"
...
...
scripts/util_functions.sh
View file @
2a86bc86
...
@@ -56,29 +56,6 @@ is_mounted() {
...
@@ -56,29 +56,6 @@ is_mounted() {
return
$?
return
$?
}
}
mount_image
()
{
if
[
!
-d
"
$2
"
]
;
then
mount
-o
rw,remount rootfs /
mkdir
-p
"
$2
"
2>/dev/null
$BOOTMODE
&&
mount
-o
ro,remount rootfs /
[
!
-d
"
$2
"
]
&&
return
1
fi
if
!
is_mounted
"
$2
"
;
then
LOOPDEVICE
=
for
LOOP
in
0 1 2 3 4 5 6 7
;
do
if
!
is_mounted
"
$2
"
;
then
LOOPDEVICE
=
/dev/block/loop
$LOOP
[
-e
$LOOPDEVICE
]
||
mknod
$LOOPDEVICE
b 7
$LOOP
2>/dev/null
losetup
$LOOPDEVICE
"
$1
"
&&
mount
-t
ext4
-o
loop
$LOOPDEVICE
"
$2
"
if
is_mounted
"
$2
"
;
then
ui_print
"- Mounting
$1
to
$2
"
break
;
fi
fi
done
fi
}
grep_prop
()
{
grep_prop
()
{
REGEX
=
"s/^
$1
=//p"
REGEX
=
"s/^
$1
=//p"
shift
shift
...
@@ -114,6 +91,15 @@ remove_system_su() {
...
@@ -114,6 +91,15 @@ remove_system_su() {
fi
fi
}
}
recovery_actions
()
{
# TWRP bug fix
mount
-o
bind
/dev/urandom /dev/random
# Clear out possible lib paths, let the binaries find them itself
export
LD_LIBRARY_PATH
=
# Temporarily block out all custom recovery binaries/libs
mv
/sbin /sbin_tmp
}
abort
()
{
abort
()
{
ui_print
"
$1
"
ui_print
"
$1
"
mv
/sbin_tmp /sbin 2>/dev/null
mv
/sbin_tmp /sbin 2>/dev/null
...
...
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