#!/bin/bash
proc_plist=/Library/MobileSubstrate/DynamicLibraries/$1.plist
proc_dlib=/Library/MobileSubstrate/DynamicLibraries/$1.dylib
procd_dlib=/Library/MobileSubstrate/DynamicLibraries/disabled/$1.dylib
if [ "$EUID" -eq 0 ]; then
	if [ $1 == "help" ]; then
        	echo "Usage: disablet [tweak]
		help: prints this help file
		list: lists all packages currently disabled
		[tweak]: input the name of a tweak's dylib to disable it " 
	elif [ $1 == "list" ]; then
        	directory=/Library/MobileSubstrate/DynamicLibraries/disabled/*
        	for file in $directory; do
			echo $(basename $file)
		done
	elif test -e "$proc_dlib"; then
		echo $1 is enabled. 
		echo Disabling...
		mv $proc_dlib /Library/MobileSubstrate/DynamicLibraries/disabled/
		mv $proc_plist /Library/MobileSubstrate/DynamicLibraries/disabled/
		echo $1 disabled.
	elif  test -e "$procd_dlib" ; then
		echo $1 is already disabled.
	else
		echo $1 is either inputted incorrectly, not installed or does not have a dylib.
		echo "Usage: disablet [tweak]
		help: prints this help file
		list: lists all packages currently disabled 
		[tweak]: input the name of a tweak's dylib to disable it"
	fi
else
	echo disablet needs to be run as root.
fi
if [ $2 == "-r" -o $2 == "--respring" ]; then
killall -9 com.apple,springboard
fi