HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials

HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials (http://www.howtoforge.com/forums/index.php)
-   Programming/Scripts (http://www.howtoforge.com/forums/forumdisplay.php?f=7)
-   -   Bash Script Help (http://www.howtoforge.com/forums/showthread.php?t=54055)

dclardy 6th September 2011 03:59

Bash Script Help
 
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/ISPConf...ter/install.sh

falko 6th September 2011 11:03

To what part of the script are you referring?

dclardy 6th September 2011 17:28

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.

falko 7th September 2011 11:46

Shouldn't you use
Code:

installchoices=install_$mail_server$dns_server$quota$jailkit
instead of
Code:

$installchoices=install_$mail_server$dns_server$quota$jailkit
?

dclardy 7th September 2011 16:17

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.

falko 8th September 2011 12:16

So it's working now?

dclardy 8th September 2011 18:48

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


All times are GMT +2. The time now is 04:21.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.