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
cb70eebb
Commit
cb70eebb
authored
Jul 30, 2017
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update scripts
parent
edaf8787
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
50 additions
and
77 deletions
+50
-77
build.py
build.py
+6
-19
addon.d.sh
scripts/addon.d.sh
+5
-5
flash_script.sh
scripts/flash_script.sh
+8
-5
util_functions.sh
scripts/util_functions.sh
+31
-48
No files found.
build.py
View file @
cb70eebb
...
@@ -89,10 +89,7 @@ def build_apk(args):
...
@@ -89,10 +89,7 @@ def build_apk(args):
source
=
os
.
path
.
join
(
'scripts'
,
script
)
source
=
os
.
path
.
join
(
'scripts'
,
script
)
target
=
os
.
path
.
join
(
'MagiskManager'
,
'app'
,
'src'
,
'main'
,
'assets'
,
script
)
target
=
os
.
path
.
join
(
'MagiskManager'
,
'app'
,
'src'
,
'main'
,
'assets'
,
script
)
print
(
'cp: {} -> {}'
.
format
(
source
,
target
))
print
(
'cp: {} -> {}'
.
format
(
source
,
target
))
with
open
(
source
,
'r'
)
as
file
:
shutil
.
copyfile
(
source
,
target
)
script_cont
=
file
.
read
()
.
replace
(
'MAGISK_VERSION_STUB'
,
''
)
with
open
(
target
,
'w'
)
as
file
:
file
.
write
(
script_cont
)
print
(
''
)
print
(
''
)
...
@@ -191,22 +188,12 @@ def zip_main(args):
...
@@ -191,22 +188,12 @@ def zip_main(args):
# Scripts
# Scripts
# flash_script.sh
# flash_script.sh
source
=
os
.
path
.
join
(
'scripts'
,
'flash_script.sh'
)
source
=
os
.
path
.
join
(
'scripts'
,
'flash_script.sh'
)
with
open
(
source
,
'r'
)
as
script
:
target
=
os
.
path
.
join
(
'META-INF'
,
'com'
,
'google'
,
'android'
,
'update-binary'
)
# Add version info into flash script
zip_with_msg
(
zipf
,
source
,
target
)
update_binary
=
script
.
read
()
.
replace
(
'MAGISK_VERSION_STUB'
,
'Magisk v{} Installer'
.
format
(
args
.
versionString
))
target
=
os
.
path
.
join
(
'META-INF'
,
'com'
,
'google'
,
'android'
,
'update-binary'
)
print
(
'zip: '
+
source
+
' -> '
+
target
)
zipf
.
writestr
(
target
,
update_binary
)
# addon.d.sh
# addon.d.sh
source
=
os
.
path
.
join
(
'scripts'
,
'addon.d.sh'
)
source
=
os
.
path
.
join
(
'scripts'
,
'addon.d.sh'
)
with
open
(
source
,
'r'
)
as
script
:
target
=
os
.
path
.
join
(
'addon.d'
,
'99-magisk.sh'
)
# Add version info addon.d.sh
zip_with_msg
(
zipf
,
source
,
target
)
addond
=
script
.
read
()
.
replace
(
'MAGISK_VERSION_STUB'
,
'Magisk v{} addon.d'
.
format
(
args
.
versionString
))
target
=
os
.
path
.
join
(
'addon.d'
,
'99-magisk.sh'
)
print
(
'zip: '
+
source
+
' -> '
+
target
)
zipf
.
writestr
(
target
,
addond
)
# updater-script
# updater-script
target
=
os
.
path
.
join
(
'META-INF'
,
'com'
,
'google'
,
'android'
,
'updater-script'
)
target
=
os
.
path
.
join
(
'META-INF'
,
'com'
,
'google'
,
'android'
,
'updater-script'
)
print
(
'zip: '
+
target
)
print
(
'zip: '
+
target
)
...
@@ -224,7 +211,7 @@ def zip_main(args):
...
@@ -224,7 +211,7 @@ def zip_main(args):
with
open
(
source
,
'r'
)
as
script
:
with
open
(
source
,
'r'
)
as
script
:
# Add version info util_functions.sh
# Add version info util_functions.sh
util_func
=
script
.
read
()
.
replace
(
util_func
=
script
.
read
()
.
replace
(
'MAGISK_VERSION_STUB'
,
'
SCRIPT_VERSION={}'
.
format
(
args
.
versionCode
))
'MAGISK_VERSION_STUB'
,
'
MAGISK_VER="{}"
\n
MAGISK_VER_CODE={}'
.
format
(
args
.
versionString
,
args
.
versionCode
))
target
=
os
.
path
.
join
(
'common'
,
'util_functions.sh'
)
target
=
os
.
path
.
join
(
'common'
,
'util_functions.sh'
)
print
(
'zip: '
+
source
+
' -> '
+
target
)
print
(
'zip: '
+
source
+
' -> '
+
target
)
zipf
.
writestr
(
target
,
util_func
)
zipf
.
writestr
(
target
,
util_func
)
...
...
scripts/addon.d.sh
View file @
cb70eebb
#!/sbin/sh
#!/sbin/sh
##########################################################################################
##########################################################################################
#
#
# Magisk Survival Script for ROMs with addon.d support
# Magisk Survival Script for ROMs with addon.d support
# by topjohnwu
# by topjohnwu
#
#
# Inspired by 99-flashafterupdate.sh of osm0sis @ xda-developers
# Inspired by 99-flashafterupdate.sh of osm0sis @ xda-developers
#
#
##########################################################################################
##########################################################################################
.
/tmp/backuptool.functions
.
/tmp/backuptool.functions
...
@@ -34,7 +34,7 @@ main() {
...
@@ -34,7 +34,7 @@ main() {
[
-f
/system/build.prop
]
||
abort
"! /system could not be mounted!"
[
-f
/system/build.prop
]
||
abort
"! /system could not be mounted!"
ui_print
"************************"
ui_print
"************************"
ui_print
"* M
AGISK_VERSION_STUB
"
ui_print
"* M
agisk v
$MAGISK_VER
addon.d
"
ui_print
"************************"
ui_print
"************************"
api_level_arch_detect
api_level_arch_detect
...
@@ -91,7 +91,7 @@ case "$1" in
...
@@ -91,7 +91,7 @@ case "$1" in
post-restore
)
post-restore
)
# Get the FD for ui_print
# Get the FD for ui_print
OUTFD
=
`
ps |
grep
-v
grep
|
grep
-oE
"update(.*)"
|
cut
-d
" "
-f3
`
OUTFD
=
`
ps |
grep
-v
grep
|
grep
-oE
"update(.*)"
|
cut
-d
" "
-f3
`
# Run the main function in a parallel subshell
# Run the main function in a parallel subshell
(
main
)
&
(
main
)
&
;;
;;
esac
esac
scripts/flash_script.sh
View file @
cb70eebb
...
@@ -50,7 +50,7 @@ get_outfd
...
@@ -50,7 +50,7 @@ get_outfd
##########################################################################################
##########################################################################################
ui_print
"************************"
ui_print
"************************"
ui_print
"* M
AGISK_VERSION_STUB
"
ui_print
"* M
agisk v
$MAGISK_VER
Installer
"
ui_print
"************************"
ui_print
"************************"
ui_print
"- Mounting /system, /vendor, /cache, /data"
ui_print
"- Mounting /system, /vendor, /cache, /data"
...
@@ -79,9 +79,6 @@ ui_print "- Device platform: $ARCH"
...
@@ -79,9 +79,6 @@ ui_print "- Device platform: $ARCH"
BINDIR
=
$INSTALLER
/
$ARCH
BINDIR
=
$INSTALLER
/
$ARCH
chmod
-R
755
$CHROMEDIR
$BINDIR
chmod
-R
755
$CHROMEDIR
$BINDIR
find_boot_image
[
-z
$BOOTIMAGE
]
&&
abort
"! Unable to detect boot image"
##########################################################################################
##########################################################################################
# Environment
# Environment
##########################################################################################
##########################################################################################
...
@@ -95,6 +92,9 @@ rm -rf $MAGISKBIN 2>/dev/null
...
@@ -95,6 +92,9 @@ rm -rf $MAGISKBIN 2>/dev/null
mkdir
-p
$MAGISKBIN
mkdir
-p
$MAGISKBIN
cp
-af
$BINDIR
/.
$COMMONDIR
/.
$MAGISKBIN
cp
-af
$BINDIR
/.
$COMMONDIR
/.
$MAGISKBIN
cp
-af
$CHROMEDIR
$MAGISKBIN
cp
-af
$CHROMEDIR
$MAGISKBIN
# Extract busybox
[
$ARCH
=
"arm"
-o
$ARCH
=
"arm64"
]
&&
BBPATH
=
lib/armeabi-v7a
||
BBPATH
=
lib/x86
unzip
-p
$INSTALLER
/common/magisk.apk
$BBPATH
/libbusybox.so
>
$MAGISKBIN
/busybox
chmod
-R
755
$MAGISKBIN
chmod
-R
755
$MAGISKBIN
# addon.d
# addon.d
...
@@ -148,6 +148,8 @@ rm -rf $COREDIR/magiskhide $COREDIR/bin
...
@@ -148,6 +148,8 @@ rm -rf $COREDIR/magiskhide $COREDIR/bin
# Unpack boot
# Unpack boot
##########################################################################################
##########################################################################################
find_boot_image
[
-z
$BOOTIMAGE
]
&&
abort
"! Unable to detect boot image"
ui_print
"- Found Boot Image:
$BOOTIMAGE
"
ui_print
"- Found Boot Image:
$BOOTIMAGE
"
# Update our previous backup to new format if exists
# Update our previous backup to new format if exists
...
@@ -183,8 +185,9 @@ if ! $BOOTMODE; then
...
@@ -183,8 +185,9 @@ if ! $BOOTMODE; then
$MAGISKBIN
/magisk
--umountimg
/magisk
$MAGISKLOOP
$MAGISKBIN
/magisk
--umountimg
/magisk
$MAGISKLOOP
rmdir
/magisk
rmdir
/magisk
recovery_cleanup
recovery_cleanup
rm
-rf
$TMPDIR
fi
fi
# rm -rf $TMPDIR
ui_print
"- Done"
ui_print
"- Done"
exit
0
exit
0
scripts/util_functions.sh
View file @
cb70eebb
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
##########################################################################################
##########################################################################################
MAGISK_VERSION_STUB
MAGISK_VERSION_STUB
SCRIPT_VERSION
=
$MAGISK_VER_CODE
get_outfd
()
{
get_outfd
()
{
readlink
/proc/
$$
/fd/
$OUTFD
2>/dev/null |
grep
/tmp
>
/dev/null
readlink
/proc/
$$
/fd/
$OUTFD
2>/dev/null |
grep
/tmp
>
/dev/null
...
@@ -36,31 +37,36 @@ ui_print() {
...
@@ -36,31 +37,36 @@ ui_print() {
fi
fi
}
}
grep_prop
()
{
REGEX
=
"s/^
$1
=//p"
shift
FILES
=
$@
[
-z
"
$FILES
"
]
&&
FILES
=
'/system/build.prop'
sed
-n
"
$REGEX
"
$FILES
2>/dev/null |
head
-n
1
}
getvar
()
{
getvar
()
{
local
VARNAME
=
$1
local
VARNAME
=
$1
local
VALUE
=
$(
eval echo
\$
"
$VARNAME
"
)
;
local
VALUE
=
`
eval echo
\$
$VARNAME
`
for
FILE
in
/dev/.magisk /data/.magisk /cache/.magisk /system/.magisk
;
do
[
!
-z
$VALUE
]
&&
return
if
[
-z
"
$VALUE
"
]
;
then
for
DIR
in
/dev /data /cache /system
;
do
LINE
=
$(
cat
$FILE
2>/dev/null |
grep
"
$VARNAME
="
)
VALUE
=
`
grep_prop
$VARNAME
$DIR
/.magisk
`
if
[
!
-z
"
$LINE
"
]
;
then
[
!
-z
$VALUE
]
&&
break
;
VALUE
=
${
LINE
#*=
}
fi
fi
done
done
eval
$VARNAME
=
\$
VALUE
eval
$VARNAME
=
\$
VALUE
}
}
find_boot_image
()
{
find_boot_image
()
{
if
[
-z
"
$BOOTIMAGE
"
]
;
then
if
[
-z
"
$BOOTIMAGE
"
]
;
then
for
BLOCK
in
boot_a
BOOT_A kern-a KERN-A android_boot ANDROID_BOOT kernel KERNEL boot BOOT lnx LNX
;
do
for
BLOCK
in
boot_a
kern-a android_boot kernel boot lnx
;
do
BOOTIMAGE
=
`
ls
/dev/block/by-name/
$BLOCK
||
ls
/dev/block/platform/
*
/by-name/
$BLOCK
||
ls
/dev/block/platform/
*
/
*
/by-name/
$BLOCK
`
2>/dev/null
BOOTIMAGE
=
`
find /dev/block
-iname
$BLOCK
|
head
-n
1
`
2>/dev/null
[
!
-z
$BOOTIMAGE
]
&&
break
[
!
-z
$BOOTIMAGE
]
&&
break
done
done
fi
fi
# Recovery fallback
# Recovery fallback
if
[
-z
"
$BOOTIMAGE
"
]
;
then
if
[
-z
"
$BOOTIMAGE
"
]
;
then
for
FSTAB
in
/etc/
*
fstab
*
;
do
for
FSTAB
in
/etc/
*
fstab
*
;
do
BOOTIMAGE
=
`
grep
-
E
'\b/boot\b'
$FSTAB
|
grep
-v
"#"
|
grep
-oE
'/dev/[a-zA-Z0-9_./-]*'
`
BOOTIMAGE
=
`
grep
-
v
'#'
$FSTAB
|
grep
-E
'\b/boot\b'
|
grep
-oE
'/dev/[a-zA-Z0-9_./-]*'
`
[
!
-z
$BOOTIMAGE
]
&&
break
[
!
-z
$BOOTIMAGE
]
&&
break
done
done
fi
fi
...
@@ -76,16 +82,6 @@ is_mounted() {
...
@@ -76,16 +82,6 @@ is_mounted() {
return
$?
return
$?
}
}
grep_prop
()
{
REGEX
=
"s/^
$1
=//p"
shift
FILES
=
$@
if
[
-z
"
$FILES
"
]
;
then
FILES
=
'/system/build.prop'
fi
cat
$FILES
2>/dev/null |
sed
-n
"
$REGEX
"
|
head
-n
1
}
remove_system_su
()
{
remove_system_su
()
{
if
[
-f
/system/bin/su
-o
-f
/system/xbin/su
]
&&
[
!
-f
/su/bin/su
]
;
then
if
[
-f
/system/bin/su
-o
-f
/system/xbin/su
]
&&
[
!
-f
/su/bin/su
]
;
then
ui_print
"! System installed root detected, mount rw :("
ui_print
"! System installed root detected, mount rw :("
...
@@ -131,15 +127,11 @@ recovery_actions() {
...
@@ -131,15 +127,11 @@ recovery_actions() {
# Preserve environment varibles
# Preserve environment varibles
OLD_PATH
=
$PATH
OLD_PATH
=
$PATH
OLD_LD_PATH
=
$LD_LIBRARY_PATH
OLD_LD_PATH
=
$LD_LIBRARY_PATH
# Extract busybox from Magisk Manager
# Add busybox to PATH
if
[
-f
$INSTALLER
/common/magisk.apk
]
;
then
mkdir
-p
$TMPDIR
/bin
mkdir
-p
$TMPDIR
/bin
ln
-s
$MAGISKBIN
/busybox
$TMPDIR
/bin/busybox
[
$ARCH
=
"arm"
-o
$ARCH
=
"arm64"
]
&&
BBPATH
=
lib/armeabi-v7a
||
BBPATH
=
lib/x86
$MAGISKBIN
/busybox
--install
-s
$TMPDIR
/bin
unzip
-p
$INSTALLER
/common/magisk.apk
$BBPATH
/libbusybox.so
>
$TMPDIR
/bin/busybox 2>/dev/null
export
PATH
=
$TMPDIR
/bin:
$PATH
chmod
755
$TMPDIR
/bin/busybox
$TMPDIR
/bin/busybox
--install
-s
$TMPDIR
/bin
export
PATH
=
$PATH
:
$TMPDIR
/bin
fi
# Temporarily block out all custom recovery binaries/libs
# Temporarily block out all custom recovery binaries/libs
mv
/sbin /sbin_tmp
mv
/sbin /sbin_tmp
# Add all possible library paths
# Add all possible library paths
...
@@ -147,48 +139,39 @@ recovery_actions() {
...
@@ -147,48 +139,39 @@ recovery_actions() {
}
}
recovery_cleanup
()
{
recovery_cleanup
()
{
mv
/sbin_tmp /sbin
mv
/sbin_tmp /sbin 2>/dev/null
# Clear LD_LIBRARY_PATH
export
LD_LIBRARY_PATH
=
$OLD_LD_PATH
export
LD_LIBRARY_PATH
=
$OLD_LD_PATH
export
PATH
=
$OLD_PATH
[
-z
$OLD_PATH
]
||
export
PATH
=
$OLD_PATH
ui_print
"- Unmounting partitions"
ui_print
"- Unmounting partitions"
umount
-l
/system
umount
-l
/system
2>/dev/null
umount
-l
/vendor 2>/dev/null
umount
-l
/vendor 2>/dev/null
umount
-l
/dev/random
umount
-l
/dev/random
2>/dev/null
}
}
abort
()
{
abort
()
{
ui_print
"
$1
"
ui_print
"
$1
"
mv
/sbin_tmp /sbin 2>/dev/null
$BOOTMODE
||
recovery_cleanup
exit
1
exit
1
}
}
set_perm
()
{
set_perm
()
{
chown
$2
:
$3
$1
||
exit
1
chown
$2
:
$3
$1
||
exit
1
chmod
$4
$1
||
exit
1
chmod
$4
$1
||
exit
1
if
[
!
-z
$5
]
;
then
[
-z
$5
]
&&
chcon
-h
'u:object_r:system_file:s0'
$1
||
chcon
-h
$5
$1
chcon
$5
$1
2>/dev/null
else
chcon
'u:object_r:system_file:s0'
$1
2>/dev/null
fi
}
}
set_perm_recursive
()
{
set_perm_recursive
()
{
find
$1
-type
d 2>/dev/null |
while
read dir
;
do
find
$1
-type
d 2>/dev/null |
while
read dir
;
do
set_perm
$dir
$2
$3
$4
$6
set_perm
$dir
$2
$3
$4
$6
done
done
find
$1
-type
f 2>/dev/null |
while
read
file
;
do
find
$1
-type
f
-o
-type
l
2>/dev/null |
while
read
file
;
do
set_perm
$file
$2
$3
$5
$6
set_perm
$file
$2
$3
$5
$6
done
done
}
}
mktouch
()
{
mktouch
()
{
mkdir
-p
${
1
%/*
}
mkdir
-p
${
1
%/*
}
2>/dev/null
if
[
-z
"
$2
"
]
;
then
[
-z
$2
]
&&
touch
$1
||
echo
$2
>
$1
touch
$1
else
echo
$2
>
$1
fi
chmod
644
$1
chmod
644
$1
}
}
...
...
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