#!/bin/bash # Title: FAD Client intall script # Created: 11-10-04 # Created By: isacklow @ cdlug . net | http://cdlug.net # Modified: 11-21-04 # Modified By: isacklow # Version: 0.2.0 # Credits: Original script: crouse @ usalug . org | http://www.usalug.org # Notes: # You can restart or check the status of your FAD client from a console as root by: # su / sudo to root # then # cd /usr/local/think # then # ./loader (To restart your client) # or # ./server -list (To check the status) # # If you have any questions please visit http://usalug.org/phpBB2/viewforum.php?f=92 # # The above may get integrated in to a secondary script or as part of a # case function in this script. ############ ### TODO ### ############ # Some of the todo list has been moved to an external file to allow me #+ to ramble off misc ideas that may not be functional for this #+ application #0 integrate additional documentation into script from original #+ echo -e "\n\nIn a few seconds we will attempt to list your running client"; #+ echo "You should have a job running or a job in que. If not wait a few minutes and type ./server -list"; #+ #+ echo "Trying to list current jobs in process...one moment please...this will take 2 minutes...please wait..."; #+ echo "or you can hit CTL-Q to end"; #+ sleep 120 #+ ./server -list; #+ sleep 3 #+ echo "That's all Folks !!! :) "; ################# ### VARIABLES ### ################# ### For test status ### MAXCOLUMN="$(tput cols)"; esc=`echo -en "\033"` norm=`echo -en "${esc}[m\017"` stat=`echo -en "\015${esc}[${MAXCOLUMN}C${esc}[10D"` done="${esc}[1;32m" failed="${esc}[1;31m" rc_done="${stat}[ ${done}Done${norm} ]" rc_failed="${stat}[ ${failed}Failed${norm} ]" ### For test status ### PROGRAM_TITLE="-=:| Find-A-Drug (FAD) Client install script |:=-"; INSTALLDIR="/usr/local/think"; TMPDIR="/tmp"; DOMAIN="www.find-a-drug.org"; FADFILE="fadv125c.tgz"; ################# ### FUNCTIONS ### ################# run_as_root() { ROOT_UID="0"; E_NOTROOT="67"; if [ "$UID" -ne "$ROOT_UID" ]; then echo -e "\n\tYou must be root to run this script!\n"; exit $E_NOTROOT fi } # ---------------------------------------------------------------------- exitcode() { if [ $? != "0" ]; then echo "$rc_failed"; exit 1 else echo "$rc_done"; fi } # ---------------------------------------------------------------------- get_input() { local output if [ "`echo $BASH_VERSION | cut -b1`" = "1" ]; then echo -n "${1} " >&2 ; read output else read -ep "${1} " output fi echo $output } # ---------------------------------------------------------------------- input() { ### NOTES ### # 1. This function will not continue without some type of entry # 2. We will need to add some type checking to make sure a properly #+ formatted email is entered. # 3. Would like way to clean this function up but it works for now. # 4. This function requires the get_input function to properly format #+ the output due to issues with certain version of bash needinput=yes while [ ! -z $needinput ] ; do if [ -z "$VAR1" ] ; then while [ -z "$VAR1" ] ; do VAR1="$(get_input "$MSG1")"; done elif [ -z "$VAR2" ] ; then while [ -z "$VAR2" ] ; do VAR2="$(get_input "$MSG2")"; done else unset needinput fi done } ############## ### SCRIPT ### ############## # Uncomment the following line for debugging #set -xe # Make sure this script is run as root user run_as_root # Start with a clear screen clear echo -e "$PROGRAM_TITLE\n"; # Check for required programs then download installation file echo -en "Checking for wget utility"; which wget &>/dev/null if [ $? != "0" ]; then echo -e "\n\tMissing wget! :("; echo -e "\tPlease install before running this script again."; exit 1 else echo "$rc_done"; echo -en "Checking for ping utility"; which ping &>/dev/null if [ $? != "0" ]; then echo -e "\n\tMissing ping! :("; echo -e "\tPlease install before running this script again."; exit 1 else echo "$rc_done"; echo -en "Checking for download site"; ping -c 3 -n $DOMAIN &>/dev/null if [ $? != "0" ]; then echo -e "\n\tEither the site is down or you are not online."; echo -e "\tPlease try again in a few minutes or when you get online."; exit 1 else echo "$rc_done"; cd $TMPDIR echo -e "Downloading $FADFILE\n"; wget http://"$DOMAIN"/"$FADFILE" exitcode fi fi fi # Check for temp directory if [ ! -d "$TMPDIR" ]; then echo -en "Creating temp directory $TMPDIR"; mkdir $TMPDIR exitcode fi # Check for install directory if [ ! -d "$INSTALLDIR" ]; then echo -en "Creating install directory $INSTALLDIR"; mkdir $INSTALLDIR exitcode fi echo -en "Moving install file to install directory"; mv /$TMPDIR/$FADFILE $INSTALLDIR exitcode echo -en "Checking for tar utility"; which tar &>/dev/null if [ $? != "0" ]; then echo -e "\n\tMissing tar! :("; echo -e "\tPlease install before running this script again."; exit 1 else echo "$rc_done"; echo -en "Unpacking install file"; cd $INSTALLDIR tar -zvxf $FADFILE 1>/dev/null exitcode fi # This section quietly accepts the agreement then installs and starts the client echo "Register and start client"; MSG1=" Please enter a username:"; MSG2=" Please enter your email:"; input USERNAME="$VAR1"; EMAIL="$VAR2"; echo "y" | ./fadsetup -nickname "$USERNAME" -team 2104 -email "$EMAIL" -country "United States" 1>/dev/null echo -en "Removing install file"; rm $FADFILE exitcode # Finish install echo -e "\nCongratulations! Installation is now complete. :)"; echo -e "\nSee the 'Notes' section at the top of this this script"; echo "for more information about the F-A-D Client\n"; ########### ### EOF ### ########### exit 0