#!/sbin/sh
umask 022
OUTFD=$2
ZIPFILE=$3
ui_print() { echo "$1"; }
mount /data 2>/dev/null
[ -f /data/adb/magisk/util_functions.sh ] || { ui_print "Requires KernelSU-Next"; exit 1; }
. /data/adb/magisk/util_functions.sh
[ $MAGISK_VER_CODE -lt 20400 ] && { ui_print "Requires KernelSU-Next"; exit 1; }
setup_flashable
mount_partitions
api_level_arch_detect
MODID=buildchain
MODPATH=$MOUNTPATH/$MODID
ui_print "- Extracting BuildChain"
unzip -o "$ZIPFILE" -x 'META-INF/*' -d $MODPATH >&2
set_perm_recursive $MODPATH 0 0 0755 0644
set_perm_recursive $MODPATH/tools 0 2000 0755 0755
set_perm_recursive $MODPATH/scripts 0 2000 0755 0755
set_perm $MODPATH/service.sh 0 0 0755
set_perm $MODPATH/post-fs-data.sh 0 0 0755
set_perm $MODPATH/uninstall.sh 0 0 0755
ui_print "- BuildChain installed"
ui_print "- Reboot, then run: buildchain setup"
ui_print "- WebUI at http://localhost:8089"
