2020-02-10 03:36:28 -08:00
|
|
|
##################################
|
|
|
|
# Magisk Manager internal scripts
|
|
|
|
##################################
|
|
|
|
|
2020-08-22 22:49:03 -07:00
|
|
|
run_delay() {
|
|
|
|
(sleep $1; $2)&
|
|
|
|
}
|
|
|
|
|
2018-05-13 18:14:10 +08:00
|
|
|
env_check() {
|
|
|
|
for file in busybox magisk magiskboot magiskinit util_functions.sh boot_patch.sh; do
|
2019-02-24 02:11:11 -05:00
|
|
|
[ -f $MAGISKBIN/$file ] || return 1
|
2018-05-13 18:14:10 +08:00
|
|
|
done
|
|
|
|
return 0
|
|
|
|
}
|
2018-06-26 00:29:01 +08:00
|
|
|
|
2018-07-04 17:15:26 +08:00
|
|
|
fix_env() {
|
2019-02-24 02:11:11 -05:00
|
|
|
cd $MAGISKBIN
|
2020-04-05 01:27:07 -07:00
|
|
|
PATH=/system/bin /system/bin/sh update-binary -x
|
|
|
|
./busybox rm -f update-binary magisk.apk
|
|
|
|
./busybox chmod -R 755 .
|
2019-03-20 03:20:02 -04:00
|
|
|
./magiskinit -x magisk magisk
|
2018-07-04 17:15:26 +08:00
|
|
|
cd /
|
|
|
|
}
|
|
|
|
|
|
|
|
direct_install() {
|
2019-02-24 02:11:11 -05: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 18:59:14 +08:00
|
|
|
echo "- Flashing new boot image"
|
2018-08-13 02:57:03 +08:00
|
|
|
flash_image $1/new-boot.img $2
|
2018-08-11 15:56:12 +08:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "! Insufficient partition size"
|
|
|
|
return 1
|
|
|
|
fi
|
2018-08-13 02:57:03 +08:00
|
|
|
rm -rf $1
|
2018-08-11 15:56:12 +08:00
|
|
|
return 0
|
2018-07-04 17:15:26 +08:00
|
|
|
}
|
|
|
|
|
2018-06-27 05:58:56 +08:00
|
|
|
restore_imgs() {
|
|
|
|
[ -z $SHA1 ] && return 1
|
2020-01-01 14:02:44 +08:00
|
|
|
local BACKUPDIR=/data/magisk_backup_$SHA1
|
|
|
|
[ -d $BACKUPDIR ] || return 1
|
2018-06-27 05:58:56 +08:00
|
|
|
|
2019-05-08 20:06:29 -03:00
|
|
|
get_flags
|
2018-06-27 05:58:56 +08:00
|
|
|
find_boot_image
|
|
|
|
|
2020-01-01 14:02:44 +08:00
|
|
|
for name in dtb dtbo; do
|
|
|
|
[ -f $BACKUPDIR/${name}.img.gz ] || continue
|
2020-09-23 04:40:44 -07:00
|
|
|
local IMAGE=$(find_block $name$SLOT)
|
2020-01-01 14:02:44 +08:00
|
|
|
[ -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-27 05:58:56 +08:00
|
|
|
}
|
2018-07-21 01:59:28 +08:00
|
|
|
|
|
|
|
post_ota() {
|
|
|
|
cd $1
|
|
|
|
chmod 755 bootctl
|
2018-12-13 06:05:19 -05:00
|
|
|
./bootctl hal-info || return
|
2020-09-23 04:40:44 -07:00
|
|
|
[ $(./bootctl get-current-slot) -eq 0 ] && SLOT_NUM=1 || SLOT_NUM=0
|
2018-12-13 06:05:19 -05:00
|
|
|
./bootctl set-active-boot-slot $SLOT_NUM
|
2019-03-22 02:32:21 -04:00
|
|
|
cat << EOF > post-fs-data.d/post_ota.sh
|
|
|
|
${1}/bootctl mark-boot-successful
|
|
|
|
rm -f ${1}/bootctl
|
2019-04-24 01:59:47 -04:00
|
|
|
rm -f ${1}/post-fs-data.d/post_ota.sh
|
2019-03-22 02:32:21 -04:00
|
|
|
EOF
|
2018-07-21 01:59:28 +08:00
|
|
|
chmod 755 post-fs-data.d/post_ota.sh
|
|
|
|
cd /
|
|
|
|
}
|
2018-11-15 13:57:41 -05:00
|
|
|
|
|
|
|
add_hosts_module() {
|
|
|
|
# Do not touch existing hosts module
|
2020-04-05 01:27:07 -07:00
|
|
|
[ -d $MAGISKTMP/modules/hosts ] && return
|
|
|
|
cd $MAGISKTMP/modules
|
2018-11-15 13:57:41 -05:00
|
|
|
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-04-05 01:27:07 -07:00
|
|
|
magisk --clone /system/etc/hosts hosts/system/etc/hosts
|
2018-11-15 13:57:41 -05:00
|
|
|
touch hosts/update
|
|
|
|
cd /
|
|
|
|
}
|
2019-10-24 12:23:03 -04:00
|
|
|
|
2020-08-15 10:58:30 +08:00
|
|
|
adb_pm_install() {
|
|
|
|
local tmp=/data/local/tmp/patched.apk
|
|
|
|
cp -f "$1" $tmp
|
|
|
|
chmod 644 $tmp
|
2020-09-08 23:29:22 +08:00
|
|
|
su 2000 -c pm install $tmp || pm install $tmp
|
2020-08-15 10:58:30 +08:00
|
|
|
local res=$?
|
|
|
|
rm -f $tmp
|
|
|
|
return $res
|
|
|
|
}
|
|
|
|
|
2020-02-10 16:33:58 -08:00
|
|
|
check_boot_ramdisk() {
|
|
|
|
# Create boolean ISAB
|
|
|
|
[ -z $SLOT ] && ISAB=false || ISAB=true
|
|
|
|
|
2020-09-23 04:40:44 -07:00
|
|
|
# If we are running as recovery mode, then we do not have ramdisk
|
|
|
|
[ "$RECOVERYMODE" = "true" ] && return 1
|
2020-02-10 16:33:58 -08:00
|
|
|
|
|
|
|
# If we are A/B, then we must have ramdisk
|
|
|
|
$ISAB && return 0
|
|
|
|
|
2020-09-23 04:40:44 -07:00
|
|
|
# If we are using legacy SAR, but not A/B, assume we do not have ramdisk
|
2020-02-10 16:33:58 -08:00
|
|
|
if grep ' / ' /proc/mounts | grep -q '/dev/root'; then
|
2020-09-23 04:40:44 -07:00
|
|
|
# Override recovery mode to true if not set
|
|
|
|
[ -z $RECOVERYMODE ] && RECOVERYMODE=true
|
2020-02-10 16:33:58 -08:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2020-09-23 04:40:44 -07:00
|
|
|
check_encryption() {
|
|
|
|
if $ISENCRYPTED; then
|
|
|
|
if [ $SDK_INT -lt 24 ]; then
|
|
|
|
CRYPTOTYPE="block"
|
|
|
|
else
|
|
|
|
# First see what the system tells us
|
|
|
|
CRYPTOTYPE=$(getprop ro.crypto.type)
|
|
|
|
if [ -z $CRYPTOTYPE ]; then
|
|
|
|
# If not mounting through device mapper, we are FBE
|
|
|
|
if grep ' /data ' /proc/mounts | grep -qv 'dm-'; then
|
|
|
|
CRYPTOTYPE="file"
|
|
|
|
else
|
|
|
|
# We are either FDE or metadata encryption (which is also FBE)
|
|
|
|
grep -q ' /metadata ' /proc/mounts && CRYPTOTYPE="file" || CRYPTOTYPE="block"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
CRYPTOTYPE="N/A"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-02-10 03:36:28 -08:00
|
|
|
##########################
|
|
|
|
# Non-root util_functions
|
|
|
|
##########################
|
|
|
|
|
|
|
|
mount_partitions() {
|
2020-09-23 04:40:44 -07:00
|
|
|
[ "$(getprop ro.build.ab_update)" = "true" ] && SLOT=$(getprop ro.boot.slot_suffix)
|
2020-02-10 03:36:28 -08:00
|
|
|
# Check whether non rootfs root dir exists
|
|
|
|
grep ' / ' /proc/mounts | grep -qv 'rootfs' && SYSTEM_ROOT=true || SYSTEM_ROOT=false
|
|
|
|
}
|
|
|
|
|
|
|
|
get_flags() {
|
2020-09-23 04:40:44 -07:00
|
|
|
KEEPVERITY=$SYSTEM_ROOT
|
|
|
|
[ "$(getprop ro.crypto.state)" = "encrypted" ] && ISENCRYPTED=true || ISENCRYPTED=false
|
|
|
|
KEEPFORCEENCRYPT=$ISENCRYPTED
|
|
|
|
# Do NOT preset RECOVERYMODE here
|
2020-02-10 03:36:28 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
run_migrations() { return; }
|
2020-04-05 01:27:07 -07:00
|
|
|
|
|
|
|
grep_prop() { return; }
|
|
|
|
|
|
|
|
#############
|
|
|
|
# Initialize
|
|
|
|
#############
|
|
|
|
|
|
|
|
mm_init() {
|
|
|
|
export BOOTMODE=true
|
|
|
|
mount_partitions
|
|
|
|
get_flags
|
|
|
|
run_migrations
|
|
|
|
SHA1=$(grep_prop SHA1 $MAGISKTMP/config)
|
2020-06-28 06:51:58 -07:00
|
|
|
check_boot_ramdisk && RAMDISKEXIST=true || RAMDISKEXIST=false
|
2020-09-23 04:40:44 -07:00
|
|
|
check_encryption
|
|
|
|
# Make sure RECOVERYMODE has value
|
|
|
|
[ -z $RECOVERYMODE ] && RECOVERYMODE=false
|
2020-04-05 01:27:07 -07:00
|
|
|
}
|