Bash Script Help

Discussion in 'Programming/Scripts' started by dclardy, Sep 6, 2011.

  1. dclardy

    dclardy New Member

    I am updating my script that automatically installs ISPConfig 3 on Debian 6. I am asking the user some questions, and I need those options to be saved so that I can use that to pick the correct installation procedure. I have it all setup, but I can't get it to find the correct options that I have given. Do you have any ideas?

    My script can be found here.

    https://github.com/dclardy64/ISPConfig-3-Debian-Installer/blob/master/install.sh
     
  2. falko

    falko Super Moderator

    To what part of the script are you referring?
     
  3. dclardy

    dclardy New Member

    In the first part of the script, I ask the user for input. This inputs are saved as variables, and I need them to be used in selected the correct install function.

    Code:
    if [ "$1" != "--help" ]; then
    
    #set mysql root password
    
    	MYSQL_ROOT_PASSWORD="root"
    	echo "Please input the root password of mysql:"
    	read -p "(Default password: root):" MYSQL_ROOT_PASSWORD
    	if [ "$MYSQL_ROOT_PASSWORD" = "" ]; then
    		MYSQL_ROOT_PASSWORD="root"
    	fi
    	echo "==========================="
    	echo "MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD"
    	echo "==========================="
    
    #set Hostname
    
    	HOSTNAME="server1"
    	echo "Please input the Hostname:"
    	read -p "(Default Hostname: server1):" HOSTNAME
    	if [ "$HOSTNAME" = "" ]; then
    		HOSTNAME="server1"
    	fi
    	echo "==========================="
    	echo "HOSTNAME=$HOSTNAME"
    	echo "==========================="
    
    #set Fully Qualified Hostname
    
    	HOSTNAMEFQDN="server1.example.com"
    	echo "Please input the Full Hostname:"
    	read -p "(Default Full Hostname: server1.example.com):" HOSTNAMEFQDN
    	if [ "$HOSTNAMEFQDN" = "" ]; then
    		HOSTNAMEFQDN="server1"
    	fi
    	echo "==========================="
    	echo "HOSTNAMEFQDN=$HOSTNAMEFQDN"
    	echo "==========================="
    
    #set Server IP
    
    	serverIP="123.156.78.9"
    	echo "Please input the Server IP:"
    	read -p "(Default Server IP: 123.456.78.9):" serverIP
    	if [ "$serverIP" = "" ]; then
    		serverIP="123.456.78.9"
    	fi
    	echo "==========================="
    	echo "serverIP=$serverIP"
    	echo "==========================="
    
    #set SSH Port
    
    	sshd_port="22"
    	echo "Please input the SSH Port:"
    	read -p "(Default SSH Port: 22):" sshd_port
    	if [ "$sshd_port" = "" ]; then
    		sshd_port="22"
    	fi
    	echo "==========================="
    	echo "sshd_port=$sshd_port"
    	echo "==========================="
    
    #set Mail Server
    
    	mail_server="Courier"
    	echo "Please select Mail Server (Courier or Dovecot:"
    	read -p "(Default Mail Server: Courier):" mail_server
    	if [ "$mail_server" = "" ]; then
    		mail_server="Courier"
    	fi
    	echo "==========================="
    	echo "mail_server=$mail_server"
    	echo "==========================="
    
    #set DNS Server
    	dns_server="Bind"
    	echo "Please select DNS Server (Bind for now):"
    	read -p "(Default DNS Server: Bind):" dns_server
    	if [ "$dns_server" = "" ]; then
    		dns_server="Bind"
    	fi
    	echo "==========================="
    	echo "dns_server=$dns_server"
    	echo "==========================="
    
    #set Quota
    	quota="Yes"
    	echo "Please select whether to install Quota or Not:"
    	read -p "(Default: Yes):" quota
    	if [ "$quota" = "" ]; then
    		quota="Yes"
    	fi
    	echo "==========================="
    	echo "quota=$quota"
    	echo "==========================="
    
    #set Jailkit
    	jailkit="Yes"
    	echo "Please select whether to install Jailkit or Not:"
    	read -p "(Default: Yes):" jailkit
    	if [ "$jailkit" = "" ]; then
    		jailkit="Yes"
    	fi
    	echo "==========================="
    	echo "jailkit=$jailkit"
    	echo "==========================="
    
    
    $installchoices=install_$mail_server$dns_server$quota$jailkit
    The last section $installchoices returns exactly what I need it do, but when it comes to the install functions it is not found.

    Code:
    #Execute functions#
    if [ "$installchoices" = "install_CourierBindNoNo" ]; then
        basic_server_setup
        install_DashNTP
    	install_MYSQLCourier
    	install_Virus
    	install_Apache
    	install_PureFTPD
    	install_Bind
    	install_Stats
    	install_fail2banCourier
    	install_SquirrelMail
    	install_ISPConfig
    
    elif [ "$installchoices" = "install_CourierBindYesNo" ]; then
    	basic_server_setup
        install_DashNTP
    	install_MYSQLCourier
    	install_Virus
    	install_Apache
    	install_PureFTPD
    	install_Quota
    	install_Bind
    	install_Stats
    	install_fail2banCourier
    	install_SquirrelMail
    	install_ISPConfig
    
    elif [ "$installchoices" = "install_CourierBindYesYes" ]; then
    	basic_server_setup
        install_DashNTP
    	install_MYSQLCourier
    	install_Virus
    	install_Apache
    	install_PureFTPD
    	install_Quota
    	install_Bind
    	install_Stats
    	install_Jailkit
    	install_fail2banCourier
    	install_SquirrelMail
    	install_ISPConfig
    
    elif [ "$installchoices" = "install_CourierBindNoYes" ]; then
    	basic_server_setup
        install_DashNTP
    	install_MYSQLCourier
    	install_Virus
    	install_Apache
    	install_PureFTPD
    	install_Bind
    	install_Stats
    	install_Jailkit
    	install_fail2banCourier
    	install_SquirrelMail
    	install_ISPConfig
    
    elif [ "$installchoices" = "install_DovecotBindNoNo" ]; then
        basic_server_setup
        install_DashNTP
    	install_MYSQLDovecot
    	install_Virus
    	install_Apache
    	install_PureFTPD
    	install_Bind
    	install_Stats
    	install_fail2banDovecot
    	install_SquirrelMail
    	install_ISPConfig
    
    elif [ "$installchoices" = "install_DovecotBindYesNo" ]; then
    	basic_server_setup
        install_DashNTP
    	install_MYSQLDovecot
    	install_Virus
    	install_Apache
    	install_PureFTPD
    	install_Quota
    	install_Bind
    	install_Stats
    	install_fail2banDovecot
    	install_SquirrelMail
    	install_ISPConfig
    
    elif [ "$installchoices" = "install_DovecotBindYesYes" ]; then
    	basic_server_setup
        install_DashNTP
    	install_MYSQLDovecot
    	install_Virus
    	install_Apache
    	install_PureFTPD
    	install_Quota
    	install_Bind
    	install_Stats
    	install_Jailkit
    	install_fail2banDovecot
    	install_SquirrelMail
    	install_ISPConfig
    
    elif [ "$installchoices" = "install_DovecotBindNoYes" ]; then
    	basic_server_setup
        install_DashNTP
    	install_MYSQLDovecot
    	install_Virus
    	install_Apache
    	install_PureFTPD
    	install_Bind
    	install_Stats
    	install_Jailkit
    	install_fail2banDovecot
    	install_SquirrelMail
    	install_ISPConfig
    fi
    #End execute functions#
    I am trying to figure out what I need to do to get the user inputs to allow me to select the correct install function.
     
  4. falko

    falko Super Moderator

    Shouldn't you use
    Code:
    installchoices=install_$mail_server$dns_server$quota$jailkit
    instead of
    Code:
    [COLOR="Red"]$[/COLOR]installchoices=install_$mail_server$dns_server$quota$jailkit
    ?
     
  5. dclardy

    dclardy New Member

    That was part of the problem. There were some other things that I needed to iron out as well, but I have them taken care of now. Thanks for the suggestion.
     
  6. falko

    falko Super Moderator

    So it's working now?
     
  7. dclardy

    dclardy New Member

    Yes. It works. That is why I got you to sticky that Install Script for me!
     

Share This Page