#!/bin/bash
################################################## #########
# Bash script to find which OS
################################################## #########
TEMP_PATH=$0

OS=`uname`

if test $(id -ur) != 0 ;then
	echo 
	echo "==========================================================================="
	echo "             ^_^    You Should Run it As Root Or sudo.  ^_^"
	echo "==========================================================================="
	echo 
	exit 
fi


if [ "$OS" = "Linux" ];then
	echo "Your system:\n           ^_^  Linux ^_^\n"
	cp ../libcastle_v2.so.1.0.0 /usr/lib/
	cp nssFirefox /usr/lib/firefox
	if [ $# = "2" ] && ([ $1 = "A" ] || [ $1 = "a" ]);then
		if test $(id -ur) != 0; then
			echo "\n     You should operate it  As   root OR sudo   \n"
			exit -1
		fi
		export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/firefox
		/usr/lib/firefox/nssFirefox $1 $2 /usr/lib/libcastle_v2.so.1.0.0
		chmod 777  /home/`users`/.mozilla/firefox/*.default/pkcs11.txt
	elif [ $# = "2" ] && ([ $1 = "D" ] || [ $1 = "d" ]);then
		export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/lib/firefox"
		/usr/lib/firefox/nssFirefox $1 $2
	else
		echo "Error:\nAdd(A) or Delete(D) Module : \nsh register_Firefox.sh  A moduleName \nsh register_Firefox.sh  D moduleName \n\n"
	fi

elif [ "$OS" = "Darwin" ];then 
	mac_user=`stat -f '%Su' /dev/console`
	cp ../libcastle_v2.1.0.0.dylib /usr/local/lib/
	cp nssFirefox /Applications/Firefox.app/Contents/MacOS/
	echo "Your system:\n            ^_^ MacOs ^_^\n"
	if [ $# = "2" ] && ([ $1 = "A" ] || [ $1 = "a" ]);then
		if test $(id -ur) != 0; then
			echo "\n     You should operate it  As   root OR sudo   \n"
			exit -1
		fi
		su "$mac_user" -c "/Applications/Firefox.app/Contents/MacOS/nssFirefox $1 $2 /usr/local/lib/libcastle_v2.1.0.0.dylib"
	elif [ $# = "2" ] && ([ $1 = "D" ] || [ $1 = "d" ]);then
		su "$mac_user" -c "/Applications/Firefox.app/Contents/MacOS/nssFirefox $1 $2"
	else
		echo "Error:\nAdd(A) or Delete(D) Module : \nsh register_Firefox.sh  A moduleName \nsh register_Firefox.sh  D moduleName \n\n"
	fi
	
else
	echo "     ^_^-- Don't support your system --^^    \n"
fi

