Update scripts
This commit is contained in:
parent
edaf8787d1
commit
cb70eebb08
21
build.py
21
build.py
@ -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)
|
||||
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)
|
||||
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="{}"\nMAGISK_VER_CODE={}'.format(args.versionString, args.versionCode))
|
||||
target = os.path.join('common', 'util_functions.sh')
|
||||
print('zip: ' + source + ' -> ' + target)
|
||||
zipf.writestr(target, util_func)
|
||||
|
@ -34,7 +34,7 @@ main() {
|
||||
[ -f /system/build.prop ] || abort "! /system could not be mounted!"
|
||||
|
||||
ui_print "************************"
|
||||
ui_print "* MAGISK_VERSION_STUB"
|
||||
ui_print "* Magisk v$MAGISK_VER addon.d"
|
||||
ui_print "************************"
|
||||
|
||||
api_level_arch_detect
|
||||
|
@ -50,7 +50,7 @@ get_outfd
|
||||
##########################################################################################
|
||||
|
||||
ui_print "************************"
|
||||
ui_print "* MAGISK_VERSION_STUB"
|
||||
ui_print "* Magisk 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
|
||||
|
@ -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
|
||||
# Add busybox to PATH
|
||||
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
|
||||
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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user