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