Update scripts

This commit is contained in:
topjohnwu 2017-07-31 03:03:52 +08:00
parent edaf8787d1
commit cb70eebb08
4 changed files with 50 additions and 77 deletions

View File

@ -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):
# 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):
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="{}"\nMAGISK_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)

View File

@ -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 "* MAGISK_VERSION_STUB" ui_print "* Magisk v$MAGISK_VER addon.d"
ui_print "************************" ui_print "************************"
api_level_arch_detect api_level_arch_detect

View File

@ -50,7 +50,7 @@ get_outfd
########################################################################################## ##########################################################################################
ui_print "************************" ui_print "************************"
ui_print "* MAGISK_VERSION_STUB" ui_print "* Magisk 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"
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
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
# 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
$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

View File

@ -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() {
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() {
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() {
# 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() {
} }
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
} }