Skip to content

Commit

Permalink
make on-pc framework-patcher auto-detect install path
Browse files Browse the repository at this point in the history
  • Loading branch information
Nanolx committed Apr 21, 2017
1 parent fa24843 commit 57ac64f
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 32 deletions.
40 changes: 8 additions & 32 deletions framework-patcher.sh
Expand Up @@ -79,41 +79,17 @@ adb shell "mount -oro /system" || error "Failed to mount /system"
"${PWD}/mydevice__${PATCH_HOOK}" \
|| error "Failed applying sigspoof core patch!"

echo -e "\nWhere to install patched services.jar?
1) NanoMod (full package)
2) NanoMod (microG only)
3) ROM (directly to /system)
enter either 1, 2 or 3"
read -r MOD

case ${MOD} in
1 ) MODPATH="/magisk/NanoMod" ;;
2 ) MODPATH="/magisk/NanoModmicroG" ;;
3 ) MODPATH="" ;;
* ) error "wrong module given" ;;
esac
adb push "${PWD}/mydevice__${PATCH_HOOK}__${PATCH_CORE}/services.jar" \
/tmp/services.jar || error "Failed to push services.jar to device"

if [[ ${MODPATH} == /magisk* ]]; then
adb push "${CWD}/mount-magisk.sh" /tmp/ || \
error "Failed to push helper script to device"
adb shell "chmod 0755 /tmp/mount-magisk.sh" || \
error "Failed to set permissions for helper script"
adb shell "/tmp/mount-magisk.sh mount-magisk" || \
error "Failed to mount Magisk image"
fi
adb push "${CWD}/remote.sh" /tmp/ || \
error "Failed to push helper script to device"

adb shell "mkdir -p ${MODPATH}/system/framework" || \
error "Failed to create framework directory"
adb push "${PWD}/mydevice__${PATCH_HOOK}__${PATCH_CORE}/services.jar" \
"${MODPATH}/system/framework" || \
error "Failed to push services.jar to device"
adb shell "chmod 0755 /tmp/remote.sh" || \
error "Failed to set permissions for helper script"

if [[ ${MODPATH} == /magisk* ]]; then
adb shell "/tmp/mount-magisk.sh umount-magisk" || \
error "Failed to unmount Magisk"
fi
adb shell "/tmp/remote.sh" || \
error "Failed to install services.jar"

echo -e "\nNow reboot device and enjoy microG!"

Expand Down
87 changes: 87 additions & 0 deletions remote.sh
@@ -0,0 +1,87 @@
#!/sbin/sh

is_mounted() {
if [ ! -z "$2" ]; then
cat /proc/mounts | grep $1 | grep $2, >/dev/null
else
cat /proc/mounts | grep $1 >/dev/null
fi
return $?
}

mount_image() {
if [ ! -d "$2" ]; then
mount -o rw,remount rootfs /
mkdir -p $2 2>/dev/null
[ ! -d "$2" ] && return 1
fi
if (! is_mounted $2); then
LOOPDEVICE=
for LOOP in 0 1 2 3 4 5 6 7; do
if (! is_mounted $2); then
LOOPDEVICE=/dev/block/loop$LOOP
if [ ! -e "$LOOPDEVICE" ]; then
mknod $LOOPDEVICE b 7 $LOOP
fi
losetup $LOOPDEVICE $1
if [ "$?" -eq "0" ]; then
mount -t ext4 -o loop $LOOPDEVICE $2
if (! is_mounted $2); then
/system/bin/toolbox mount -t ext4 -o loop $LOOPDEVICE $2
fi
if (! is_mounted $2); then
/system/bin/toybox mount -t ext4 -o loop $LOOPDEVICE $2
fi
fi
if (is_mounted $2); then
echo "$LOOPDEVICE" > /tmp/loopdevice
break;
fi
fi
done
fi
}

mount_magisk () {
mount /data &>/dev/null

}

umount_magisk () {
umount /magisk
losetup -d $(cat /tmp/loopdevice)
rm /tmp/loopdevice
}

mount /data &>/dev/null

if [[ -f /data/magisk.img ]]; then
echo "Magisk found, mount to /magisk"
mount_image /data/magisk.img /magisk
fi

install_path=""

if [[ -d /magisk/NanoMod ]]; then
echo "NanoMod found, using as destionation"
install_path="/magisk/NanoMod/system/framework"
mkdir -p "${install_path}"
elif [[ -d /magisk/NanoModmicroG ]]; then
echo "NanoMod microG found, using as destination"
install_path="/magisk/NanoModmicroG/system/framework"
mkdir -p "${install_path}"
else
echo "NanoMod not found, using ROM as destination"
install_path="/system/"
mount -orw,remount /system
fi

cp /tmp/services.jar "${install_path}/services.jar"

if (is_mounted /magisk); then
echo "Unmounting /magisk"
umount_magisk
fi

echo "Unmounting /system"
umount /system

0 comments on commit 57ac64f

Please sign in to comment.