2020-03-20 10:44:08 +00:00
|
|
|
############################################
|
2017-06-18 16:15:44 +00:00
|
|
|
# Magisk General Utility Functions
|
2020-03-20 10:44:08 +00:00
|
|
|
############################################
|
2017-06-18 16:15:44 +00:00
|
|
|
|
2019-02-24 07:11:11 +00:00
|
|
|
#MAGISK_VERSION_STUB
|
|
|
|
|
2023-07-17 23:07:16 +00:00
|
|
|
###################
|
|
|
|
# Global Variables
|
|
|
|
###################
|
|
|
|
|
|
|
|
# True if the script is running on booted Android, not something like recovery
|
2023-07-21 19:04:42 +00:00
|
|
|
# BOOTMODE=
|
2023-07-17 23:07:16 +00:00
|
|
|
|
|
|
|
# The path to store temporary files that don't need to persist
|
2023-07-21 19:04:42 +00:00
|
|
|
# TMPDIR=
|
2023-07-17 23:07:16 +00:00
|
|
|
|
|
|
|
# The non-volatile path where magisk executables are stored
|
2023-07-21 19:04:42 +00:00
|
|
|
# MAGISKBIN=
|
2023-07-17 23:07:16 +00:00
|
|
|
|
2019-02-11 22:14:07 +00:00
|
|
|
###################
|
|
|
|
# Helper Functions
|
|
|
|
###################
|
2017-07-10 17:54:11 +00:00
|
|
|
|
2019-02-11 22:14:07 +00:00
|
|
|
ui_print() {
|
2020-11-30 00:35:34 +00:00
|
|
|
if $BOOTMODE; then
|
|
|
|
echo "$1"
|
|
|
|
else
|
|
|
|
echo -e "ui_print $1\nui_print" >> /proc/self/fd/$OUTFD
|
|
|
|
fi
|
2019-02-11 22:14:07 +00:00
|
|
|
}
|
2018-01-01 08:46:28 +00:00
|
|
|
|
2019-02-11 22:14:07 +00:00
|
|
|
toupper() {
|
|
|
|
echo "$@" | tr '[:lower:]' '[:upper:]'
|
|
|
|
}
|
2017-09-27 16:54:01 +00:00
|
|
|
|
2019-02-11 22:14:07 +00:00
|
|
|
grep_cmdline() {
|
|
|
|
local REGEX="s/^$1=//p"
|
2021-11-18 02:53:33 +00:00
|
|
|
{ echo $(cat /proc/cmdline)$(sed -e 's/[^"]//g' -e 's/""//g' /proc/cmdline) | xargs -n 1; \
|
|
|
|
sed -e 's/ = /=/g' -e 's/, /,/g' -e 's/"//g' /proc/bootconfig; \
|
|
|
|
} 2>/dev/null | sed -n "$REGEX"
|
2019-02-11 22:14:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
grep_prop() {
|
|
|
|
local REGEX="s/^$1=//p"
|
|
|
|
shift
|
|
|
|
local FILES=$@
|
|
|
|
[ -z "$FILES" ] && FILES='/system/build.prop'
|
2021-01-22 10:28:53 +00:00
|
|
|
cat $FILES 2>/dev/null | dos2unix | sed -n "$REGEX" | head -n 1
|
2019-02-11 22:14:07 +00:00
|
|
|
}
|
|
|
|
|
2021-04-06 10:56:39 +00:00
|
|
|
grep_get_prop() {
|
|
|
|
local result=$(grep_prop $@)
|
|
|
|
if [ -z "$result" ]; then
|
|
|
|
# Fallback to getprop
|
|
|
|
getprop "$1"
|
|
|
|
else
|
|
|
|
echo $result
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-02-11 22:14:07 +00:00
|
|
|
getvar() {
|
|
|
|
local VARNAME=$1
|
2020-04-05 08:27:07 +00:00
|
|
|
local VALUE
|
|
|
|
local PROPPATH='/data/.magisk /cache/.magisk'
|
2023-03-16 11:07:00 +00:00
|
|
|
[ ! -z $MAGISKTMP ] && PROPPATH="$MAGISKTMP/.magisk/config $PROPPATH"
|
2020-04-05 08:27:07 +00:00
|
|
|
VALUE=$(grep_prop $VARNAME $PROPPATH)
|
2021-03-21 22:34:33 +00:00
|
|
|
[ ! -z $VALUE ] && eval $VARNAME=\$VALUE
|
2019-02-11 22:14:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
is_mounted() {
|
2021-01-22 10:28:53 +00:00
|
|
|
grep -q " $(readlink -f $1) " /proc/mounts 2>/dev/null
|
2019-02-11 22:14:07 +00:00
|
|
|
return $?
|
|
|
|
}
|
|
|
|
|
|
|
|
abort() {
|
|
|
|
ui_print "$1"
|
|
|
|
$BOOTMODE || recovery_cleanup
|
2021-03-21 22:34:33 +00:00
|
|
|
[ ! -z $MODPATH ] && rm -rf $MODPATH
|
2020-03-22 07:08:04 +00:00
|
|
|
rm -rf $TMPDIR
|
2019-02-11 22:14:07 +00:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2020-03-09 05:25:06 +00:00
|
|
|
print_title() {
|
2021-10-20 20:06:45 +00:00
|
|
|
local len line1len line2len bar
|
2020-04-21 23:14:18 +00:00
|
|
|
line1len=$(echo -n $1 | wc -c)
|
|
|
|
line2len=$(echo -n $2 | wc -c)
|
2020-11-30 00:35:34 +00:00
|
|
|
len=$line2len
|
|
|
|
[ $line1len -gt $line2len ] && len=$line1len
|
2020-03-09 05:25:06 +00:00
|
|
|
len=$((len + 2))
|
2021-10-20 20:06:45 +00:00
|
|
|
bar=$(printf "%${len}s" | tr ' ' '*')
|
|
|
|
ui_print "$bar"
|
2020-03-09 05:25:06 +00:00
|
|
|
ui_print " $1 "
|
2020-04-21 23:14:18 +00:00
|
|
|
[ "$2" ] && ui_print " $2 "
|
2021-10-20 20:06:45 +00:00
|
|
|
ui_print "$bar"
|
2020-03-09 05:25:06 +00:00
|
|
|
}
|
|
|
|
|
2019-02-11 22:14:07 +00:00
|
|
|
######################
|
|
|
|
# Environment Related
|
|
|
|
######################
|
2017-10-31 09:05:24 +00:00
|
|
|
|
2018-08-29 02:03:12 +00:00
|
|
|
setup_flashable() {
|
2019-02-24 07:11:11 +00:00
|
|
|
ensure_bb
|
|
|
|
$BOOTMODE && return
|
2018-07-07 09:48:05 +00:00
|
|
|
if [ -z $OUTFD ] || readlink /proc/$$/fd/$OUTFD | grep -q /tmp; then
|
2018-06-21 02:53:49 +00:00
|
|
|
# We will have to manually find out OUTFD
|
2023-08-29 01:35:20 +00:00
|
|
|
for FD in $(ls /proc/$$/fd); do
|
2018-07-07 09:48:05 +00:00
|
|
|
if readlink /proc/$$/fd/$FD | grep -q pipe; then
|
2020-02-04 19:55:03 +00:00
|
|
|
if ps | grep -v grep | grep -qE " 3 $FD |status_fd=$FD"; then
|
2017-07-09 16:17:34 +00:00
|
|
|
OUTFD=$FD
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
2021-01-22 10:28:53 +00:00
|
|
|
recovery_actions
|
2017-07-09 16:17:34 +00:00
|
|
|
}
|
|
|
|
|
2019-02-24 07:11:11 +00:00
|
|
|
ensure_bb() {
|
2020-03-19 10:48:23 +00:00
|
|
|
if set -o | grep -q standalone; then
|
|
|
|
# We are definitely in busybox ash
|
|
|
|
set -o standalone
|
|
|
|
return
|
|
|
|
fi
|
2020-03-09 05:25:06 +00:00
|
|
|
|
|
|
|
# Find our busybox binary
|
2020-03-19 10:48:23 +00:00
|
|
|
local bb
|
2020-03-09 05:25:06 +00:00
|
|
|
if [ -f $TMPDIR/busybox ]; then
|
2020-03-19 10:48:23 +00:00
|
|
|
bb=$TMPDIR/busybox
|
2020-03-09 05:25:06 +00:00
|
|
|
elif [ -f $MAGISKBIN/busybox ]; then
|
2020-03-19 10:48:23 +00:00
|
|
|
bb=$MAGISKBIN/busybox
|
2019-02-11 22:14:07 +00:00
|
|
|
else
|
2020-03-09 05:25:06 +00:00
|
|
|
abort "! Cannot find BusyBox"
|
2019-02-11 22:14:07 +00:00
|
|
|
fi
|
2020-03-19 10:48:23 +00:00
|
|
|
chmod 755 $bb
|
|
|
|
|
2020-12-28 08:24:03 +00:00
|
|
|
# Busybox could be a script, make sure /system/bin/sh exists
|
|
|
|
if [ ! -f /system/bin/sh ]; then
|
|
|
|
umount -l /system 2>/dev/null
|
|
|
|
mkdir -p /system/bin
|
|
|
|
ln -s $(command -v sh) /system/bin/sh
|
|
|
|
fi
|
|
|
|
|
|
|
|
export ASH_STANDALONE=1
|
|
|
|
|
2020-03-19 10:48:23 +00:00
|
|
|
# Find our current arguments
|
|
|
|
# Run in busybox environment to ensure consistent results
|
|
|
|
# /proc/<pid>/cmdline shall be <interpreter> <script> <arguments...>
|
2020-12-28 08:24:03 +00:00
|
|
|
local cmds="$($bb sh -c "
|
2020-03-20 11:02:48 +00:00
|
|
|
for arg in \$(tr '\0' '\n' < /proc/$$/cmdline); do
|
2020-03-19 10:48:23 +00:00
|
|
|
if [ -z \"\$cmds\" ]; then
|
|
|
|
# Skip the first argument as we want to change the interpreter
|
2020-12-28 08:24:03 +00:00
|
|
|
cmds=\"sh\"
|
2020-03-19 10:48:23 +00:00
|
|
|
else
|
|
|
|
cmds=\"\$cmds '\$arg'\"
|
|
|
|
fi
|
|
|
|
done
|
2020-10-14 08:42:26 +00:00
|
|
|
echo \$cmds")"
|
2020-03-09 05:25:06 +00:00
|
|
|
|
|
|
|
# Re-exec our script
|
2020-03-19 10:48:23 +00:00
|
|
|
echo $cmds | $bb xargs $bb
|
|
|
|
exit
|
2017-06-18 16:15:44 +00:00
|
|
|
}
|
|
|
|
|
2019-02-11 22:14:07 +00:00
|
|
|
recovery_actions() {
|
2020-01-11 21:48:21 +00:00
|
|
|
# Make sure random won't get blocked
|
2019-02-11 22:14:07 +00:00
|
|
|
mount -o bind /dev/urandom /dev/random
|
|
|
|
# Unset library paths
|
|
|
|
OLD_LD_LIB=$LD_LIBRARY_PATH
|
|
|
|
OLD_LD_PRE=$LD_PRELOAD
|
2019-02-24 07:11:11 +00:00
|
|
|
OLD_LD_CFG=$LD_CONFIG_FILE
|
2019-02-11 22:14:07 +00:00
|
|
|
unset LD_LIBRARY_PATH
|
|
|
|
unset LD_PRELOAD
|
2019-02-24 07:11:11 +00:00
|
|
|
unset LD_CONFIG_FILE
|
2019-02-11 22:14:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
recovery_cleanup() {
|
2020-02-04 19:55:03 +00:00
|
|
|
local DIR
|
2019-02-11 22:14:07 +00:00
|
|
|
ui_print "- Unmounting partitions"
|
2023-07-18 01:58:48 +00:00
|
|
|
(
|
2020-02-04 19:55:03 +00:00
|
|
|
if [ ! -d /postinstall/tmp ]; then
|
|
|
|
umount -l /system
|
|
|
|
umount -l /system_root
|
|
|
|
fi
|
2020-01-11 21:48:21 +00:00
|
|
|
umount -l /vendor
|
|
|
|
umount -l /persist
|
2020-11-03 07:20:38 +00:00
|
|
|
umount -l /metadata
|
2020-02-04 19:55:03 +00:00
|
|
|
for DIR in /apex /system /system_root; do
|
|
|
|
if [ -L "${DIR}_link" ]; then
|
|
|
|
rmdir $DIR
|
|
|
|
mv -f ${DIR}_link $DIR
|
|
|
|
fi
|
|
|
|
done
|
2023-07-18 01:58:48 +00:00
|
|
|
umount -l /dev/random
|
|
|
|
) 2>/dev/null
|
2019-12-27 09:53:27 +00:00
|
|
|
[ -z $OLD_LD_LIB ] || export LD_LIBRARY_PATH=$OLD_LD_LIB
|
|
|
|
[ -z $OLD_LD_PRE ] || export LD_PRELOAD=$OLD_LD_PRE
|
|
|
|
[ -z $OLD_LD_CFG ] || export LD_CONFIG_FILE=$OLD_LD_CFG
|
2018-06-20 17:37:08 +00:00
|
|
|
}
|
|
|
|
|
2019-02-11 22:14:07 +00:00
|
|
|
#######################
|
|
|
|
# Installation Related
|
|
|
|
#######################
|
|
|
|
|
2020-02-08 11:26:39 +00:00
|
|
|
# find_block [partname...]
|
2018-06-20 17:37:08 +00:00
|
|
|
find_block() {
|
2020-04-21 17:56:04 +00:00
|
|
|
local BLOCK DEV DEVICE DEVNAME PARTNAME UEVENT
|
2018-07-02 18:57:57 +00:00
|
|
|
for BLOCK in "$@"; do
|
2023-08-29 01:35:20 +00:00
|
|
|
DEVICE=$(find /dev/block \( -type b -o -type c -o -type l \) -iname $BLOCK | head -n 1) 2>/dev/null
|
2018-07-02 18:57:57 +00:00
|
|
|
if [ ! -z $DEVICE ]; then
|
2024-08-12 18:03:03 +00:00
|
|
|
echo $DEVICE
|
2018-07-02 18:57:57 +00:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
# Fallback by parsing sysfs uevents
|
2020-04-21 17:56:04 +00:00
|
|
|
for UEVENT in /sys/dev/block/*/uevent; do
|
2023-08-29 01:35:20 +00:00
|
|
|
DEVNAME=$(grep_prop DEVNAME $UEVENT)
|
|
|
|
PARTNAME=$(grep_prop PARTNAME $UEVENT)
|
2018-12-24 13:36:37 +00:00
|
|
|
for BLOCK in "$@"; do
|
2020-04-21 17:56:04 +00:00
|
|
|
if [ "$(toupper $BLOCK)" = "$(toupper $PARTNAME)" ]; then
|
2018-06-20 17:37:08 +00:00
|
|
|
echo /dev/block/$DEVNAME
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
done
|
2020-04-21 17:56:04 +00:00
|
|
|
# Look just in /dev in case we're dealing with MTD/NAND without /dev/block devices/links
|
|
|
|
for DEV in "$@"; do
|
2023-08-29 01:35:20 +00:00
|
|
|
DEVICE=$(find /dev \( -type b -o -type c -o -type l \) -maxdepth 1 -iname $DEV | head -n 1) 2>/dev/null
|
2020-04-21 17:56:04 +00:00
|
|
|
if [ ! -z $DEVICE ]; then
|
2024-08-12 18:03:03 +00:00
|
|
|
echo $DEVICE
|
2020-04-21 17:56:04 +00:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
done
|
2018-06-20 17:37:08 +00:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2020-02-08 11:26:39 +00:00
|
|
|
# setup_mntpoint <mountpoint>
|
|
|
|
setup_mntpoint() {
|
2020-02-04 19:55:03 +00:00
|
|
|
local POINT=$1
|
|
|
|
[ -L $POINT ] && mv -f $POINT ${POINT}_link
|
|
|
|
if [ ! -d $POINT ]; then
|
|
|
|
rm -f $POINT
|
|
|
|
mkdir -p $POINT
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-02-08 11:26:39 +00:00
|
|
|
# mount_name <partname(s)> <mountpoint> <flag>
|
2019-12-27 09:53:27 +00:00
|
|
|
mount_name() {
|
2019-04-30 21:35:58 +00:00
|
|
|
local PART=$1
|
2019-12-27 09:53:27 +00:00
|
|
|
local POINT=$2
|
|
|
|
local FLAG=$3
|
2020-02-08 11:26:39 +00:00
|
|
|
setup_mntpoint $POINT
|
2019-04-30 21:35:58 +00:00
|
|
|
is_mounted $POINT && return
|
2019-12-27 09:53:27 +00:00
|
|
|
# First try mounting with fstab
|
|
|
|
mount $FLAG $POINT 2>/dev/null
|
2019-04-30 21:35:58 +00:00
|
|
|
if ! is_mounted $POINT; then
|
2020-11-03 07:20:38 +00:00
|
|
|
local BLOCK=$(find_block $PART)
|
|
|
|
mount $FLAG $BLOCK $POINT || return
|
2019-04-30 21:35:58 +00:00
|
|
|
fi
|
2020-11-03 07:20:38 +00:00
|
|
|
ui_print "- Mounting $POINT"
|
2019-12-27 09:53:27 +00:00
|
|
|
}
|
|
|
|
|
2020-02-08 11:26:39 +00:00
|
|
|
# mount_ro_ensure <partname(s)> <mountpoint>
|
2019-12-27 09:53:27 +00:00
|
|
|
mount_ro_ensure() {
|
|
|
|
# We handle ro partitions only in recovery
|
|
|
|
$BOOTMODE && return
|
2020-01-11 21:48:21 +00:00
|
|
|
local PART=$1
|
|
|
|
local POINT=$2
|
|
|
|
mount_name "$PART" $POINT '-o ro'
|
2019-04-30 21:35:58 +00:00
|
|
|
is_mounted $POINT || abort "! Cannot mount $POINT"
|
|
|
|
}
|
|
|
|
|
2023-08-29 01:35:20 +00:00
|
|
|
# After calling this method, the following variables will be set:
|
2023-09-24 08:22:24 +00:00
|
|
|
# SLOT, SYSTEM_AS_ROOT, LEGACYSAR
|
2017-09-12 20:07:25 +00:00
|
|
|
mount_partitions() {
|
|
|
|
# Check A/B slot
|
2023-07-17 23:07:16 +00:00
|
|
|
SLOT=$(grep_cmdline androidboot.slot_suffix)
|
2018-06-20 17:37:08 +00:00
|
|
|
if [ -z $SLOT ]; then
|
2023-07-17 23:07:16 +00:00
|
|
|
SLOT=$(grep_cmdline androidboot.slot)
|
2019-04-30 21:35:58 +00:00
|
|
|
[ -z $SLOT ] || SLOT=_${SLOT}
|
2017-11-10 17:33:50 +00:00
|
|
|
fi
|
2023-01-31 23:37:39 +00:00
|
|
|
[ "$SLOT" = "normal" ] && unset SLOT
|
2018-06-20 17:37:08 +00:00
|
|
|
[ -z $SLOT ] || ui_print "- Current boot slot: $SLOT"
|
2018-01-01 08:46:28 +00:00
|
|
|
|
2019-12-27 09:53:27 +00:00
|
|
|
# Mount ro partitions
|
2020-11-08 13:10:18 +00:00
|
|
|
if is_mounted /system_root; then
|
2023-04-06 01:53:55 +00:00
|
|
|
umount /system 2>/dev/null
|
|
|
|
umount /system_root 2>/dev/null
|
2020-11-08 13:10:18 +00:00
|
|
|
fi
|
2020-01-11 21:48:21 +00:00
|
|
|
mount_ro_ensure "system$SLOT app$SLOT" /system
|
2020-04-20 11:18:19 +00:00
|
|
|
if [ -f /system/init -o -L /system/init ]; then
|
2023-08-29 05:13:24 +00:00
|
|
|
SYSTEM_AS_ROOT=true
|
2020-02-08 11:26:39 +00:00
|
|
|
setup_mntpoint /system_root
|
2020-03-09 05:38:47 +00:00
|
|
|
if ! mount --move /system /system_root; then
|
|
|
|
umount /system
|
|
|
|
umount -l /system 2>/dev/null
|
|
|
|
mount_ro_ensure "system$SLOT app$SLOT" /system_root
|
|
|
|
fi
|
2017-09-12 20:07:25 +00:00
|
|
|
mount -o bind /system_root/system /system
|
2019-04-30 21:35:58 +00:00
|
|
|
else
|
2023-08-29 01:35:20 +00:00
|
|
|
if grep ' / ' /proc/mounts | grep -qv 'rootfs' || grep -q ' /system_root ' /proc/mounts; then
|
2023-08-29 05:13:24 +00:00
|
|
|
SYSTEM_AS_ROOT=true
|
2023-08-29 01:35:20 +00:00
|
|
|
else
|
2023-08-29 05:13:24 +00:00
|
|
|
SYSTEM_AS_ROOT=false
|
2023-08-29 01:35:20 +00:00
|
|
|
fi
|
2017-09-12 20:07:25 +00:00
|
|
|
fi
|
2023-08-29 05:13:24 +00:00
|
|
|
$SYSTEM_AS_ROOT && ui_print "- Device is system-as-root"
|
2023-09-24 08:22:24 +00:00
|
|
|
|
|
|
|
LEGACYSAR=false
|
|
|
|
if $BOOTMODE; then
|
|
|
|
grep ' / ' /proc/mounts | grep -q '/dev/root' && LEGACYSAR=true
|
|
|
|
else
|
|
|
|
# Recovery mode, assume devices that don't use dynamic partitions are legacy SAR
|
|
|
|
local IS_DYNAMIC=false
|
|
|
|
if grep -q 'androidboot.super_partition' /proc/cmdline; then
|
|
|
|
IS_DYNAMIC=true
|
|
|
|
elif [ -n "$(find_block super)" ]; then
|
|
|
|
IS_DYNAMIC=true
|
|
|
|
fi
|
|
|
|
if $SYSTEM_AS_ROOT && ! $IS_DYNAMIC; then
|
|
|
|
LEGACYSAR=true
|
|
|
|
ui_print "- Legacy SAR, force kernel to load rootfs"
|
|
|
|
fi
|
|
|
|
fi
|
2020-01-11 21:48:21 +00:00
|
|
|
}
|
|
|
|
|
2022-01-12 10:21:26 +00:00
|
|
|
# After calling this method, the following variables will be set:
|
2023-09-24 08:22:24 +00:00
|
|
|
# ISENCRYPTED, PATCHVBMETAFLAG,
|
2023-08-29 05:13:24 +00:00
|
|
|
# KEEPVERITY, KEEPFORCEENCRYPT, RECOVERYMODE
|
2018-06-17 17:40:56 +00:00
|
|
|
get_flags() {
|
2023-08-29 05:13:24 +00:00
|
|
|
if grep ' /data ' /proc/mounts | grep -q 'dm-'; then
|
|
|
|
ISENCRYPTED=true
|
|
|
|
elif [ "$(getprop ro.crypto.state)" = "encrypted" ]; then
|
|
|
|
ISENCRYPTED=true
|
2023-08-29 09:14:35 +00:00
|
|
|
elif [ "$DATA" = "false" ]; then
|
2023-08-29 05:13:24 +00:00
|
|
|
# No data access means unable to decrypt in recovery
|
|
|
|
ISENCRYPTED=true
|
|
|
|
else
|
|
|
|
ISENCRYPTED=false
|
|
|
|
fi
|
|
|
|
if [ -n "$(find_block vbmeta vbmeta_a)" ]; then
|
|
|
|
PATCHVBMETAFLAG=false
|
|
|
|
else
|
|
|
|
PATCHVBMETAFLAG=true
|
|
|
|
ui_print "- No vbmeta partition, patch vbmeta in boot image"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Overridable config flags with safe defaults
|
2018-06-17 17:40:56 +00:00
|
|
|
getvar KEEPVERITY
|
|
|
|
getvar KEEPFORCEENCRYPT
|
2018-12-24 17:08:46 +00:00
|
|
|
getvar RECOVERYMODE
|
2018-06-17 17:40:56 +00:00
|
|
|
if [ -z $KEEPVERITY ]; then
|
2023-08-29 05:13:24 +00:00
|
|
|
if $SYSTEM_AS_ROOT; then
|
2018-08-29 04:40:14 +00:00
|
|
|
KEEPVERITY=true
|
2023-08-29 05:13:24 +00:00
|
|
|
ui_print "- System-as-root, keep dm-verity"
|
2018-08-29 04:40:14 +00:00
|
|
|
else
|
|
|
|
KEEPVERITY=false
|
|
|
|
fi
|
2018-06-17 17:40:56 +00:00
|
|
|
fi
|
|
|
|
if [ -z $KEEPFORCEENCRYPT ]; then
|
2023-08-29 05:13:24 +00:00
|
|
|
if $ISENCRYPTED; then
|
2018-06-17 17:40:56 +00:00
|
|
|
KEEPFORCEENCRYPT=true
|
2019-03-03 11:35:25 +00:00
|
|
|
ui_print "- Encrypted data, keep forceencrypt"
|
2018-06-17 17:40:56 +00:00
|
|
|
else
|
|
|
|
KEEPFORCEENCRYPT=false
|
|
|
|
fi
|
|
|
|
fi
|
2018-12-24 17:08:46 +00:00
|
|
|
[ -z $RECOVERYMODE ] && RECOVERYMODE=false
|
2018-06-17 17:40:56 +00:00
|
|
|
}
|
|
|
|
|
2018-06-20 17:37:08 +00:00
|
|
|
find_boot_image() {
|
|
|
|
BOOTIMAGE=
|
2019-03-30 04:49:48 +00:00
|
|
|
if $RECOVERYMODE; then
|
2024-08-05 18:24:30 +00:00
|
|
|
BOOTIMAGE=$(find_block "recovery$SLOT" "sos")
|
2024-08-12 19:29:21 +00:00
|
|
|
elif [ -e "/dev/block/by-name/init_boot$SLOT" ] && [ "$(uname -r | cut -d. -f1)" -ge 5 ] && uname -r | grep -Evq "android12-|^5\.4"; then
|
2024-08-05 18:24:30 +00:00
|
|
|
# init_boot is only used with GKI 13+. It is possible that some devices with init_boot
|
2024-08-12 18:49:27 +00:00
|
|
|
# partition still uses Android 12 GKI or previous kernels, so we need to explicitly detect that scenario.
|
2024-08-12 18:03:03 +00:00
|
|
|
BOOTIMAGE="/dev/block/by-name/init_boot$SLOT"
|
|
|
|
elif [ -e "/dev/block/by-name/boot$SLOT" ]; then
|
2024-08-05 18:24:30 +00:00
|
|
|
# Standard location since AOSP Android 10+
|
2024-08-12 18:03:03 +00:00
|
|
|
BOOTIMAGE="/dev/block/by-name/boot$SLOT"
|
2024-08-05 18:24:30 +00:00
|
|
|
elif [ -n "$SLOT" ]; then
|
|
|
|
# Fallback for A/B devices running < Android 10
|
|
|
|
BOOTIMAGE=$(find_block "ramdisk$SLOT" "boot$SLOT")
|
2018-06-20 17:37:08 +00:00
|
|
|
else
|
2024-08-05 18:24:30 +00:00
|
|
|
# Fallback for all legacy and non-standard devices
|
|
|
|
BOOTIMAGE=$(find_block ramdisk kern-a android_boot kernel bootimg boot lnx boot_a)
|
2024-06-30 17:29:54 +00:00
|
|
|
fi
|
2018-07-03 10:28:44 +00:00
|
|
|
if [ -z $BOOTIMAGE ]; then
|
|
|
|
# Lets see what fstabs tells me
|
2022-02-05 17:36:02 +00:00
|
|
|
BOOTIMAGE=$(grep -v '#' /etc/*fstab* | grep -E '/boot(img)?[^a-zA-Z]' | grep -oE '/dev/[a-zA-Z0-9_./-]*' | head -n 1)
|
2018-07-03 10:28:44 +00:00
|
|
|
fi
|
2018-06-20 17:37:08 +00:00
|
|
|
}
|
|
|
|
|
2018-08-10 10:59:14 +00:00
|
|
|
flash_image() {
|
2023-07-18 01:58:48 +00:00
|
|
|
local CMD1
|
2017-09-26 12:21:43 +00:00
|
|
|
case "$1" in
|
2021-01-22 10:28:53 +00:00
|
|
|
*.gz) CMD1="gzip -d < '$1' 2>/dev/null";;
|
2019-02-11 22:14:07 +00:00
|
|
|
*) CMD1="cat '$1'";;
|
2017-09-26 12:21:43 +00:00
|
|
|
esac
|
2018-08-10 10:59:14 +00:00
|
|
|
if [ -b "$2" ]; then
|
2020-12-19 22:12:12 +00:00
|
|
|
local img_sz=$(stat -c '%s' "$1")
|
|
|
|
local blk_sz=$(blockdev --getsize64 "$2")
|
|
|
|
[ "$img_sz" -gt "$blk_sz" ] && return 1
|
|
|
|
blockdev --setrw "$2"
|
|
|
|
local blk_ro=$(blockdev --getro "$2")
|
|
|
|
[ "$blk_ro" -eq 1 ] && return 2
|
2023-07-18 01:58:48 +00:00
|
|
|
eval "$CMD1" | cat - /dev/zero > "$2" 2>/dev/null
|
2020-03-11 19:57:52 +00:00
|
|
|
elif [ -c "$2" ]; then
|
2020-06-01 09:08:13 +00:00
|
|
|
flash_eraseall "$2" >&2
|
2023-07-18 01:58:48 +00:00
|
|
|
eval "$CMD1" | nandwrite -p "$2" - >&2
|
2018-08-10 10:59:14 +00:00
|
|
|
else
|
2020-03-11 19:57:52 +00:00
|
|
|
ui_print "- Not block or char device, storing image"
|
2023-07-18 01:58:48 +00:00
|
|
|
eval "$CMD1" > "$2" 2>/dev/null
|
2018-02-09 19:34:13 +00:00
|
|
|
fi
|
2018-08-11 07:56:12 +00:00
|
|
|
return 0
|
2017-09-06 08:13:23 +00:00
|
|
|
}
|
|
|
|
|
2019-12-27 09:53:27 +00:00
|
|
|
# Common installation script for flash_script.sh and addon.d.sh
|
2020-01-01 06:02:44 +00:00
|
|
|
install_magisk() {
|
2019-11-02 03:26:08 +00:00
|
|
|
cd $MAGISKBIN
|
|
|
|
|
|
|
|
# Source the boot patcher
|
2020-01-01 06:02:44 +00:00
|
|
|
SOURCEDMODE=true
|
2019-11-02 03:26:08 +00:00
|
|
|
. ./boot_patch.sh "$BOOTIMAGE"
|
|
|
|
|
|
|
|
ui_print "- Flashing new boot image"
|
2020-12-19 22:12:12 +00:00
|
|
|
flash_image new-boot.img "$BOOTIMAGE"
|
|
|
|
case $? in
|
|
|
|
1)
|
|
|
|
abort "! Insufficient partition size"
|
|
|
|
;;
|
|
|
|
2)
|
|
|
|
abort "! $BOOTIMAGE is read only"
|
|
|
|
;;
|
|
|
|
esac
|
2019-11-02 03:26:08 +00:00
|
|
|
|
|
|
|
./magiskboot cleanup
|
|
|
|
rm -f new-boot.img
|
|
|
|
|
2020-01-01 06:02:44 +00:00
|
|
|
run_migrations
|
2019-11-02 03:26:08 +00:00
|
|
|
}
|
|
|
|
|
2017-09-06 08:13:23 +00:00
|
|
|
sign_chromeos() {
|
2017-10-07 14:08:10 +00:00
|
|
|
ui_print "- Signing ChromeOS boot image"
|
2017-09-06 08:13:23 +00:00
|
|
|
|
2017-10-07 14:08:10 +00:00
|
|
|
echo > empty
|
2018-05-05 17:48:24 +00:00
|
|
|
./chromeos/futility vbutil_kernel --pack new-boot.img.signed \
|
2017-09-06 08:13:23 +00:00
|
|
|
--keyblock ./chromeos/kernel.keyblock --signprivate ./chromeos/kernel_data_key.vbprivk \
|
|
|
|
--version 1 --vmlinuz new-boot.img --config empty --arch arm --bootloader empty --flags 0x1
|
|
|
|
|
|
|
|
rm -f empty new-boot.img
|
|
|
|
mv new-boot.img.signed new-boot.img
|
|
|
|
}
|
|
|
|
|
2017-06-18 16:15:44 +00:00
|
|
|
remove_system_su() {
|
2022-12-21 00:16:57 +00:00
|
|
|
[ -d /postinstall/tmp ] && POSTINST=/postinstall
|
|
|
|
cd $POSTINST/system
|
|
|
|
if [ -f bin/su -o -f xbin/su ] && [ ! -f /su/bin/su ]; then
|
2018-08-29 02:03:12 +00:00
|
|
|
ui_print "- Removing system installed root"
|
2020-04-20 04:20:19 +00:00
|
|
|
blockdev --setrw /dev/block/mapper/system$SLOT 2>/dev/null
|
2022-12-21 00:16:57 +00:00
|
|
|
mount -o rw,remount $POSTINST/system
|
2017-06-18 16:15:44 +00:00
|
|
|
# SuperSU
|
2022-12-21 00:16:57 +00:00
|
|
|
cd bin
|
|
|
|
if [ -e .ext/.su ]; then
|
|
|
|
mv -f app_process32_original app_process32 2>/dev/null
|
|
|
|
mv -f app_process64_original app_process64 2>/dev/null
|
|
|
|
mv -f install-recovery_original.sh install-recovery.sh 2>/dev/null
|
2017-06-18 16:15:44 +00:00
|
|
|
if [ -e app_process64 ]; then
|
|
|
|
ln -sf app_process64 app_process
|
2019-02-12 06:48:33 +00:00
|
|
|
elif [ -e app_process32 ]; then
|
2017-06-18 16:15:44 +00:00
|
|
|
ln -sf app_process32 app_process
|
|
|
|
fi
|
|
|
|
fi
|
2022-12-21 00:16:57 +00:00
|
|
|
# More SuperSU, SuperUser & ROM su
|
|
|
|
cd ..
|
|
|
|
rm -rf .pin bin/.ext etc/.installed_su_daemon etc/.has_su_daemon \
|
|
|
|
xbin/daemonsu xbin/su xbin/sugote xbin/sugote-mksh xbin/supolicy \
|
|
|
|
bin/app_process_init bin/su /cache/su lib/libsupol.so lib64/libsupol.so \
|
|
|
|
su.d etc/init.d/99SuperSUDaemon etc/install-recovery.sh /cache/install-recovery.sh \
|
|
|
|
.supersu /cache/.supersu /data/.supersu \
|
|
|
|
app/Superuser.apk app/SuperSU /cache/Superuser.apk
|
|
|
|
elif [ -f /cache/su.img -o -f /data/su.img -o -d /data/su -o -d /data/adb/su ]; then
|
2020-01-11 21:48:21 +00:00
|
|
|
ui_print "- Removing systemless installed root"
|
|
|
|
umount -l /su 2>/dev/null
|
2022-12-21 00:16:57 +00:00
|
|
|
rm -rf /cache/su.img /data/su.img /data/su /data/adb/su /data/adb/suhide \
|
|
|
|
/cache/.supersu /data/.supersu /cache/supersu_install /data/supersu_install
|
2017-06-18 16:15:44 +00:00
|
|
|
fi
|
2022-12-21 00:16:57 +00:00
|
|
|
cd $TMPDIR
|
2017-06-18 16:15:44 +00:00
|
|
|
}
|
|
|
|
|
2017-07-02 13:36:09 +00:00
|
|
|
api_level_arch_detect() {
|
2021-04-06 10:56:39 +00:00
|
|
|
API=$(grep_get_prop ro.build.version.sdk)
|
2021-05-13 07:21:04 +00:00
|
|
|
ABI=$(grep_get_prop ro.product.cpu.abi)
|
2024-04-04 14:15:14 +00:00
|
|
|
if [ "$ABI" = "arm64-v8a" ]; then
|
2021-05-13 07:21:04 +00:00
|
|
|
ARCH=arm64
|
|
|
|
ABI32=armeabi-v7a
|
|
|
|
IS64BIT=true
|
|
|
|
elif [ "$ABI" = "x86_64" ]; then
|
|
|
|
ARCH=x64
|
|
|
|
ABI32=x86
|
|
|
|
IS64BIT=true
|
2024-04-04 14:15:14 +00:00
|
|
|
elif [ "$ABI" = "armeabi-v7a" ]; then
|
2021-05-13 07:21:04 +00:00
|
|
|
ARCH=arm
|
|
|
|
ABI32=armeabi-v7a
|
|
|
|
IS64BIT=false
|
2024-04-04 14:15:14 +00:00
|
|
|
elif [ "$ABI" = "x86" ]; then
|
|
|
|
ARCH=x86
|
|
|
|
ABI32=x86
|
|
|
|
IS64BIT=false
|
|
|
|
elif [ "$ABI" = "riscv64" ]; then
|
|
|
|
ARCH=riscv64
|
|
|
|
ABI32=riscv32
|
|
|
|
IS64BIT=true
|
2021-05-13 07:21:04 +00:00
|
|
|
fi
|
2017-07-02 13:36:09 +00:00
|
|
|
}
|
|
|
|
|
2018-06-26 14:41:03 +00:00
|
|
|
check_data() {
|
|
|
|
DATA=false
|
|
|
|
DATA_DE=false
|
|
|
|
if grep ' /data ' /proc/mounts | grep -vq 'tmpfs'; then
|
|
|
|
# Test if data is writable
|
|
|
|
touch /data/.rw && rm /data/.rw && DATA=true
|
2021-03-13 16:32:30 +00:00
|
|
|
# Test if data is decrypted
|
2018-06-26 14:41:03 +00:00
|
|
|
$DATA && [ -d /data/adb ] && touch /data/adb/.rw && rm /data/adb/.rw && DATA_DE=true
|
2020-12-09 12:11:23 +00:00
|
|
|
$DATA_DE && [ -d /data/adb/magisk ] || mkdir /data/adb/magisk || DATA_DE=false
|
2018-06-26 14:41:03 +00:00
|
|
|
fi
|
2024-07-16 18:16:15 +00:00
|
|
|
MAGISKBIN="/data/magisk"
|
|
|
|
$DATA || MAGISKBIN="/cache/data_adb/magisk"
|
|
|
|
$DATA_DE && MAGISKBIN="/data/adb/magisk"
|
2018-06-26 14:41:03 +00:00
|
|
|
}
|
|
|
|
|
2020-01-01 06:02:44 +00:00
|
|
|
run_migrations() {
|
|
|
|
local LOCSHA1
|
|
|
|
local TARGET
|
|
|
|
# Legacy app installation
|
2021-11-18 02:53:33 +00:00
|
|
|
local BACKUP=$MAGISKBIN/stock_boot*.gz
|
2020-01-01 06:02:44 +00:00
|
|
|
if [ -f $BACKUP ]; then
|
|
|
|
cp $BACKUP /data
|
|
|
|
rm -f $BACKUP
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Legacy backup
|
|
|
|
for gz in /data/stock_boot*.gz; do
|
|
|
|
[ -f $gz ] || break
|
2023-08-29 01:35:20 +00:00
|
|
|
LOCSHA1=$(basename $gz | sed -e 's/stock_boot_//' -e 's/.img.gz//')
|
2020-01-01 06:02:44 +00:00
|
|
|
[ -z $LOCSHA1 ] && break
|
|
|
|
mkdir /data/magisk_backup_${LOCSHA1} 2>/dev/null
|
|
|
|
mv $gz /data/magisk_backup_${LOCSHA1}/boot.img.gz
|
|
|
|
done
|
|
|
|
|
|
|
|
# Stock backups
|
|
|
|
LOCSHA1=$SHA1
|
2020-04-14 04:24:02 +00:00
|
|
|
for name in boot dtb dtbo dtbs; do
|
2021-11-18 02:53:33 +00:00
|
|
|
BACKUP=$MAGISKBIN/stock_${name}.img
|
2020-01-01 06:02:44 +00:00
|
|
|
[ -f $BACKUP ] || continue
|
|
|
|
if [ $name = 'boot' ]; then
|
2023-08-29 01:35:20 +00:00
|
|
|
LOCSHA1=$($MAGISKBIN/magiskboot sha1 $BACKUP)
|
2020-01-01 06:02:44 +00:00
|
|
|
mkdir /data/magisk_backup_${LOCSHA1} 2>/dev/null
|
|
|
|
fi
|
|
|
|
TARGET=/data/magisk_backup_${LOCSHA1}/${name}.img
|
|
|
|
cp $BACKUP $TARGET
|
|
|
|
rm -f $BACKUP
|
|
|
|
gzip -9f $TARGET
|
|
|
|
done
|
2024-07-23 09:21:49 +00:00
|
|
|
|
|
|
|
copy_preinit_files
|
2020-01-01 06:02:44 +00:00
|
|
|
}
|
|
|
|
|
2023-03-16 11:07:00 +00:00
|
|
|
copy_preinit_files() {
|
2024-07-17 22:53:11 +00:00
|
|
|
local PREINITDIR=$MAGISKTMP/.magisk/preinit
|
|
|
|
if [ ! -d $PREINITDIR ]; then
|
2023-03-22 06:58:45 +00:00
|
|
|
ui_print "- Unable to find preinit dir"
|
2021-07-27 09:37:22 +00:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2020-11-03 07:20:38 +00:00
|
|
|
# Copy all enabled sepolicy.rule
|
2024-07-16 18:16:15 +00:00
|
|
|
for r in /data/adb/modules*/*/sepolicy.rule; do
|
2020-11-03 07:20:38 +00:00
|
|
|
[ -f "$r" ] || continue
|
|
|
|
local MODDIR=${r%/*}
|
|
|
|
[ -f $MODDIR/disable ] && continue
|
|
|
|
[ -f $MODDIR/remove ] && continue
|
2023-02-28 12:36:58 +00:00
|
|
|
[ -f $MODDIR/update ] && continue
|
2024-07-17 22:53:11 +00:00
|
|
|
cat $r
|
|
|
|
echo
|
2024-07-18 10:40:45 +00:00
|
|
|
done > $PREINITDIR/sepolicy.rule
|
2020-11-03 07:20:38 +00:00
|
|
|
}
|
|
|
|
|
2019-02-11 22:14:07 +00:00
|
|
|
#################
|
|
|
|
# Module Related
|
|
|
|
#################
|
2017-07-09 16:17:34 +00:00
|
|
|
|
|
|
|
set_perm() {
|
2018-02-09 19:34:13 +00:00
|
|
|
chown $2:$3 $1 || return 1
|
|
|
|
chmod $4 $1 || return 1
|
2021-10-20 20:01:51 +00:00
|
|
|
local CON=$5
|
2019-02-12 07:14:57 +00:00
|
|
|
[ -z $CON ] && CON=u:object_r:system_file:s0
|
|
|
|
chcon $CON $1 || return 1
|
2017-07-09 16:17:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
set_perm_recursive() {
|
|
|
|
find $1 -type d 2>/dev/null | while read dir; do
|
|
|
|
set_perm $dir $2 $3 $4 $6
|
|
|
|
done
|
2017-07-30 19:03:52 +00:00
|
|
|
find $1 -type f -o -type l 2>/dev/null | while read file; do
|
2017-07-09 16:17:34 +00:00
|
|
|
set_perm $file $2 $3 $5 $6
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
mktouch() {
|
2017-07-30 19:03:52 +00:00
|
|
|
mkdir -p ${1%/*} 2>/dev/null
|
|
|
|
[ -z $2 ] && touch $1 || echo $2 > $1
|
2017-07-09 16:17:34 +00:00
|
|
|
chmod 644 $1
|
|
|
|
}
|
|
|
|
|
2019-02-24 07:11:11 +00:00
|
|
|
boot_actions() { return; }
|
2019-02-11 22:14:07 +00:00
|
|
|
|
2020-03-15 07:22:40 +00:00
|
|
|
# Require ZIPFILE to be set
|
|
|
|
is_legacy_script() {
|
|
|
|
unzip -l "$ZIPFILE" install.sh | grep -q install.sh
|
|
|
|
return $?
|
|
|
|
}
|
|
|
|
|
|
|
|
# Require OUTFD, ZIPFILE to be set
|
|
|
|
install_module() {
|
2020-03-19 10:53:01 +00:00
|
|
|
rm -rf $TMPDIR
|
|
|
|
mkdir -p $TMPDIR
|
2022-06-07 09:18:41 +00:00
|
|
|
chcon u:object_r:system_file:s0 $TMPDIR
|
2021-01-25 04:58:30 +00:00
|
|
|
cd $TMPDIR
|
2020-03-19 10:53:01 +00:00
|
|
|
|
2020-03-15 07:22:40 +00:00
|
|
|
setup_flashable
|
|
|
|
mount_partitions
|
|
|
|
api_level_arch_detect
|
|
|
|
|
|
|
|
# Setup busybox and binaries
|
2020-11-30 00:35:34 +00:00
|
|
|
if $BOOTMODE; then
|
|
|
|
boot_actions
|
|
|
|
else
|
|
|
|
recovery_actions
|
|
|
|
fi
|
2020-03-15 07:22:40 +00:00
|
|
|
|
|
|
|
# Extract prop file
|
|
|
|
unzip -o "$ZIPFILE" module.prop -d $TMPDIR >&2
|
|
|
|
[ ! -f $TMPDIR/module.prop ] && abort "! Unable to extract zip file!"
|
|
|
|
|
2020-11-30 00:35:34 +00:00
|
|
|
local MODDIRNAME=modules
|
|
|
|
$BOOTMODE && MODDIRNAME=modules_update
|
2024-07-16 18:16:15 +00:00
|
|
|
local MODULEROOT=/data/adb/$MODDIRNAME
|
2023-08-29 01:35:20 +00:00
|
|
|
MODID=$(grep_prop id $TMPDIR/module.prop)
|
|
|
|
MODNAME=$(grep_prop name $TMPDIR/module.prop)
|
|
|
|
MODAUTH=$(grep_prop author $TMPDIR/module.prop)
|
2020-04-21 23:14:18 +00:00
|
|
|
MODPATH=$MODULEROOT/$MODID
|
2020-03-15 07:22:40 +00:00
|
|
|
|
|
|
|
# Create mod paths
|
2020-11-03 07:20:38 +00:00
|
|
|
rm -rf $MODPATH
|
2020-03-15 07:22:40 +00:00
|
|
|
mkdir -p $MODPATH
|
|
|
|
|
|
|
|
if is_legacy_script; then
|
|
|
|
unzip -oj "$ZIPFILE" module.prop install.sh uninstall.sh 'common/*' -d $TMPDIR >&2
|
|
|
|
|
|
|
|
# Load install script
|
|
|
|
. $TMPDIR/install.sh
|
|
|
|
|
|
|
|
# Callbacks
|
|
|
|
print_modname
|
|
|
|
on_install
|
|
|
|
|
|
|
|
[ -f $TMPDIR/uninstall.sh ] && cp -af $TMPDIR/uninstall.sh $MODPATH/uninstall.sh
|
|
|
|
$SKIPMOUNT && touch $MODPATH/skip_mount
|
|
|
|
$PROPFILE && cp -af $TMPDIR/system.prop $MODPATH/system.prop
|
|
|
|
cp -af $TMPDIR/module.prop $MODPATH/module.prop
|
|
|
|
$POSTFSDATA && cp -af $TMPDIR/post-fs-data.sh $MODPATH/post-fs-data.sh
|
|
|
|
$LATESTARTSERVICE && cp -af $TMPDIR/service.sh $MODPATH/service.sh
|
|
|
|
|
|
|
|
ui_print "- Setting permissions"
|
|
|
|
set_permissions
|
|
|
|
else
|
2020-04-21 23:14:18 +00:00
|
|
|
print_title "$MODNAME" "by $MODAUTH"
|
2020-03-15 07:22:40 +00:00
|
|
|
print_title "Powered by Magisk"
|
|
|
|
|
|
|
|
unzip -o "$ZIPFILE" customize.sh -d $MODPATH >&2
|
|
|
|
|
|
|
|
if ! grep -q '^SKIPUNZIP=1$' $MODPATH/customize.sh 2>/dev/null; then
|
|
|
|
ui_print "- Extracting module files"
|
|
|
|
unzip -o "$ZIPFILE" -x 'META-INF/*' -d $MODPATH >&2
|
|
|
|
|
|
|
|
# Default permissions
|
|
|
|
set_perm_recursive $MODPATH 0 0 0755 0644
|
2021-10-20 20:01:51 +00:00
|
|
|
set_perm_recursive $MODPATH/system/bin 0 2000 0755 0755
|
|
|
|
set_perm_recursive $MODPATH/system/xbin 0 2000 0755 0755
|
|
|
|
set_perm_recursive $MODPATH/system/system_ext/bin 0 2000 0755 0755
|
|
|
|
set_perm_recursive $MODPATH/system/vendor/bin 0 2000 0755 0755 u:object_r:vendor_file:s0
|
2020-03-15 07:22:40 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Load customization script
|
|
|
|
[ -f $MODPATH/customize.sh ] && . $MODPATH/customize.sh
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Handle replace folders
|
|
|
|
for TARGET in $REPLACE; do
|
|
|
|
ui_print "- Replace target: $TARGET"
|
|
|
|
mktouch $MODPATH$TARGET/.replace
|
|
|
|
done
|
|
|
|
|
|
|
|
if $BOOTMODE; then
|
2021-03-21 22:25:56 +00:00
|
|
|
# Update info for Magisk app
|
2024-07-16 18:16:15 +00:00
|
|
|
mktouch /data/adb/modules/$MODID/update
|
|
|
|
rm -rf /data/adb/modules/$MODID/remove 2>/dev/null
|
|
|
|
rm -rf /data/adb/modules/$MODID/disable 2>/dev/null
|
|
|
|
cp -af $MODPATH/module.prop /data/adb/modules/$MODID/module.prop
|
2020-03-15 07:22:40 +00:00
|
|
|
fi
|
|
|
|
|
2023-03-16 11:07:00 +00:00
|
|
|
# Copy over custom sepolicy rules
|
2020-11-03 07:20:38 +00:00
|
|
|
if [ -f $MODPATH/sepolicy.rule ]; then
|
|
|
|
ui_print "- Installing custom sepolicy rules"
|
2023-03-16 11:07:00 +00:00
|
|
|
copy_preinit_files
|
2020-03-15 07:22:40 +00:00
|
|
|
fi
|
|
|
|
|
2021-03-21 23:36:03 +00:00
|
|
|
# Remove stuff that doesn't belong to modules and clean up any empty directories
|
2020-03-15 07:22:40 +00:00
|
|
|
rm -rf \
|
|
|
|
$MODPATH/system/placeholder $MODPATH/customize.sh \
|
2020-11-03 07:20:38 +00:00
|
|
|
$MODPATH/README.md $MODPATH/.git*
|
2022-04-25 10:37:51 +00:00
|
|
|
rmdir -p $MODPATH 2>/dev/null
|
2020-03-15 07:22:40 +00:00
|
|
|
|
|
|
|
cd /
|
|
|
|
$BOOTMODE || recovery_cleanup
|
|
|
|
rm -rf $TMPDIR
|
|
|
|
|
|
|
|
ui_print "- Done"
|
|
|
|
}
|
|
|
|
|
2019-12-27 09:53:27 +00:00
|
|
|
##########
|
|
|
|
# Presets
|
|
|
|
##########
|
|
|
|
|
|
|
|
# Detect whether in boot mode
|
|
|
|
[ -z $BOOTMODE ] && ps | grep zygote | grep -qv grep && BOOTMODE=true
|
|
|
|
[ -z $BOOTMODE ] && ps -A 2>/dev/null | grep zygote | grep -qv grep && BOOTMODE=true
|
|
|
|
[ -z $BOOTMODE ] && BOOTMODE=false
|
|
|
|
|
2020-03-22 07:08:04 +00:00
|
|
|
TMPDIR=/dev/tmp
|
2024-07-16 18:16:15 +00:00
|
|
|
MAGISKBIN="/data/adb/magisk"
|