"Fossies" - the Fresh Open Source Software Archive

Member "fogproject-1.5.9/lib/common/input.sh" (13 Sep 2020, 13171 Bytes) of package /linux/misc/fogproject-1.5.9.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "input.sh": 1.5.8_vs_1.5.9.

    1 #  FOG is a computer imaging solution.
    2 #  Copyright (C) 2007  Chuck Syperski & Jian Zhang
    3 #
    4 #   This program is free software: you can redistribute it and/or modify
    5 #   it under the terms of the GNU General Public License as published by
    6 #   the Free Software Foundation, either version 3 of the License, or
    7 #    any later version.
    8 #
    9 #   This program is distributed in the hope that it will be useful,
   10 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
   11 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12 #   GNU General Public License for more details.
   13 #
   14 #   You should have received a copy of the GNU General Public License
   15 #   along with this program.  If not, see <http://www.gnu.org/licenses/>.
   16 if [[ $guessdefaults == 1 ]]; then
   17     case $linuxReleaseName in
   18         *[Ff][Ee][Dd][Oo][Rr][Aa]*|*[Rr][Ee][Dd][Hh][Aa][Tt]*|*[Cc][Ee][Nn][Tt][Oo][Ss]*|*[Mm][Aa][Gg][Ee][Ii][Aa]*)
   19             strSuggestedOS=1
   20             ;;
   21         *[Uu][Bb][Uu][Nn][Tt][Uu]*|*[Bb][Ii][Aa][Nn]*|*[Mm][Ii][Nn][Tt]*)
   22             strSuggestedOS=2
   23             ;;
   24         *[Aa][Rr][Cc][Hh]*)
   25             strSuggestedOS=3
   26             ;;
   27         *)
   28             strSuggestedOS=1
   29             ;;
   30     esac
   31     allinterfaces=$(getAllNetworkInterfaces)
   32     strSuggestedInterface=$(echo ${allinterfaces} | awk '{print $1}')
   33     if [[ -z $strSuggestedInterface ]]; then
   34         echo "ERROR: Not able to find a network interface that is up on your system."
   35         exit 1
   36     fi
   37     strSuggestedRoute=$(ip route | grep -E "default.*${strSuggestedInterface}|${strSuggestedInterface}.*default" | head -n1 | cut -d' ' -f3 | tr -d [:blank:])
   38     if [[ -z $strSuggestedRoute ]]; then
   39         strSuggestedRoute=$(route -n 2>/dev/null | grep -E "^.*UG.*${strSuggestedInterface}$" | head -n1 | awk '{print $2}' | tr -d [:blank:])
   40     fi
   41     strSuggestedDNS=""
   42     [[ -f /etc/resolv.conf ]] && strSuggestedDNS=$(cat /etc/resolv.conf | grep -E "^nameserver" | head -n 1 | tr -d "nameserver" | tr -d [:blank:] | grep "^[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*$")
   43     [[ -z $strSuggestedDNS && -d /etc/NetworkManager/system-connections ]] && strSuggestedDNS=$(cat /etc/NetworkManager/system-connections/* | grep "dns" | head -n 1 | tr -d "dns=" | tr -d ";" | tr -d [:blank:] | grep "^[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*$")
   44     if [[ -z $strSuggestedDNS ]]; then #If the suggested DNS is still empty, take further steps to get the addresses.
   45         mkdir -p /tmp > /dev/null 2>&1 #Make sure /tmp exists, this will be the working directory.
   46         cat /etc/resolv.conf | grep "nameserver" > /tmp/nameservers.txt #Get all lines from reslov.conf that have "nameserver" in them.
   47         sed -i 's:#.*$::g' /tmp/nameservers.txt #Remove all comments from new file.
   48         sed -i -- 's/nameserver //g' /tmp/nameservers.txt #Change "nameserver " to "tmpDns="
   49         sed -i '/^$/d' /tmp/nameservers.txt #Delete blank lines from temp file.
   50         strSuggestedDNS=$(head -n 1 /tmp/nameservers.txt) #Get first DNS Address from the file.
   51     rm -f /tmp/nameservers.txt #Cleanup after ourselves.    
   52     fi
   53     strSuggestedHostname=$(hostname -f)
   54 fi
   55 displayOSChoices
   56 while [[ -z $installtype ]]; do
   57     installtype="N"
   58     if [[ -z $autoaccept ]]; then
   59         echo "  FOG Server installation modes:"
   60         echo "      * Normal Server: (Choice N) "
   61         echo "          This is the typical installation type and"
   62         echo "          will install all FOG components for you on this"
   63         echo "          machine.  Pick this option if you are unsure what to pick."
   64         echo
   65         echo "      * Storage Node: (Choice S)"
   66         echo "          This install mode will only install the software required"
   67         echo "          to make this server act as a node in a storage group"
   68         echo
   69         echo "  More information:  "
   70         echo "     http://www.fogproject.org/wiki/index.php?title=InstallationModes"
   71         echo
   72         echo -n "  What type of installation would you like to do? [N/s (Normal/Storage)] "
   73         read installtype
   74     fi
   75     case $installtype in
   76         [Nn]|[Nn][Oo][Rr][Mm][Aa][Ll]|"")
   77             installtype="N"
   78             ;;
   79         [Ss]|[Ss][Tt][Oo][Rr][Aa][Gg][Ee])
   80             installtype="S"
   81             ;;
   82         *)
   83             installtype=""
   84             echo "  Invalid input, please try again."
   85             ;;
   86     esac
   87 done
   88 while [[ -z $interface ]]; do
   89     blInt="N"
   90     if [[ -z $autoaccept ]]; then
   91         echo
   92         echo "  We found the following interfaces on your system:"
   93         for i in $allinterfaces
   94         do
   95             iip=$(ip -4 addr show $i | awk '$1 == "inet" {print $2}')
   96             echo "      * $i - $iip"
   97         done
   98         echo
   99         echo "  Would you like to change the default network interface from $strSuggestedInterface?"
  100         echo -n "  If you are not sure, select No. [y/N] "
  101         read blInt
  102     fi
  103     case $blInt in
  104         [Nn]|[Nn][Oo]|"")
  105             interface=$strSuggestedInterface
  106             ;;
  107         [Yy]|[Yy][Ee][Ss])
  108             echo -n "  What network interface would you like to use? "
  109             read interface
  110             ;;
  111         *)
  112             echo "  Invalid input, please try again."
  113             ;;
  114     esac
  115     ip -4 link show $interface >/dev/null 2>&1
  116     if [[ $? -ne 0 ]]; then
  117         echo
  118         echo "   * The network interface named $interface does not exist."
  119         interface=""
  120         continue
  121     fi
  122     ipaddress=$(ip -4 addr show $interface | awk '$1 == "inet" {gsub(/\/.*$/, "", $2); print $2}')
  123     if [[ $(validip $ipaddress) -ne 0 ]]; then
  124         echo
  125         echo "   * The interface $interface does not seem to have a valid IP configured to it."
  126         interface=""
  127         continue
  128     fi
  129     submask=$(cidr2mask $(getCidr $interface))
  130     if [[ -z $submask ]]; then
  131         submask=$(/sbin/ifconfig -a | grep $ipaddress -B1 | awk -F'[netmask ]+' '{print $4}' | head -n2)
  132         submask=$(mask2cidr $submask)
  133     fi
  134 done
  135 if [[ $strSuggestedHostname == $ipaddress ]]; then
  136     strSuggestedHostname=$(hostnamectl --static)
  137 fi
  138 case $installtype in
  139     [Nn])
  140         count=0
  141         blRouter=""
  142         blDNS=""
  143         installlang=""
  144         while [[ -z $routeraddress ]]; do
  145             if [[ -z $autoaccept ]]; then
  146                 echo
  147                 echo -n "  Would you like to setup a router address for the DHCP server? [Y/n] "
  148                 read blRouter
  149             fi
  150             case $blRouter in
  151                 [Yy]|[Yy][Ee][Ss]|"")
  152                     if [[ $count -ge 1 ]] || [[ -z $autoaccept ]]; then
  153                         echo "  What is the IP address to be used for the router on"
  154                         echo -n "      the DHCP server? [$strSuggestedRoute]"
  155                         read routeraddress
  156                     fi
  157                     case $routeraddress in
  158                         "")
  159                             routeraddress=$(echo $strSuggestedRoute | grep -o '^[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}$' | tr -d '[[:space:]]')
  160                             ;;
  161                         *)
  162                             routeraddress=$(echo $routeraddress | grep -o '^[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}$' | tr -d '[[:space:]]')
  163                             ;;
  164                     esac
  165                     if [[ ! $(validip $routeraddress) -eq 0 ]]; then
  166                         routeraddress=""
  167                         echo "  Invalid router IP Address!"
  168                         continue
  169                     fi
  170                     plainrouter=$routeraddress
  171                     ;;
  172                 [Nn]|[Nn][Oo])
  173                     routeraddress="#   No router address added"
  174                     ;;
  175                 *)
  176                     echo "  Invalid input, please try again."
  177                     ;;
  178             esac
  179         done
  180         count=0
  181         while [[ -z $dnsaddress ]]; do
  182             if [[ -z $autoaccept ]]; then
  183                 echo
  184                 echo -n "  Would you like DHCP to handle DNS? [Y/n] "
  185                 read blDNS
  186             fi
  187             case $blDNS in
  188                 [Yy]|[Yy][Ee][Ss]|"")
  189                     if [[ $count -ge 1 ]] || [[ -z $autoaccept ]]; then
  190                         echo -n "  What DNS address should DHCP allow? [$strSuggestedDNS] "
  191                         read dnsaddress
  192                     fi
  193                     case $dnsaddress in
  194                         "")
  195                             dnsaddress=$(echo $strSuggestedDNS | grep -o '^[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}$' | tr -d '[[:space:]]')
  196                             ;;
  197                         *)
  198                             dnsaddress=$(echo $dnsaddress | grep -o '^[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}$' | tr -d '[[:space:]]')
  199                             ;;
  200                     esac
  201                     if [[ ! $(validip $dnsaddress) -eq 0 ]]; then
  202                         dnsaddress=""
  203                         echo "  Invalid DNS IP address!"
  204                     fi
  205                     ;;
  206                 [Nn]|[Nn][Oo])
  207                     dnsaddress="#   No dns added"
  208                     ;;
  209                 *)
  210                     echo "  Invalid input, please try again."
  211                     ;;
  212             esac
  213         done
  214         while [[ -z $dodhcp ]]; do
  215             if [[ -z $autoaccept ]]; then
  216                 echo
  217                 echo -n "  Would you like to use the FOG server for DHCP service? [y/N] "
  218                 read dodhcp
  219             fi
  220             case $dodhcp in
  221                 [Nn]|[Nn][Oo]|"")
  222                     bldhcp=0
  223                     dodhcp="N"
  224                     ;;
  225                 [Yy]|[Yy][Ee][Ss])
  226                     bldhcp=1
  227                     ;;
  228                 *)
  229                     echo "  Invalid input, please try again."
  230                     ;;
  231             esac
  232         done
  233         while [[ -z $installlang ]]; do
  234             if [[ -z $autoaccept ]]; then
  235                 echo
  236                 echo "  This version of FOG has internationalization support, would  "
  237                 echo -n "  you like to install the additional language packs? [y/N] "
  238                 read installlang
  239             fi
  240             case $installlang in
  241                 [Nn]|[Nn][Oo]|"")
  242                     installlang=0
  243                     ;;
  244                 [Yy]|[Yy][Ee][Ss])
  245                     installlang=1
  246                     ;;
  247                 *)
  248                     echo "  Invalid input, please try again."
  249                     ;;
  250             esac
  251         done
  252         [[ -z $snmysqlhost ]] && snmysqlhost='localhost'
  253         [[ -z $snmysqluser ]] && snmysqluser='fogmaster'
  254         ;;
  255     [Ss])
  256         while [[ -z $snmysqlhost ]]; do
  257             echo
  258             echo "  What is the IP address or hostname of the FOG server running "
  259             echo "  the fog database?  This is typically the server that also "
  260             echo -n "  runs the web server, dhcp, and tftp.  IP or Hostname: "
  261             read snmysqlhost
  262         done
  263         strSuggestedSNUser='fogstorage'
  264         while [[ -z $snmysqluser ]]; do
  265             snmysqluser=$strSuggestedSNUser
  266             if [[ -z $autoaccept ]]; then
  267                 echo
  268                 echo "  What is the username to access the database?"
  269                 echo "  This information is storage in the management portal under ";
  270                 echo "  'FOG Configuration' -> "
  271                 echo "  'FOG Settings' -> "
  272                 echo "  'FOG Storage Nodes' -> "
  273                 echo -n "  'FOG_STORAGENODE_MYSQLUSER'. Username [$strSuggestedSNUser]: "
  274                 read snmysqluser
  275                 [[ -z $snmysqluser ]] && snmysqluser=$strSuggestedSNUser
  276             fi
  277         done
  278         while [[ -z $snmysqlpass ]]; do
  279             echo
  280             echo "  What is the password to access the database?  "
  281             echo "  This information is storage in the management portal under "
  282             echo "  'FOG Configuration' -> "
  283             echo "  'FOG Settings' -> "
  284             echo "  'FOG Storage Nodes' -> "
  285             echo  -n "  'FOG_STORAGENODE_MYSQLPASS'.  Password: "
  286             read -r snmysqlpass
  287             [[ -z $snmysqlpass ]] && echo "Invalid input, please try again."
  288         done
  289         ;;
  290 esac
  291 while [[ -z $dohttps ]]; do
  292     if [[ -z $autoaccept && -z $shttpproto ]]; then
  293         echo
  294         echo "  Using encrypted connections is state of the art on the web and we"
  295         echo "  encourage you to enable this for your FOG server. But using HTTPS"
  296         echo "  has some implications within FOG, PXE and fog-client and you want"
  297         echo "  to read https://wiki.fogproject.org/HTTPS before you decide!"
  298         echo -n "  Would you like to enable secure HTTPS on your FOG server? [y/N] "
  299         read dohttps
  300     fi
  301     [[ "$shttpproto" == "https" ]] && dohttps="yes"
  302     case $dohttps in
  303         [Nn]|[Nn][Oo]|"")
  304             dohttps=0
  305             httpproto="http"
  306             ;;
  307         [Yy]|[Yy][Ee][Ss])
  308             dohttps=1
  309             httpproto="https"
  310             ;;
  311         *)
  312             echo "  Invalid input, please try again."
  313             dohttps=""
  314             ;;
  315     esac
  316 done