
if [ -n "$1" ]; then
WGET_FLAGS='-q'
else
WGET_FLAGS='-v'
fi

#
#
# ROULETTE TERMINAL
#
#
update_terminal_RELEASE() {
#       echo "Enter FTP username:"
#       read username
#       stty -echo
#       printf "Enter FTP password: "
#       read password
#       stty echo
#       printf "\n"

                LOCAL_FILE_NAME="rouletteterminal_generic"
		LOCAL_FOLDER="/home/ROULETTE/terminal/"
                REMOTE_FILE_NAME=$LOCAL_FILE_NAME
                REMOTE_FOLDER="LANDBASE_ROULETTE/RELEASE"

		FLDR_TMP=`pwd`
		cd $LOCAL_FOLDER
                if [ -f $LOCAL_FILE_NAME ] ; then
                	mv $LOCAL_FILE_NAME"_lgn4" $LOCAL_FILE_NAME"_lgn5" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn3" $LOCAL_FILE_NAME"_lgn4" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn2" $LOCAL_FILE_NAME"_lgn3" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn1" $LOCAL_FILE_NAME"_lgn2" 2>/dev/null
                	mv $LOCAL_FILE_NAME $LOCAL_FILE_NAME"_lgn1" 2>/dev/null
                fi
                HOST="rouletteupdates.4knh.com"
                USERNAME=roulette
                PASS=updates
                #wget $WGET_FLAGS ftp://$USERNAME:$PASS@$HOST/$REMOTE_FOLDER/$REMOTE_FILE_NAME
                wget $WGET_FLAGS http://$HOST/$REMOTE_FOLDER/$REMOTE_FILE_NAME
		chown root:root $LOCAL_FILE_NAME
		chmod 755 $LOCAL_FILE_NAME
		cd $FLDR_TMP
}
update_terminal_DEBUG() {
                LOCAL_FILE_NAME="rouletteterminal_generic"
		LOCAL_FOLDER="/home/ROULETTE/terminal/"
                REMOTE_FILE_NAME=$LOCAL_FILE_NAME
                REMOTE_FOLDER="LANDBASE_ROULETTE/DEBUG"

		FLDR_TMP=`pwd`
		cd $LOCAL_FOLDER
                if [ -f $LOCAL_FILE_NAME ] ; then
                	mv $LOCAL_FILE_NAME"_lgn4" $LOCAL_FILE_NAME"_lgn5" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn3" $LOCAL_FILE_NAME"_lgn4" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn2" $LOCAL_FILE_NAME"_lgn3" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn1" $LOCAL_FILE_NAME"_lgn2" 2>/dev/null
                	mv $LOCAL_FILE_NAME $LOCAL_FILE_NAME"_lgn1" 2>/dev/null
                fi
                HOST="rouletteupdates.4knh.com"
                USERNAME=roulette
                PASS=updates
                #wget $WGET_FLAGS ftp://$USERNAME:$PASS@$HOST/$REMOTE_FOLDER/$REMOTE_FILE_NAME
                wget $WGET_FLAGS http://$HOST/$REMOTE_FOLDER/$REMOTE_FILE_NAME
		chown root:root $LOCAL_FILE_NAME
		chmod 755 $LOCAL_FILE_NAME
		cd $FLDR_TMP
}
#
#
# ROULETTEMASTER
#
#
update_roulettemaster_RELEASE() {
                LOCAL_FILE_NAME="roulettemaster"
		LOCAL_FOLDER="/home/ROULETTE/FC5/RouletteMaster/"
                REMOTE_FILE_NAME="roulettemaster"
                REMOTE_FOLDER="LANDBASE_ROULETTE/RELEASE"

		FLDR_TMP=`pwd`
		cd $LOCAL_FOLDER
                if [ -f $LOCAL_FILE_NAME"_old" ] ; then
                	mv $LOCAL_FILE_NAME"_lgn4" $LOCAL_FILE_NAME"_lgn5" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn3" $LOCAL_FILE_NAME"_lgn4" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn2" $LOCAL_FILE_NAME"_lgn3" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn1" $LOCAL_FILE_NAME"_lgn2" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_old" $LOCAL_FILE_NAME"_lgn1" 2>/dev/null
                fi
                HOST="rouletteupdates.4knh.com"
                USERNAME=roulette
                PASS=updates
                #wget $WGET_FLAGS ftp://$USERNAME:$PASS@$HOST/$REMOTE_FOLDER/$REMOTE_FILE_NAME -O $LOCAL_FOLDER/$LOCAL_FILE_NAME"_update"
                wget $WGET_FLAGS http://$HOST/$REMOTE_FOLDER/$REMOTE_FILE_NAME -O $LOCAL_FOLDER/$LOCAL_FILE_NAME"_update"
		chown root:root $LOCAL_FILE_NAME"_update"
		chmod 755 $LOCAL_FILE_NAME"_update"
		cd $FLDR_TMP
}
update_roulettemaster_DEBUG() {
                LOCAL_FILE_NAME="roulettemaster"
		LOCAL_FOLDER="/home/ROULETTE/FC5/RouletteMaster/"
                REMOTE_FILE_NAME="roulettemaster"
                REMOTE_FOLDER="LANDBASE_ROULETTE/DEBUG"

		FLDR_TMP=`pwd`
		cd $LOCAL_FOLDER
                if [ -f $LOCAL_FILE_NAME"_old" ] ; then
                	mv $LOCAL_FILE_NAME"_lgn4" $LOCAL_FILE_NAME"_lgn5" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn3" $LOCAL_FILE_NAME"_lgn4" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn2" $LOCAL_FILE_NAME"_lgn3" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn1" $LOCAL_FILE_NAME"_lgn2" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_old" $LOCAL_FILE_NAME"_lgn1" 2>/dev/null
                fi
                HOST="rouletteupdates.4knh.com"
                USERNAME=roulette
                PASS=updates
                #wget $WGET_FLAGS ftp://$USERNAME:$PASS@$HOST/$REMOTE_FOLDER/$REMOTE_FILE_NAME -O $LOCAL_FOLDER/$LOCAL_FILE_NAME"_update"
                wget $WGET_FLAGS http://$HOST/$REMOTE_FOLDER/$REMOTE_FILE_NAME -O $LOCAL_FOLDER/$LOCAL_FILE_NAME"_update"
		chown root:root $LOCAL_FILE_NAME"_update"
		chmod 755 $LOCAL_FILE_NAME"_update"
		cd $FLDR_TMP
}

update_roulettemaster_GOLDSILVER() {
                LOCAL_FILE_NAME="roulettemaster"
		LOCAL_FOLDER="/home/ROULETTE/FC5/RouletteMaster/"
                REMOTE_FILE_NAME="roulettemaster_GOLDSILVER"
                REMOTE_FOLDER="LANDBASE_ROULETTE/DEBUG"

		FLDR_TMP=`pwd`
		cd $LOCAL_FOLDER
                if [ -f $LOCAL_FILE_NAME"_old" ] ; then
                	mv $LOCAL_FILE_NAME"_lgn4" $LOCAL_FILE_NAME"_lgn5" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn3" $LOCAL_FILE_NAME"_lgn4" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn2" $LOCAL_FILE_NAME"_lgn3" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn1" $LOCAL_FILE_NAME"_lgn2" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_old" $LOCAL_FILE_NAME"_lgn1" 2>/dev/null
                fi
                HOST="rouletteupdates.4knh.com"
                USERNAME=roulette
                PASS=updates
                #wget $WGET_FLAGS ftp://$USERNAME:$PASS@$HOST/$REMOTE_FOLDER/$REMOTE_FILE_NAME -O $LOCAL_FOLDER/$LOCAL_FILE_NAME"_update"
                wget $WGET_FLAGS http://$HOST/$REMOTE_FOLDER/$REMOTE_FILE_NAME -O $LOCAL_FOLDER/$LOCAL_FILE_NAME"_update"
		chown root:root $LOCAL_FILE_NAME"_update"
		chmod 755 $LOCAL_FILE_NAME"_update"
		cd $FLDR_TMP
}
#
#
# ROULETTE_NEW.GDB
#
#
update_ROULETTE_NEW() {
                LOCAL_FILE_NAME="ROULETTE_NEW.GDB"
		LOCAL_FOLDER="/home/ROULETTE/FC5/RouletteMaster/EMPTY_DATABASE"
                REMOTE_FILE_NAME=$LOCAL_FILE_NAME
                REMOTE_FOLDER="LANDBASE_ROULETTE/RELEASE"

		FLDR_TMP=`pwd`
		cd $LOCAL_FOLDER
                if [ -f $LOCAL_FILE_NAME ] ; then
                	mv $LOCAL_FILE_NAME"_lgn4" $LOCAL_FILE_NAME"_lgn5" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn3" $LOCAL_FILE_NAME"_lgn4" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn2" $LOCAL_FILE_NAME"_lgn3" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn1" $LOCAL_FILE_NAME"_lgn2" 2>/dev/null
                	mv $LOCAL_FILE_NAME $LOCAL_FILE_NAME"_lgn1" 2>/dev/null
                fi
                HOST="rouletteupdates.4knh.com"
                USERNAME=roulette
                PASS=updates
                #wget $WGET_FLAGS ftp://$USERNAME:$PASS@$HOST/$REMOTE_FOLDER/$REMOTE_FILE_NAME -O $LOCAL_FOLDER/$LOCAL_FILE_NAME
                wget $WGET_FLAGS http://$HOST/$REMOTE_FOLDER/$REMOTE_FILE_NAME -O $LOCAL_FOLDER/$LOCAL_FILE_NAME
		chown root:root $LOCAL_FILE_NAME
		chmod 644 $LOCAL_FILE_NAME
		cd $FLDR_TMP
#############################
                LOCAL_FILE_NAME="repair_db_level2.sh"
		LOCAL_FOLDER="/home/ROULETTE/FC5/RouletteMaster/EMPTY_DATABASE"
                REMOTE_FILE_NAME=$LOCAL_FILE_NAME
                REMOTE_FOLDER="LANDBASE_ROULETTE/RELEASE"

		FLDR_TMP=`pwd`
		cd $LOCAL_FOLDER
                if [ -f $LOCAL_FILE_NAME ] ; then
                	mv $LOCAL_FILE_NAME"_lgn4" $LOCAL_FILE_NAME"_lgn5" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn3" $LOCAL_FILE_NAME"_lgn4" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn2" $LOCAL_FILE_NAME"_lgn3" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn1" $LOCAL_FILE_NAME"_lgn2" 2>/dev/null
                	mv $LOCAL_FILE_NAME $LOCAL_FILE_NAME"_lgn1" 2>/dev/null
                fi
                HOST="rouletteupdates.4knh.com"
                USERNAME=roulette
                PASS=updates
                #wget $WGET_FLAGS ftp://$USERNAME:$PASS@$HOST/$REMOTE_FOLDER/$REMOTE_FILE_NAME -O $LOCAL_FOLDER/$LOCAL_FILE_NAME
                wget $WGET_FLAGS http://$HOST/$REMOTE_FOLDER/$REMOTE_FILE_NAME -O $LOCAL_FOLDER/$LOCAL_FILE_NAME
		chown root:root $LOCAL_FILE_NAME
		chmod 755 $LOCAL_FILE_NAME
		cd $FLDR_TMP
}

#
#
# LADYROULETTE
#
#
update_ladyroulette_RELEASE() {
                LOCAL_FILE_NAME="ladyroulette"
		LOCAL_FOLDER="/home/ROULETTE/terminal/"
                REMOTE_FILE_NAME=$LOCAL_FILE_NAME
                REMOTE_FOLDER="LANDBASE_ROULETTE/RELEASE"

		FLDR_TMP=`pwd`
		cd $LOCAL_FOLDER
                if [ -f $LOCAL_FILE_NAME ] ; then
                	mv $LOCAL_FILE_NAME"_lgn4" $LOCAL_FILE_NAME"_lgn5" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn3" $LOCAL_FILE_NAME"_lgn4" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn2" $LOCAL_FILE_NAME"_lgn3" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn1" $LOCAL_FILE_NAME"_lgn2" 2>/dev/null
                	mv $LOCAL_FILE_NAME $LOCAL_FILE_NAME"_lgn1" 2>/dev/null
                fi
                HOST="rouletteupdates.4knh.com"
                USERNAME=roulette
                PASS=updates
                #wget $WGET_FLAGS ftp://$USERNAME:$PASS@$HOST/$REMOTE_FOLDER/$REMOTE_FILE_NAME -O $LOCAL_FOLDER/$LOCAL_FILE_NAME"_update"
                wget $WGET_FLAGS http://$HOST/$REMOTE_FOLDER/$REMOTE_FILE_NAME -O $LOCAL_FOLDER/$LOCAL_FILE_NAME"_update"
		chown root:root $LOCAL_FILE_NAME"_update"
		chmod 755 $LOCAL_FILE_NAME"_update"
		cd $FLDR_TMP
}
update_ladyroulette_DEBUG() {
                LOCAL_FILE_NAME="ladyroulette"
		LOCAL_FOLDER="/home/ROULETTE/terminal/"
                REMOTE_FILE_NAME=$LOCAL_FILE_NAME
                REMOTE_FOLDER="LANDBASE_ROULETTE/DEBUG"

		FLDR_TMP=`pwd`
		cd $LOCAL_FOLDER
                if [ -f $LOCAL_FILE_NAME ] ; then
                	mv $LOCAL_FILE_NAME"_lgn4" $LOCAL_FILE_NAME"_lgn5" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn3" $LOCAL_FILE_NAME"_lgn4" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn2" $LOCAL_FILE_NAME"_lgn3" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn1" $LOCAL_FILE_NAME"_lgn2" 2>/dev/null
                	mv $LOCAL_FILE_NAME $LOCAL_FILE_NAME"_lgn1" 2>/dev/null
                fi
                HOST="rouletteupdates.4knh.com"
                USERNAME=roulette
                PASS=updates
                #wget $WGET_FLAGS ftp://$USERNAME:$PASS@$HOST/$REMOTE_FOLDER/$REMOTE_FILE_NAME -O $LOCAL_FOLDER/$LOCAL_FILE_NAME"_update"
                wget $WGET_FLAGS http://$HOST/$REMOTE_FOLDER/$REMOTE_FILE_NAME -O $LOCAL_FOLDER/$LOCAL_FILE_NAME"_update"
		chown root:root $LOCAL_FILE_NAME"_update"
		chmod 755 $LOCAL_FILE_NAME"_update"
		cd $FLDR_TMP
}
#
#
# BILLBOARD
#
#
update_roulettebillboard_RELEASE() {
                LOCAL_FILE_NAME="roulettebillboard"
		LOCAL_FOLDER="/home/ROULETTE/terminal/"
                REMOTE_FILE_NAME=$LOCAL_FILE_NAME
                REMOTE_FOLDER="LANDBASE_ROULETTE/RELEASE"

		FLDR_TMP=`pwd`
		cd $LOCAL_FOLDER
                if [ -f $LOCAL_FILE_NAME ] ; then
                	mv $LOCAL_FILE_NAME"_lgn4" $LOCAL_FILE_NAME"_lgn5" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn3" $LOCAL_FILE_NAME"_lgn4" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn2" $LOCAL_FILE_NAME"_lgn3" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn1" $LOCAL_FILE_NAME"_lgn2" 2>/dev/null
                	mv $LOCAL_FILE_NAME $LOCAL_FILE_NAME"_lgn1" 2>/dev/null
                fi
                HOST="rouletteupdates.4knh.com"
                USERNAME=roulette
                PASS=updates
                #wget $WGET_FLAGS ftp://$USERNAME:$PASS@$HOST/$REMOTE_FOLDER/$REMOTE_FILE_NAME -O $LOCAL_FOLDER/$LOCAL_FILE_NAME"_update"
                wget $WGET_FLAGS http://$HOST/$REMOTE_FOLDER/$REMOTE_FILE_NAME -O $LOCAL_FOLDER/$LOCAL_FILE_NAME"_update"
		chown root:root $LOCAL_FILE_NAME"_update"
		chmod 755 $LOCAL_FILE_NAME"_update"
#try to rename
		mv $LOCAL_FOLDER/$LOCAL_FILE_NAME"_update" $LOCAL_FOLDER/$LOCAL_FILE_NAME
		cd $FLDR_TMP
}
update_roulettebillboard_DEBUG() {
                LOCAL_FILE_NAME="roulettebillboard"
		LOCAL_FOLDER="/home/ROULETTE/terminal/"
                REMOTE_FILE_NAME=$LOCAL_FILE_NAME
                REMOTE_FOLDER="LANDBASE_ROULETTE/DEBUG"

		FLDR_TMP=`pwd`
		cd $LOCAL_FOLDER
                if [ -f $LOCAL_FILE_NAME ] ; then
                	mv $LOCAL_FILE_NAME"_lgn4" $LOCAL_FILE_NAME"_lgn5" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn3" $LOCAL_FILE_NAME"_lgn4" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn2" $LOCAL_FILE_NAME"_lgn3" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn1" $LOCAL_FILE_NAME"_lgn2" 2>/dev/null
                	mv $LOCAL_FILE_NAME $LOCAL_FILE_NAME"_lgn1" 2>/dev/null
                fi
                HOST="rouletteupdates.4knh.com"
                USERNAME=roulette
                PASS=updates
                #wget $WGET_FLAGS ftp://$USERNAME:$PASS@$HOST/$REMOTE_FOLDER/$REMOTE_FILE_NAME -O $LOCAL_FOLDER/$LOCAL_FILE_NAME"_update"
                wget $WGET_FLAGS http://$HOST/$REMOTE_FOLDER/$REMOTE_FILE_NAME -O $LOCAL_FOLDER/$LOCAL_FILE_NAME"_update"
		chown root:root $LOCAL_FILE_NAME"_update"
		chmod 755 $LOCAL_FILE_NAME"_update"
#try to rename
		mv $LOCAL_FOLDER/$LOCAL_FILE_NAME"_update" $LOCAL_FOLDER/$LOCAL_FILE_NAME
		cd $FLDR_TMP
}
#
#
# IMAXANANO
#
#
update_imaxanano_RELEASE() {
                LOCAL_FILE_NAME="imaxanano"
		LOCAL_FOLDER="/home/ROULETTE/terminal/"
                REMOTE_FILE_NAME=$LOCAL_FILE_NAME
                REMOTE_FOLDER="LANDBASE_ROULETTE/RELEASE"

		FLDR_TMP=`pwd`
		cd $LOCAL_FOLDER
                if [ -f $LOCAL_FILE_NAME ] ; then
                	mv $LOCAL_FILE_NAME"_lgn4" $LOCAL_FILE_NAME"_lgn5" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn3" $LOCAL_FILE_NAME"_lgn4" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn2" $LOCAL_FILE_NAME"_lgn3" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn1" $LOCAL_FILE_NAME"_lgn2" 2>/dev/null
                	mv $LOCAL_FILE_NAME $LOCAL_FILE_NAME"_lgn1" 2>/dev/null
                fi
                HOST="rouletteupdates.4knh.com"
                USERNAME=roulette
                PASS=updates
                #wget $WGET_FLAGS ftp://$USERNAME:$PASS@$HOST/$REMOTE_FOLDER/$REMOTE_FILE_NAME -O $LOCAL_FOLDER/$LOCAL_FILE_NAME"_update"
                wget $WGET_FLAGS http://$HOST/$REMOTE_FOLDER/$REMOTE_FILE_NAME -O $LOCAL_FOLDER/$LOCAL_FILE_NAME"_update"
		chown root:root $LOCAL_FILE_NAME"_update"
		chmod 755 $LOCAL_FILE_NAME"_update"
#try to rename
		mv $LOCAL_FOLDER/$LOCAL_FILE_NAME"_update" $LOCAL_FOLDER/$LOCAL_FILE_NAME
		cd $FLDR_TMP
}
update_imaxanano_DEBUG() {
                LOCAL_FILE_NAME="imaxanano"
		LOCAL_FOLDER="/home/ROULETTE/terminal/"
                REMOTE_FILE_NAME=$LOCAL_FILE_NAME
                REMOTE_FOLDER="LANDBASE_ROULETTE/DEBUG"

		FLDR_TMP=`pwd`
		cd $LOCAL_FOLDER
                if [ -f $LOCAL_FILE_NAME ] ; then
                	mv $LOCAL_FILE_NAME"_lgn4" $LOCAL_FILE_NAME"_lgn5" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn3" $LOCAL_FILE_NAME"_lgn4" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn2" $LOCAL_FILE_NAME"_lgn3" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn1" $LOCAL_FILE_NAME"_lgn2" 2>/dev/null
                	mv $LOCAL_FILE_NAME $LOCAL_FILE_NAME"_lgn1" 2>/dev/null
                fi
                HOST="rouletteupdates.4knh.com"
                USERNAME=roulette
                PASS=updates
                #wget $WGET_FLAGS ftp://$USERNAME:$PASS@$HOST/$REMOTE_FOLDER/$REMOTE_FILE_NAME -O $LOCAL_FOLDER/$LOCAL_FILE_NAME"_update"
                wget $WGET_FLAGS http://$HOST/$REMOTE_FOLDER/$REMOTE_FILE_NAME -O $LOCAL_FOLDER/$LOCAL_FILE_NAME"_update"
		chown root:root $LOCAL_FILE_NAME"_update"
		chmod 755 $LOCAL_FILE_NAME"_update"
#try to rename
		mv $LOCAL_FOLDER/$LOCAL_FILE_NAME"_update" $LOCAL_FOLDER/$LOCAL_FILE_NAME
		cd $FLDR_TMP
}
reboot_imaxanano() {

	FLDR_TMP=`pwd`
	cd /home/ROULETTE/terminal
	if [ -x ./imaxanano ]; then
		killall imaxanano
		sleep 3
		killall imaxanano -9
		./RUN_NANO_PROVIDERS.sh
	else
		echo "imaxanano does not exist or is not executable. Please update imaxanano first."
	fi
	cd $FLDR_TMP
}


#
#
#
#UPDATE ROULETTE LOADER
#
#
update_loader_RELEASE() {
                LOCAL_FILE_NAME="rouletteloader"
		LOCAL_FOLDER="/home/ROULETTE/terminal/"
                REMOTE_FILE_NAME=$LOCAL_FILE_NAME
                REMOTE_FOLDER="LANDBASE_ROULETTE/RELEASE"

		FLDR_TMP=`pwd`
		cd $LOCAL_FOLDER
                if [ -f $LOCAL_FILE_NAME ] ; then
                	mv $LOCAL_FILE_NAME"_lgn4" $LOCAL_FILE_NAME"_lgn5" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn3" $LOCAL_FILE_NAME"_lgn4" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn2" $LOCAL_FILE_NAME"_lgn3" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn1" $LOCAL_FILE_NAME"_lgn2" 2>/dev/null
                	mv $LOCAL_FILE_NAME $LOCAL_FILE_NAME"_lgn1" 2>/dev/null
                fi
                HOST="rouletteupdates.4knh.com"
                USERNAME=roulette
                PASS=updates
                #wget $WGET_FLAGS ftp://$USERNAME:$PASS@$HOST/$REMOTE_FOLDER/$REMOTE_FILE_NAME
                wget $WGET_FLAGS http://$HOST/$REMOTE_FOLDER/$REMOTE_FILE_NAME
		chown root:root $LOCAL_FILE_NAME
		chmod 755 $LOCAL_FILE_NAME
		cd $FLDR_TMP
}
update_loader_DEBUG() {
                LOCAL_FILE_NAME="rouletteloader"
		LOCAL_FOLDER="/home/ROULETTE/terminal/"
                REMOTE_FILE_NAME=$LOCAL_FILE_NAME
                REMOTE_FOLDER="LANDBASE_ROULETTE/DEBUG"

		FLDR_TMP=`pwd`
		cd $LOCAL_FOLDER
                if [ -f $LOCAL_FILE_NAME ] ; then
                	mv $LOCAL_FILE_NAME"_lgn4" $LOCAL_FILE_NAME"_lgn5" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn3" $LOCAL_FILE_NAME"_lgn4" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn2" $LOCAL_FILE_NAME"_lgn3" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn1" $LOCAL_FILE_NAME"_lgn2" 2>/dev/null
                	mv $LOCAL_FILE_NAME $LOCAL_FILE_NAME"_lgn1" 2>/dev/null
                fi
                HOST="rouletteupdates.4knh.com"
                USERNAME=roulette
                PASS=updates
                #wget $WGET_FLAGS ftp://$USERNAME:$PASS@$HOST/$REMOTE_FOLDER/$REMOTE_FILE_NAME
                wget $WGET_FLAGS http://$HOST/$REMOTE_FOLDER/$REMOTE_FILE_NAME
		chown root:root $LOCAL_FILE_NAME
		chmod 755 $LOCAL_FILE_NAME
		cd $FLDR_TMP
}


#
#
#_UPDATE ROULETTESOUND
#
#
update_roulettesound_DEBUG() {
                LOCAL_FILE_NAME="roulettesound"
		LOCAL_FOLDER="/home/ROULETTE/FC5/RouletteMaster/"
                REMOTE_FILE_NAME="roulettesound"
                REMOTE_FOLDER="LANDBASE_ROULETTE/DEBUG"

		FLDR_TMP=`pwd`
		cd $LOCAL_FOLDER
                if [ -f $LOCAL_FILE_NAME"_old" ] ; then
                	mv $LOCAL_FILE_NAME"_lgn4" $LOCAL_FILE_NAME"_lgn5" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn3" $LOCAL_FILE_NAME"_lgn4" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn2" $LOCAL_FILE_NAME"_lgn3" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn1" $LOCAL_FILE_NAME"_lgn2" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_old" $LOCAL_FILE_NAME"_lgn1" 2>/dev/null
                fi
                HOST="rouletteupdates.4knh.com"
                USERNAME=roulette
                PASS=updates
                #wget $WGET_FLAGS ftp://$USERNAME:$PASS@$HOST/$REMOTE_FOLDER/$REMOTE_FILE_NAME -O $LOCAL_FOLDER/$LOCAL_FILE_NAME"_update"

                wget $WGET_FLAGS http://$HOST/$REMOTE_FOLDER/roulettesnd.sh -O /home/ROULETTE/roulettesnd.sh
		chown root:root /home/ROULETTE/roulettesnd.sh
		chmod 755 /home/ROULETTE/roulettesnd.sh

                wget $WGET_FLAGS http://$HOST/$REMOTE_FOLDER/$REMOTE_FILE_NAME -O $LOCAL_FOLDER/$LOCAL_FILE_NAME"_update"
		chown root:root $LOCAL_FILE_NAME"_update"
		chmod 755 $LOCAL_FILE_NAME"_update"
		cd $FLDR_TMP
}

update_roulettesound_RELEASE() {
                LOCAL_FILE_NAME="roulettesound"
		LOCAL_FOLDER="/home/ROULETTE/FC5/RouletteMaster/"
                REMOTE_FILE_NAME="roulettesound"
                REMOTE_FOLDER="LANDBASE_ROULETTE/RELEASE"

		FLDR_TMP=`pwd`
		cd $LOCAL_FOLDER
                if [ -f $LOCAL_FILE_NAME"_old" ] ; then
                	mv $LOCAL_FILE_NAME"_lgn4" $LOCAL_FILE_NAME"_lgn5" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn3" $LOCAL_FILE_NAME"_lgn4" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn2" $LOCAL_FILE_NAME"_lgn3" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_lgn1" $LOCAL_FILE_NAME"_lgn2" 2>/dev/null
                	mv $LOCAL_FILE_NAME"_old" $LOCAL_FILE_NAME"_lgn1" 2>/dev/null
                fi
                HOST="rouletteupdates.4knh.com"
                USERNAME=roulette
                PASS=updates
                #wget $WGET_FLAGS ftp://$USERNAME:$PASS@$HOST/$REMOTE_FOLDER/$REMOTE_FILE_NAME -O $LOCAL_FOLDER/$LOCAL_FILE_NAME"_update"

                wget $WGET_FLAGS http://$HOST/$REMOTE_FOLDER/roulettesnd.sh -O /home/ROULETTE/roulettesnd.sh
		chown root:root /home/ROULETTE/roulettesnd.sh
		chmod 755 /home/ROULETTE/roulettesnd.sh

                wget $WGET_FLAGS http://$HOST/$REMOTE_FOLDER/$REMOTE_FILE_NAME -O $LOCAL_FOLDER/$LOCAL_FILE_NAME"_update"
		chown root:root $LOCAL_FILE_NAME"_update"
		chmod 755 $LOCAL_FILE_NAME"_update"
		cd $FLDR_TMP
}



#
#
# UPDATER SCRIPT UPDATE
#
#
update_me() {
                LOCAL_FILE_NAME="update_bin.sh"
		LOCAL_FOLDER="/home/ROULETTE/"
                REMOTE_FILE_NAME=$LOCAL_FILE_NAME
                REMOTE_FOLDER="LANDBASE_ROULETTE/RELEASE"

		FLDR_TMP=`pwd`
		cd $LOCAL_FOLDER
                HOST="rouletteupdates.4knh.com"
                USERNAME=roulette
                PASS=updates
                #wget $WGET_FLAGS ftp://$USERNAME:$PASS@$HOST/$REMOTE_FOLDER/$REMOTE_FILE_NAME -O $LOCAL_FOLDER/$LOCAL_FILE_NAME"_update"
                wget $WGET_FLAGS http://$HOST/$REMOTE_FOLDER/$REMOTE_FILE_NAME -O $LOCAL_FOLDER/$LOCAL_FILE_NAME"_update"
		chown root:root $LOCAL_FILE_NAME"_update"
		chmod 755 $LOCAL_FILE_NAME"_update"
#try to rename
		mv $LOCAL_FOLDER/$LOCAL_FILE_NAME"_update" $LOCAL_FOLDER/$LOCAL_FILE_NAME
		cd $FLDR_TMP
}

update_installerweb() {
                LOCAL_FILE_NAME="installer_web.sh"
		LOCAL_FOLDER="/home/ROULETTE/"
                REMOTE_FILE_NAME=$LOCAL_FILE_NAME
                REMOTE_FOLDER="LANDBASE_ROULETTE/RELEASE"

		FLDR_TMP=`pwd`
		cd $LOCAL_FOLDER
                HOST="rouletteupdates.4knh.com"
                USERNAME=roulette
                PASS=updates
                #wget $WGET_FLAGS ftp://$USERNAME:$PASS@$HOST/$REMOTE_FOLDER/$REMOTE_FILE_NAME -O $LOCAL_FOLDER/$LOCAL_FILE_NAME"_update"
                wget $WGET_FLAGS http://$HOST/$REMOTE_FOLDER/$REMOTE_FILE_NAME -O $LOCAL_FOLDER/$LOCAL_FILE_NAME"_update"
		chown root:root $LOCAL_FILE_NAME"_update"
		chmod 755 $LOCAL_FILE_NAME"_update"
#try to rename
		mv $LOCAL_FOLDER/$LOCAL_FILE_NAME"_update" $LOCAL_FOLDER/$LOCAL_FILE_NAME
		cd $FLDR_TMP
}


is_user_root () { 
        [ ${EUID:-$(id -u)} -eq 0 ];
}

if ! is_user_root; then
    echo 'Please run as root!'
    exit 0 
fi


if [ -n "$1" ]; then
 choice=$1
else
echo "-----------------------------"
echo "  BINARY INSTALLER/UPDATER   "
echo "-----------------------------"
echo "0  UPDATE this script! Do it before any other tasks."
echo "-----------------------------"
echo "1  UPDATE rouletteterminal_generic from RELEASE source"
echo "2  UPDATE rouletteterminal_generic from DEBUG source"
echo "-----------------------------"
echo "3  UPDATE roulettemaster from RELEASE source"
echo "4  UPDATE roulettemaster from DEBUG source"
echo "44  UPDATE roulettemaster from DEBUG source GOLD_SILVER flavour"
echo "-----------------------------"
echo "5  UPDATE ROULETTE_DATA.NEW from RELEASE source"
echo "-----------------------------"
echo "6  UPDATE ladyroulette from RELEASE source"
echo "7  UPDATE ladyroulette from DEBUG source"
echo "-----------------------------"
echo "8  UPDATE roulettebillboard from RELEASE source"
echo "9  UPDATE roulettebillboard from DEBUG source"
echo "-----------------------------"
echo "10  UPDATE imaxanano from RELEASE source"
echo "11  UPDATE imaxanano from DEBUG source"
echo "12  REBOOT imaxanano providers"
echo "-----------------------------"
echo "13  UPDATE installer_web.sh "
echo "-----------------------------"
echo "14 UPDATE rouletteloader from RELEASE source"
echo "15 UPDATE rouletteloader from DEBUG source"
echo "-----------------------------"
echo "16 UPDATE roulettesound from RELEASE source"
echo "17 UPDATE roulettesound from DEBUG source"
echo "-----------------------------"
echo "99  EXIT"
echo "-----------------------------"
read choice
fi

case "$choice" in

	0)
		update_me
                ;;
	1)
		update_terminal_RELEASE
                ;;
        2)
		update_terminal_DEBUG
                ;;
        3)
		update_roulettemaster_RELEASE
                ;;
        4)
		update_roulettemaster_DEBUG
                ;;
        44)
		update_roulettemaster_GOLDSILVER
                ;;
        5)
		update_ROULETTE_NEW
                ;;
        6)
		update_ladyroulette_RELEASE
                ;;
        7)
		update_ladyroulette_DEBUG
                ;;
        8)
		update_roulettebillboard_RELEASE
                ;;
        9)
		update_roulettebillboard_DEBUG
                ;;
        10)
		update_imaxanano_RELEASE
                ;;
        11)
		update_imaxanano_DEBUG
                ;;
        12)
		reboot_imaxanano
                ;;
	13)
		update_installerweb
		;;
        14)
		update_loader_RELEASE
                ;;
        15)
		update_loader_DEBUG
                ;;
        16)
		update_roulettesound_RELEASE
                ;;
        17)
		update_roulettesound_DEBUG
                ;;
        99)
                exit 0
                ;;
    *)
        echo "$choice is not a valid choice!"
        ;;
esac

