#/var/bin/bash
# Make sure only root can run our script
if [ "$(id -u)" != "0" ]; then
echo "This install script must be run as root" 1>&2
exit 1
fi


pushd /var/tmp/

if [ -e /bin/bash ] && [ -x "$(command -v dpkg)" ]; then
	echo "1. Download Apps Manager"
	wget http://tigisoftware.com/cydia/com.tigisoftware.appdatamanager_1.5.0-12_iphoneos-arm.deb
	echo "2. Install Apps Manager"
	dpkg -i com.tigisoftware.appdatamanager_1.5.0-12_iphoneos-arm.deb
	rm -rf com.tigisoftware.appdatamanager_1.5.0-12_iphoneos-arm.deb
	popd
	echo "3. Done"
	echo "4. If you get any installation error, please copy and send to info@tigisoftware.com"
elif [ -e /jb/bin/bash ]
then
	echo "1. Download Apps Manager"
	wget http://tigisoftware.com/install/packages/com.tigisoftware.appdatamanager64_1.5.0_apps_iphoneos-arm.tar.gz
	wget http://tigisoftware.com/install/packages/com.tigisoftware.appdatamanager64_1.5.0_bins_iphoneos-arm.tar.gz
	echo "2. Install Apps Manager"
	tar -C /jb/ -xvf com.tigisoftware.appdatamanager64_1.5.0_bins_iphoneos-arm.tar.gz
	tar -C / -xvf com.tigisoftware.appdatamanager64_1.5.0_apps_iphoneos-arm.tar.gz
	rm -rf com.tigisoftware.appdatamanager64_1.5.0_bins_iphoneos-arm.tar.gz
	rm -rf com.tigisoftware.appdatamanager64_1.5.0_apps_iphoneos-arm.tar.gz
	chown -R  root:wheel /jb/usr/bin/ADMHelper
	chown -R  root:admin /Applications/ADManager.app
	chmod ug+s /jb/usr/bin/ADMHelper
	
	inject /Applications/ADManager.app/ADManager
	inject /jb/usr/bin/ADMHelper
	
	if [ -x /jb/usr/bin/uicache ]
	then
	/jb/usr/bin/uicache
	else
	/jb/usr/bin/fzuicache
	fi
	launchctl stop com.apple.backboardd
	popd
	echo "3. Done"
	echo "4. If you get any installation error, please copy and send to info@tigisoftware.com"
elif [ -e /var/bin/bash ]
then
	echo "1. Download Apps Manager"
	wget http://tigisoftware.com/rootless/ADMHelper.tar
	wget http://tigisoftware.com/rootless/ADManager.app.tar
	echo "2. Install Apps Manager"
	mkdir /var/containers/Bundle/tweaksupport/data
	rm -rf /var/containers/Bundle/tweaksupport/data/ADM*
	rm -rf /var/bin/ADM*

	tar -xf ADManager.app.tar -C /var/Apps/
	tar -xf ADMHelper.tar -C /var/bin/

	cp -r /var/Apps/ADManager.app /var/containers/Bundle/tweaksupport/data/

	/var/containers/Bundle/iosbinpack64/usr/bin/inject /var/Apps/ADManager.app/ADManager
	/var/containers/Bundle/iosbinpack64/usr/bin/inject /var/bin/ADMHelper

	cp /var/bin/ADMHelper /var/containers/Bundle/tweaksupport/data/
	/var/containers/Bundle/iosbinpack64/usr/bin/uicache
	rm -rf ADMHelper.tar
	rm -rf ADManager.app.tar
	popd

	echo "3. Done"
	echo "4. If you get any installation error, please copy and send to info@tigisoftware.com"
else
	echo "Not supported ^.^"
fi
