#!/sbin/sh

umask 022
OUTFD=${2}
ZIP=${3}

mkdir /dev/tmp
unzip -oq "${ZIP}" CommonPatcher -d "/dev/tmp"
if [ ! -f /dev/tmp/CommonPatcher ]; then
	echo " !! failed to load CommonPatcher"
	exit 1
else
	source "/dev/tmp/CommonPatcher"
fi

detect_bootmode

setup_environment
BASEDIR="${TMPDIR}/dexpatcher"

detect_outfd

show_banner

mount_partitions

setup_patcher

detect_sdk
detect_arch
detect_mode

if check_fake_package_signature; then
	error    " ROM has native signature spoofing already!"
fi

detect_odex

patch_services
install_services
install_addond

${BOOTMODE} || umount_partitions

ui_print " "
ui_print " > Done!"
ui_print " "
ui_print "Thanks for using NanoDroid"
ui_print " "

exit 0
