Magisk/scripts/flash_script.sh

102 lines
2.1 KiB
Bash
Raw Normal View History

#MAGISK
############################################
# Magisk Flash Script (updater-script)
############################################
2016-09-14 02:31:13 +00:00
##############
2017-07-09 16:17:34 +00:00
# Preparation
##############
2017-07-09 16:17:34 +00:00
2016-11-13 08:58:43 +00:00
# Default permissions
umask 022
2016-09-14 02:31:13 +00:00
OUTFD=$2
COMMONDIR=$INSTALLER/assets
CHROMEDIR=$INSTALLER/assets/chromeos
2016-09-14 02:31:13 +00:00
2017-09-15 19:48:58 +00:00
if [ ! -f $COMMONDIR/util_functions.sh ]; then
2017-06-24 14:38:20 +00:00
echo "! Unable to extract zip file!"
exit 1
fi
# Load utility functions
2017-06-18 16:15:44 +00:00
. $COMMONDIR/util_functions.sh
2018-08-29 02:03:12 +00:00
setup_flashable
2017-07-09 16:17:34 +00:00
############
2017-07-09 16:17:34 +00:00
# Detection
############
2017-07-09 16:17:34 +00:00
2020-03-23 08:17:13 +00:00
if echo $MAGISK_VER | grep -q '\.'; then
PRETTY_VER=$MAGISK_VER
else
PRETTY_VER="$MAGISK_VER($MAGISK_VER_CODE)"
fi
print_title "Magisk $PRETTY_VER Installer"
2016-09-14 02:31:13 +00:00
2019-04-06 17:04:17 +00:00
is_mounted /data || mount /data || is_mounted /cache || mount /cache
2017-09-12 20:07:25 +00:00
mount_partitions
check_data
get_flags
2019-04-04 21:13:57 +00:00
find_boot_image
2018-07-04 15:46:16 +00:00
[ -z $BOOTIMAGE ] && abort "! Unable to detect target image"
ui_print "- Target image: $BOOTIMAGE"
2017-07-02 13:36:09 +00:00
# Detect version and architecture
api_level_arch_detect
2016-10-02 20:34:50 +00:00
2023-03-17 12:08:31 +00:00
[ $API -lt 23 ] && abort "! Magisk only support Android 6.0 and above"
2016-10-29 22:13:59 +00:00
2021-05-13 07:21:04 +00:00
ui_print "- Device platform: $ABI"
2016-10-29 22:13:59 +00:00
2021-05-13 07:21:04 +00:00
BINDIR=$INSTALLER/lib/$ABI
cd $BINDIR
for file in lib*.so; do mv "$file" "${file:3:${#file}-6}"; done
cd /
2024-04-01 05:01:22 +00:00
cp -af $INSTALLER/lib/$ABI32/libmagisk.so $BINDIR/magisk32 2>/dev/null
2016-10-29 22:13:59 +00:00
# Check if system root is installed and remove
$BOOTMODE || remove_system_su
##############
2016-11-13 08:58:43 +00:00
# Environment
##############
2016-11-13 08:58:43 +00:00
2017-04-21 23:05:10 +00:00
ui_print "- Constructing environment"
2017-07-24 18:02:19 +00:00
2017-04-21 23:05:10 +00:00
# Copy required files
rm -rf $MAGISKBIN/* 2>/dev/null
mkdir -p $MAGISKBIN 2>/dev/null
cp -af $BINDIR/. $COMMONDIR/. $BBBIN $MAGISKBIN
2022-12-26 23:59:56 +00:00
# Remove files only used by the Magisk app
rm -f $MAGISKBIN/bootctl $MAGISKBIN/main.jar \
$MAGISKBIN/module_installer.sh $MAGISKBIN/uninstaller.sh
2017-04-21 23:05:10 +00:00
chmod -R 755 $MAGISKBIN
2017-02-04 10:44:07 +00:00
2017-06-18 16:15:44 +00:00
# addon.d
if [ -d /system/addon.d ]; then
ui_print "- Adding addon.d survival script"
blockdev --setrw /dev/block/mapper/system$SLOT 2>/dev/null
mount -o rw,remount /system || mount -o rw,remount /
2018-08-03 14:40:49 +00:00
ADDOND=/system/addon.d/99-magisk.sh
2020-02-09 11:07:49 +00:00
cp -af $COMMONDIR/addon.d.sh $ADDOND
2018-08-03 14:40:49 +00:00
chmod 755 $ADDOND
2017-06-18 16:15:44 +00:00
fi
##################
# Image Patching
##################
2017-03-12 10:13:58 +00:00
install_magisk
2016-09-14 02:31:13 +00:00
2017-09-05 13:44:22 +00:00
# Cleanups
$BOOTMODE || recovery_cleanup
rm -rf $TMPDIR
2017-07-30 19:03:52 +00:00
2016-09-14 02:31:13 +00:00
ui_print "- Done"
exit 0