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
|
2019-02-24 13:13:27 +00:00
|
|
|
chmod -R 755 .
|
2019-03-20 07:20:02 +00:00
|
|
|
./magiskinit -x magisk magisk
|
2018-07-04 09:15:26 +00:00
|
|
|
cd /
|
|
|
|
}
|
|
|
|
|
2019-02-11 22:14:07 +00:00
|
|
|
run_migrations() {
|
|
|
|
# Move the stock backups
|
|
|
|
if [ -f /data/magisk/stock_boot* ]; then
|
|
|
|
mv /data/magisk/stock_boot* /data 2>/dev/null
|
|
|
|
fi
|
|
|
|
if [ -f /data/adb/magisk/stock_boot* ]; then
|
|
|
|
mv /data/adb/magisk/stock_boot* /data 2>/dev/null
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-07-04 09:15:26 +00:00
|
|
|
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
|
2018-08-11 07:56:12 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "! Insufficient partition size"
|
|
|
|
return 1
|
|
|
|
fi
|
2018-08-12 18:57:03 +00:00
|
|
|
rm -rf $1
|
2018-08-11 07:56:12 +00:00
|
|
|
return 0
|
2018-07-04 09:15:26 +00:00
|
|
|
}
|
|
|
|
|
2018-06-25 16:29:01 +00:00
|
|
|
mm_patch_dtbo() {
|
2019-02-24 07:11:11 +00:00
|
|
|
$KEEPVERITY && return 1 || patch_dtbo_image
|
2018-06-25 16:29:01 +00:00
|
|
|
}
|
2018-06-26 21:58:56 +00:00
|
|
|
|
|
|
|
restore_imgs() {
|
2018-11-20 10:24:40 +00:00
|
|
|
local SHA1=`grep_prop SHA1 /sbin/.magisk/config`
|
2018-11-15 05:33:20 +00:00
|
|
|
[ -z $SHA1 ] && local SHA1=`cat /.backup/.sha1`
|
2018-06-26 21:58:56 +00:00
|
|
|
[ -z $SHA1 ] && return 1
|
2018-07-20 17:59:28 +00:00
|
|
|
local STOCKBOOT=/data/stock_boot_${SHA1}.img.gz
|
|
|
|
local STOCKDTBO=/data/stock_dtbo.img.gz
|
2018-06-26 21:58:56 +00:00
|
|
|
[ -f $STOCKBOOT ] || return 1
|
|
|
|
|
|
|
|
find_boot_image
|
|
|
|
find_dtbo_image
|
|
|
|
|
2018-08-10 10:59:14 +00:00
|
|
|
if [ -f $STOCKDTBO -a -b "$DTBOIMAGE" ]; then
|
|
|
|
flash_image $STOCKDTBO $DTBOIMAGE
|
2018-06-26 21:58:56 +00:00
|
|
|
fi
|
2018-08-10 10:59:14 +00:00
|
|
|
if [ -f $STOCKBOOT -a -b "$BOOTIMAGE" ]; then
|
|
|
|
flash_image $STOCKBOOT $BOOTIMAGE
|
2018-06-26 21:58:56 +00:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
return 1
|
|
|
|
}
|
2018-07-20 17:59:28 +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
|
2018-07-20 17:59:28 +00:00
|
|
|
chmod 755 post-fs-data.d/post_ota.sh
|
|
|
|
cd /
|
|
|
|
}
|
2018-11-15 18:57:41 +00:00
|
|
|
|
|
|
|
add_hosts_module() {
|
|
|
|
# Do not touch existing hosts module
|
|
|
|
[ -d /sbin/.magisk/img/hosts ] && return
|
|
|
|
cd /sbin/.magisk/img
|
|
|
|
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
|
|
|
|
minMagisk=17000
|
|
|
|
EOF
|
|
|
|
if [ -f .core/hosts ]; then
|
|
|
|
# Migrate old hosts file to new module
|
|
|
|
mv -f .core/hosts hosts/system/etc/hosts
|
|
|
|
else
|
2018-11-27 08:26:05 +00:00
|
|
|
cp -f /system/etc/hosts hosts/system/etc/hosts
|
2018-11-15 18:57:41 +00:00
|
|
|
fi
|
2018-11-27 08:26:05 +00:00
|
|
|
magisk --clone-attr /system/etc/hosts hosts/system/etc/hosts
|
2018-11-15 18:57:41 +00:00
|
|
|
touch hosts/update
|
|
|
|
touch hosts/auto_mount
|
|
|
|
cd /
|
|
|
|
}
|
2018-11-27 08:24:26 +00:00
|
|
|
|
|
|
|
rm_launch() {
|
2019-02-24 07:11:11 +00:00
|
|
|
pm uninstall $1
|
2019-03-22 06:32:21 +00:00
|
|
|
am start -n $2
|
2018-11-27 08:24:26 +00:00
|
|
|
exit
|
|
|
|
}
|