Magisk/app/src/full/res/raw/utils.sh

112 lines
2.5 KiB
Bash
Raw Normal View History

2018-04-14 12:08:53 +02:00
db_sepatch() {
magiskpolicy --live 'create magisk_file' 'attradd magisk_file mlstrustedobject' \
'allow * magisk_file file *' 'allow * magisk_file dir *' \
'allow magisk_file * filesystem associate'
}
2018-04-05 19:54:09 +02:00
db_clean() {
2018-02-18 05:41:58 +01:00
local USERID=$1
local DIR="/sbin/.core/db-${USERID}"
umount -l /data/user*/*/*/databases/su.db $DIR $DIR/*
rm -rf $DIR
2018-04-22 07:53:25 +02:00
[ "$USERID" = "*" ] && rm -fv /data/adb/magisk.db*
2018-02-18 11:12:12 +01:00
}
2018-04-05 19:54:09 +02:00
db_init() {
2018-06-11 18:04:36 +02:00
# Temporary let the folder rw by anyone
2018-04-14 12:08:53 +02:00
chcon u:object_r:magisk_file:s0 /data/adb
2018-02-18 11:12:12 +01:00
chmod 777 /data/adb
}
2018-04-05 19:54:09 +02:00
db_restore() {
2018-02-18 11:12:12 +01:00
chmod 700 /data/adb
2018-06-11 18:04:36 +02:00
magisk --restorecon
2018-02-18 05:41:58 +01:00
}
2018-04-05 19:54:09 +02:00
db_setup() {
2018-02-18 05:41:58 +01:00
local USER=$1
local USERID=$(($USER / 100000))
local DIR=/sbin/.core/db-${USERID}
mkdir -p $DIR
touch $DIR/magisk.db
2018-02-18 11:12:12 +01:00
mount -o bind /data/adb/magisk.db $DIR/magisk.db
2018-04-22 07:53:25 +02:00
rm -f /data/adb/magisk.db-*
2018-04-14 12:08:53 +02:00
chcon u:object_r:magisk_file:s0 $DIR $DIR/*
2018-02-18 05:41:58 +01:00
chmod 700 $DIR
chown $USER.$USER $DIR
chmod 666 $DIR/*
}
2018-05-13 12:14:10 +02:00
env_check() {
for file in busybox magisk magiskboot magiskinit util_functions.sh boot_patch.sh; do
2018-06-25 18:29:01 +02:00
[ -f /data/adb/magisk/$file ] || return 1
2018-05-13 12:14:10 +02:00
done
return 0
}
2018-06-25 18:29:01 +02:00
2018-07-04 11:15:26 +02:00
fix_env() {
cd /data/adb/magisk
sh update-binary extract
rm -f update-binary magisk.apk
cd /
rm -rf /sbin/.core/busybox/*
/sbin/.core/mirror/bin/busybox --install -s /sbin/.core/busybox
}
direct_install() {
rm -rf /data/adb/magisk/* 2>/dev/null
mkdir -p /data/adb/magisk 2>/dev/null
chmod 700 /data/adb
2018-07-05 11:29:44 +02:00
cp -rf $3/* /data/adb/magisk
2018-08-10 12:59:14 +02:00
echo "- Flashing new boot image"
flash_image $1 $2
if [ $? -ne 0 ]; then
echo "! Insufficient partition size"
return 1
fi
2018-08-10 12:59:14 +02:00
rm -f $1
2018-07-04 11:15:26 +02:00
rm -rf $3
return 0
2018-07-04 11:15:26 +02:00
}
2018-06-25 18:29:01 +02:00
mm_patch_dtbo() {
if $KEEPVERITY; then
2018-08-10 12:59:14 +02:00
return 1
2018-06-25 18:29:01 +02:00
else
find_dtbo_image
2018-08-10 12:59:14 +02:00
patch_dtbo_image
2018-06-25 18:29:01 +02:00
fi
}
2018-06-26 23:58:56 +02:00
restore_imgs() {
local SHA1=`cat /.backup/.sha1`
[ -z $SHA1 ] && local SHA1=`grep_prop #STOCKSHA1`
2018-06-26 23:58:56 +02:00
[ -z $SHA1 ] && return 1
local STOCKBOOT=/data/stock_boot_${SHA1}.img.gz
local STOCKDTBO=/data/stock_dtbo.img.gz
2018-06-26 23:58:56 +02:00
[ -f $STOCKBOOT ] || return 1
find_boot_image
find_dtbo_image
2018-08-10 12:59:14 +02:00
if [ -f $STOCKDTBO -a -b "$DTBOIMAGE" ]; then
flash_image $STOCKDTBO $DTBOIMAGE
2018-06-26 23:58:56 +02:00
fi
2018-08-10 12:59:14 +02:00
if [ -f $STOCKBOOT -a -b "$BOOTIMAGE" ]; then
flash_image $STOCKBOOT $BOOTIMAGE
2018-06-26 23:58:56 +02:00
return 0
fi
return 1
}
post_ota() {
cd $1
chmod 755 bootctl
./bootctl hal-info || return
[ `./bootctl get-current-slot` -eq 0 ] && SLOT_NUM=1 || SLOT_NUM=0
./bootctl set-active-boot-slot $SLOT_NUM
echo '${0%/*}/../bootctl mark-boot-successful;rm -f ${0%/*}/../bootctl $0' > post-fs-data.d/post_ota.sh
chmod 755 post-fs-data.d/post_ota.sh
cd /
}