Magisk/app/src/main/res/raw/manager.sh

162 lines
4.0 KiB
Bash
Raw Normal View History

2020-02-10 11:36:28 +00:00
##################################
# Magisk Manager internal scripts
##################################
2018-05-13 10:14:10 +00:00
env_check() {
for file in busybox magisk magiskboot magiskinit util_functions.sh boot_patch.sh; do
2019-02-24 07:11:11 +00:00
[ -f $MAGISKBIN/$file ] || return 1
2018-05-13 10:14:10 +00:00
done
return 0
}
2018-06-25 16:29:01 +00:00
2018-07-04 09:15:26 +00:00
fix_env() {
2019-02-24 07:11:11 +00:00
cd $MAGISKBIN
2019-03-22 06:32:21 +00:00
PATH=/sbin:/system/bin sh update-binary -x
2019-02-24 07:11:11 +00:00
./busybox rm -f $MAGISKTMP/busybox/*
2019-03-22 06:32:21 +00:00
cp -af busybox $MAGISKTMP/busybox/busybox
$MAGISKTMP/busybox/busybox --install -s $MAGISKTMP/busybox
2018-07-04 09:15:26 +00:00
rm -f update-binary magisk.apk
chmod -R 755 .
2019-03-20 07:20:02 +00:00
./magiskinit -x magisk magisk
2018-07-04 09:15:26 +00:00
cd /
}
direct_install() {
2019-02-24 07:11:11 +00:00
rm -rf $MAGISKBIN/* 2>/dev/null
mkdir -p $MAGISKBIN 2>/dev/null
chmod 700 $NVBASE
cp -af $1/. $MAGISKBIN
rm -f $MAGISKBIN/new-boot.img
2018-08-10 10:59:14 +00:00
echo "- Flashing new boot image"
2018-08-12 18:57:03 +00:00
flash_image $1/new-boot.img $2
if [ $? -ne 0 ]; then
echo "! Insufficient partition size"
return 1
fi
2018-08-12 18:57:03 +00:00
rm -rf $1
return 0
2018-07-04 09:15:26 +00:00
}
mm_patch_dtb() {
2020-02-11 00:31:41 +00:00
(local result=1
local PATCHED=$TMPDIR/dt.patched
for name in dtb dtbo; do
local IMAGE=`find_block $name$SLOT`
if [ ! -z $IMAGE ]; then
if $MAGISKBIN/magiskboot dtb $IMAGE patch $PATCHED; then
result=0
if [ ! -z $SHA1 ]; then
# Backup stuffs
mkdir /data/magisk_backup_${SHA1} 2>/dev/null
cat $IMAGE | gzip -9 > /data/magisk_backup_${SHA1}/${name}.img.gz
fi
cat $PATCHED /dev/zero > $IMAGE
rm -f $PATCHED
fi
fi
done
2020-02-11 00:31:41 +00:00
# Run broadcast command passed from app
eval $1
)& >/dev/null 2>&1
2018-06-25 16:29:01 +00:00
}
2018-06-26 21:58:56 +00:00
restore_imgs() {
[ -z $SHA1 ] && return 1
local BACKUPDIR=/data/magisk_backup_$SHA1
[ -d $BACKUPDIR ] || return 1
2018-06-26 21:58:56 +00:00
get_flags
2018-06-26 21:58:56 +00:00
find_boot_image
for name in dtb dtbo; do
[ -f $BACKUPDIR/${name}.img.gz ] || continue
local IMAGE=`find_block $name$SLOT`
[ -z $IMAGE ] && continue
flash_image $BACKUPDIR/${name}.img.gz $IMAGE
done
[ -f $BACKUPDIR/boot.img.gz ] || return 1
flash_image $BACKUPDIR/boot.img.gz $BOOTIMAGE
2018-06-26 21:58:56 +00:00
}
post_ota() {
cd $1
chmod 755 bootctl
2018-12-13 11:05:19 +00:00
./bootctl hal-info || return
[ `./bootctl get-current-slot` -eq 0 ] && SLOT_NUM=1 || SLOT_NUM=0
./bootctl set-active-boot-slot $SLOT_NUM
2019-03-22 06:32:21 +00:00
cat << EOF > post-fs-data.d/post_ota.sh
${1}/bootctl mark-boot-successful
rm -f ${1}/bootctl
2019-04-24 05:59:47 +00:00
rm -f ${1}/post-fs-data.d/post_ota.sh
2019-03-22 06:32:21 +00:00
EOF
chmod 755 post-fs-data.d/post_ota.sh
cd /
}
add_hosts_module() {
# Do not touch existing hosts module
2020-01-11 04:37:08 +00:00
[ -d /sbin/.magisk/modules/hosts ] && return
cd /sbin/.magisk/modules
mkdir -p hosts/system/etc
cat << EOF > hosts/module.prop
id=hosts
name=Systemless Hosts
version=1.0
versionCode=1
author=Magisk Manager
description=Magisk Manager built-in systemless hosts module
EOF
2020-01-11 04:37:08 +00:00
cp -f /system/etc/hosts hosts/system/etc/hosts
2018-11-27 08:26:05 +00:00
magisk --clone-attr /system/etc/hosts hosts/system/etc/hosts
touch hosts/update
cd /
}
force_pm_install() {
local APK=$1
local VERIFY=`settings get global package_verifier_enable`
2019-10-24 19:23:57 +00:00
[ "$VERIFY" -eq 1 ] && settings put global package_verifier_enable 0
pm install -r $APK
local res=$?
2019-10-24 19:23:57 +00:00
[ "$VERIFY" -eq 1 ] && settings put global package_verifier_enable 1
return $res
}
2020-02-11 00:33:58 +00:00
check_boot_ramdisk() {
# Create boolean ISAB
[ -z $SLOT ] && ISAB=false || ISAB=true
# If we are running as recovery mode, then we do not have ramdisk in boot
$RECOVERYMODE && return 1
# If we are A/B, then we must have ramdisk
$ISAB && return 0
# If we are using legacy SAR, but not AB, we do not have ramdisk in boot
if grep ' / ' /proc/mounts | grep -q '/dev/root'; then
# Override recovery mode to true
RECOVERYMODE=true
return 1
fi
return 0
}
2020-02-10 11:36:28 +00:00
##########################
# Non-root util_functions
##########################
mount_partitions() {
[ "`getprop ro.build.ab_update`" = "true" ] && SLOT=`getprop ro.boot.slot_suffix`
# Check whether non rootfs root dir exists
grep ' / ' /proc/mounts | grep -qv 'rootfs' && SYSTEM_ROOT=true || SYSTEM_ROOT=false
}
get_flags() {
$SYSTEM_ROOT && KEEPVERITY=true || KEEPVERITY=false
[ "`getprop ro.crypto.state`" = "encrypted" ] && KEEPFORCEENCRYPT=true || KEEPFORCEENCRYPT=false
RECOVERYMODE=false
}
run_migrations() { return; }