Removed setting the UDC for now as the service runs before the other init scripts selinux is a complete pain, but I need to figure out a way to make it so that you can use hidg devices without root; preferably with a way for an android app to request access.
128 lines
3.6 KiB
Bash
128 lines
3.6 KiB
Bash
#!/bin/sh
|
|
chmod 755 "$MODPATH/system/bin/ghid.sh"
|
|
sed "s@\[MODDIR\]@$MODPATH@g" "$MODPATH/system/bin/ghid.sh" | sed 's/modules_update/modules/g' >"$TMPDIR/ghid.sh"
|
|
cp "$TMPDIR/ghid.sh" "$MODPATH/system/bin/ghid.sh"
|
|
|
|
rpwd="$PWD"
|
|
|
|
|
|
|
|
##########################################################################################
|
|
# Initialization
|
|
##########################################################################################
|
|
cd "$MAGISKBIN"
|
|
get_flags
|
|
find_boot_image
|
|
|
|
[ -e "$BOOTIMAGE" ] || abort "$BOOTIMAGE does not exist!"
|
|
|
|
# Flags
|
|
[ -z "$KEEPVERITY" ] && KEEPVERITY=false
|
|
[ -z "$KEEPFORCEENCRYPT" ] && KEEPFORCEENCRYPT=false
|
|
[ -z "$RECOVERYMODE" ] && RECOVERYMODE=false
|
|
export KEEPVERITY
|
|
export KEEPFORCEENCRYPT
|
|
|
|
chmod -R 755 .
|
|
|
|
eval "$BOOTSIGNER" -verify < "$BOOTIMAGE" && BOOTSIGNED=true
|
|
"$BOOTSIGNED" && ui_print "- Boot image is signed with AVB 1.0"
|
|
|
|
##########################################################################################
|
|
# Start bootpatch
|
|
##########################################################################################
|
|
|
|
##########################################################################################
|
|
# Unpack
|
|
##########################################################################################
|
|
|
|
CHROMEOS=false
|
|
|
|
ui_print "- Unpacking boot image"
|
|
./magiskboot unpack "$BOOTIMAGE"
|
|
|
|
case $? in
|
|
1 )
|
|
abort "! Unsupported/Unknown image format"
|
|
;;
|
|
2 )
|
|
ui_print "- ChromeOS boot image detected"
|
|
CHROMEOS=true
|
|
;;
|
|
esac
|
|
|
|
[ -f recovery_dtbo ] && RECOVERYMODE=true
|
|
|
|
##########################################################################################
|
|
# Ramdisk restores
|
|
##########################################################################################
|
|
|
|
# Test patch status and do restore
|
|
ui_print "- Checking ramdisk status"
|
|
if [ -e ramdisk.cpio ]; then
|
|
./magiskboot cpio ramdisk.cpio test
|
|
STATUS=$?
|
|
else
|
|
# Stock A only system-as-root
|
|
STATUS=0
|
|
fi
|
|
case $((STATUS & 3)) in
|
|
0 ) # Stock boot
|
|
ui_print "- Stock boot image detected"
|
|
abort "Magisk not installed????"
|
|
;;
|
|
1 ) # Magisk patched
|
|
ui_print "- Magisk patched boot image detected"
|
|
;;
|
|
2 ) # Unsupported
|
|
ui_print "! Boot image patched by unsupported programs"
|
|
abort "! Please restore back to stock boot image"
|
|
;;
|
|
esac
|
|
|
|
##########################################################################################
|
|
# Ramdisk patches
|
|
##########################################################################################
|
|
|
|
ui_print "- Patching ramdisk"
|
|
ui_print "- Adding overlay.d/ghid.rc"
|
|
|
|
./magiskboot cpio ramdisk.cpio \
|
|
"mkdir 755 overlay.d" \
|
|
"add 755 overlay.d/ghid.rc $MODPATH/overlay.d/ghid.rc"
|
|
|
|
if [ $((STATUS & 4)) -ne 0 ]; then
|
|
ui_print "- Compressing ramdisk"
|
|
./magiskboot cpio ramdisk.cpio compress
|
|
fi
|
|
|
|
rm -f ramdisk.cpio.orig config
|
|
|
|
ui_print "- Repacking boot image"
|
|
./magiskboot repack "$BOOTIMAGE" || abort "! Unable to repack boot image!"
|
|
|
|
# Sign chromeos boot
|
|
$CHROMEOS && sign_chromeos
|
|
|
|
##########################################################################################
|
|
# End bootpatch
|
|
##########################################################################################
|
|
|
|
|
|
ui_print "- Flashing new boot image"
|
|
|
|
if ! flash_image new-boot.img "$BOOTIMAGE"; then
|
|
ui_print "- Compressing ramdisk to fit in partition"
|
|
./magiskboot cpio ramdisk.cpio compress
|
|
./magiskboot repack "$BOOTIMAGE"
|
|
flash_image new-boot.img "$BOOTIMAGE" || abort "! Insufficient partition size"
|
|
fi
|
|
|
|
./magiskboot cleanup
|
|
rm -f new-boot.img
|
|
|
|
patch_dtb_partitions
|
|
run_migrations
|
|
|
|
cd "$rpwd"
|