From 95fdaebe15b7156d5c7a8b47a8ee60446dc03a47 Mon Sep 17 00:00:00 2001 From: t3chn0m4g3 Date: Fri, 15 Jun 2018 16:24:20 +0000 Subject: [PATCH] add config file for makeiso rework makeiso.sh / installer.sh to acommodate for the changes --- iso/installer/install.sh | 51 ++++++------ iso/installer/iso.conf.dist | 13 ++++ makeiso.sh | 151 ++++++++++++++++++++++-------------- 3 files changed, 133 insertions(+), 82 deletions(-) create mode 100644 iso/installer/iso.conf.dist diff --git a/iso/installer/install.sh b/iso/installer/install.sh index 837c3487..da1ab1d1 100755 --- a/iso/installer/install.sh +++ b/iso/installer/install.sh @@ -9,15 +9,14 @@ export DIALOGRC=/etc/dialogrc cp /root/installer/dialogrc /etc/ # Some global vars -myPROXYFILEPATH="/root/installer/proxy" -myNTPCONFPATH="/root/installer/ntp" -myPFXPATH="/root/installer/keys/8021x.pfx" -myPFXPWPATH="/root/installer/keys/8021x.pw" -myPFXHOSTIDPATH="/root/installer/keys/8021x.id" +myNTPCONFFILE="/root/installer/ntp.conf" +myPFXFILE="/root/installer/keys/8021x.pfx" myTPOTCOMPOSE="/opt/tpot/etc/tpot.yml" myBACKTITLE="T-Pot-Installer" mySITES="https://index.docker.io https://github.com https://pypi.python.org https://ubuntu.com" myPROGRESSBOXCONF=" --backtitle "$myBACKTITLE" --progressbox 24 80" +myCONF_FILE="/root/installer/iso.conf" +myTPOT_CONF_FILE="/root/installer/tpot.conf" fuRANDOMWORD () { local myWORDFILE="$1" @@ -32,12 +31,25 @@ sleep 3 tput civis dialog --no-ok --no-cancel --backtitle "$myBACKTITLE" --title "[ Wait to avoid interference with service messages ]" --pause "" 6 80 7 +# Let's load the iso config file +if [ -f $myCONF_FILE ]; + then + dialog --backtitle "$myBACKTITLE" --title "[ Found personalized iso.config ]" --msgbox "\nYour personalized settings will be applied!" 7 47 + source $myCONF_FILE + else + # dialog logic considers 1=false, 0=true + myCONF_PROXY_USE="1" + myCONF_SSH_PUBKEY_USE="1" + myCONF_PFX_USE="1" + myCONF_NTP_USE="1" +fi + # Let's setup the proxy for env -if [ -f $myPROXYFILEPATH ]; +if [ "$myCONF_PROXY_USE" == "0" ]; then dialog --title "[ Setting up the proxy ]" $myPROGRESSBOXCONF <&1>/dev/null <&1>/dev/null <&1 | dialog --title "[ Generating a self-signed-certificate for NGINX ]" $myPROGRESSBOXCONF; # Let's setup the ntp server -if [ -f $myNTPCONFPATH ]; +if [ "$myCONF_NTP_USE" == "0" ]; then dialog --title "[ Setting up the ntp server ]" $myPROGRESSBOXCONF <&1 | dialog --title "[ Setting up the ntp server ]" $myPROGRESSBOXCONF + cp $myNTPCONFFILE /etc/ntp.conf 2>&1 | dialog --title "[ Setting up the ntp server ]" $myPROGRESSBOXCONF fi # Let's setup 802.1x networking -if [ -f $myPFXPATH ]; +if [ "myCONF_PFX_USE" == "0" ]; then dialog --title "[ Setting 802.1x networking ]" $myPROGRESSBOXCONF <&1 | dialog --title "[ Setting 802.1x networking ]" $myPROGRESSBOXCONF - if [ -f $myPFXPWPATH ]; - then -dialog --title "[ Setting up 802.1x password ]" $myPROGRESSBOXCONF <&1 | dialog --title "[ Setting 802.1x networking ]" $myPROGRESSBOXCONF tee -a /etc/network/interfaces 2>&1>/dev/null < $myAUTHKEYSPATH +rm -rf $myTMP $myTPOTDIR $myPFXFILE $myNTPCONFFILE $myCONF_FILE +echo > $myAUTHKEYSFILE if [ -f $myTPOTSEED.bak ]; then mv $myTPOTSEED.bak $myTPOTSEED @@ -64,25 +82,6 @@ function valid_ip() return $stat } -# Let's check if all dependencies are met -myINST="" -for myDEPS in $myPACKAGES; -do - myOK=$(dpkg -s $myDEPS | grep ok | awk '{ print $3 }'); - if [ "$myOK" != "ok" ] - then - myINST=$(echo $myINST $myDEPS) - fi -done -if [ "$myINST" != "" ] - then - apt-get update -y - for myDEPS in $myINST; - do - apt-get install $myDEPS -y - done -fi - # Let's ask if the user wants to run the script ... dialog --backtitle "$myBACKTITLE" --title "[ Continue? ]" --yesno "\nDownload latest supported Ubuntu Mini ISO and build the T-Pot Install Image." 8 50 mySTART=$? @@ -91,29 +90,39 @@ if [ "$mySTART" = "1" ]; exit fi +# Let's load the default config file +if [ -f $myCONF_DEFAULT_FILE ]; + then + source $myCONF_DEFAULT_FILE +fi + # Let's ask the user for a proxy ... while true; do dialog --backtitle "$myBACKTITLE" --title "[ Proxy Settings ]" --yesno "\nDo you want to configure a proxy?" 7 50 - myADDPROXY=$? - if [ "$myADDPROXY" = "0" ] + myCONF_PROXY_USE=$? + if [ "$myCONF_PROXY_USE" = "0" ] then myIPRESULT="false" while [ "$myIPRESULT" = "false" ]; do - myPROXYIP=$(dialog --backtitle "$myBACKTITLE" --no-cancel --title "Proxy IP?" --inputbox "" 7 50 "1.2.3.4" 3>&1 1>&2 2>&3 3>&-) - if valid_ip $myPROXYIP; then myIPRESULT="true"; fi + myCONF_PROXY_IP=$(dialog --backtitle "$myBACKTITLE" --no-cancel --title "Proxy IP?" --inputbox "" 7 50 "$myCONF_PROXY_IP" 3>&1 1>&2 2>&3 3>&-) + if valid_ip $myCONF_PROXY_IP; then myIPRESULT="true"; fi done myPORTRESULT="false" while [ "$myPORTRESULT" = "false" ]; do - myPROXYPORT=$(dialog --backtitle "$myBACKTITLE" --no-cancel --title "Proxy Port (i.e. 3128)?" --inputbox "" 7 50 "3128" 3>&1 1>&2 2>&3 3>&-) - if [[ $myPROXYPORT =~ ^-?[0-9]+$ ]] && [ $myPROXYPORT -gt 0 ] && [ $myPROXYPORT -lt 65536 ]; then myPORTRESULT="true"; fi + myCONF_PROXY_PORT=$(dialog --backtitle "$myBACKTITLE" --no-cancel --title "Proxy Port (i.e. 3128)?" --inputbox "" 7 50 "$myCONF_PROXY_PORT" 3>&1 1>&2 2>&3 3>&-) + if [[ $myCONF_PROXY_PORT =~ ^-?[0-9]+$ ]] && [ $myCONF_PROXY_PORT -gt 0 ] && [ $myCONF_PROXY_PORT -lt 65536 ]; then myPORTRESULT="true"; fi done - echo http://$myPROXYIP:$myPROXYPORT > $myPROXYCONFIG - sed -i.bak 's#d-i mirror/http/proxy.*#d-i mirror/http/proxy string http://'$myPROXYIP':'$myPROXYPORT'/#' $myTPOTSEED + ################################################################# + #echo http://$myCONF_PROXY_IP:$myCONF_PROXY_PORT > $myPROXYCONFIG + ################################################################# + sed -i.bak 's#d-i mirror/http/proxy.*#d-i mirror/http/proxy string http://'$myCONF_PROXY_IP':'$myCONF_PROXY_PORT'/#' $myTPOTSEED break else + myCONF_PROXY_IP="" + myCONF_PROXY_PORT="" break fi done @@ -122,19 +131,20 @@ done while true; do dialog --backtitle "$myBACKTITLE" --title "[ Add ssh keys? ]" --yesno "\nDo you want to add public key(s) to authorized_keys file?" 8 50 - myADDKEYS=$? - if [ "$myADDKEYS" = "0" ] + myCONF_SSH_PUBKEY_USE=$? + if [ "$myCONF_SSH_PUBKEY_USE" = "0" ] then - myKEYS=$(dialog --backtitle "$myBACKTITLE" --fselect "/" 15 50 3>&1 1>&2 2>&3 3>&-) - if [ -f "$myKEYS" ] + myCONF_SSH_PUBKEY_FILE=$(dialog --backtitle "$myBACKTITLE" --fselect "$myCONF_SSH_PUBKEY_FILE" 15 50 3>&1 1>&2 2>&3 3>&-) + if [ -f "$myCONF_SSH_PUBKEY_FILE" ] then - cat $myKEYS > $myAUTHKEYSPATH + cp $myCONF_SSH_PUBKEY_FILE $myAUTHKEYSFILE break else dialog --backtitle "$myBACKTITLE" --title "[ Try again! ]" --msgbox "\nThis is no regular file." 7 50; fi else - echo > $myAUTHKEYSPATH + echo > $myAUTHKEYSFILE + myCONF_SSH_PUBKEY_FILE="" break fi done @@ -143,27 +153,36 @@ done while true; do dialog --backtitle "$myBACKTITLE" --title "[ Need 802.1x auth? ]" --yesno "\nDo you want to add a 802.1x host certificate?" 7 50 - myADDPFX=$? - if [ "$myADDPFX" = "0" ] + myCONF_PFX_USE=$? + if [ "$myCONF_PFX_USE" = "0" ] then - myPFX=$(dialog --backtitle "$myBACKTITLE" --fselect "/" 15 50 3>&1 1>&2 2>&3 3>&-) - if [ -f "$myPFX" ] + myCONF_PFX_FILE=$(dialog --backtitle "$myBACKTITLE" --fselect "$myCONF_PFX_FILE" 15 50 3>&1 1>&2 2>&3 3>&-) + if [ -f "$myCONF_PFX_FILE" ] then - cp $myPFX $myPFXPATH + cp $myCONF_PFX_FILE $myPFXFILE dialog --backtitle "$myBACKTITLE" --title "[ Password protected? ]" --yesno "\nDoes the certificate need your password?" 7 50 - myADDPFXPW=$? - if [ "$myADDPFXPW" = "0" ] + myCONF_PFX_PW_USE=$? + if [ "$myCONF_PFX_PW_USE" = "0" ] then - myPFXPW=$(dialog --backtitle "$myBACKTITLE" --no-cancel --inputbox "Password?" 7 50 3>&1 1>&2 2>&3 3>&-) - echo $myPFXPW > $myPFXPWPATH + myCONF_PFX_PW=$(dialog --backtitle "$myBACKTITLE" --no-cancel --inputbox "Password?" 7 50 3>&1 1>&2 2>&3 3>&-) + ################################### + #echo $myCONF_PFX_PW > $myPFXPWPATH + ################################### + else + myCONF_PFX_PW="" fi - myPFXHOSTID=$(dialog --backtitle "$myBACKTITLE" --no-cancel --inputbox "Host ID?" 7 50 "." 3>&1 1>&2 2>&3 3>&-) - echo $myPFXHOSTID > $myPFXHOSTIDPATH + myCONF_PFX_HOST_ID=$(dialog --backtitle "$myBACKTITLE" --no-cancel --inputbox "Host ID?" 7 50 "$myCONF_PFX_HOST_ID" 3>&1 1>&2 2>&3 3>&-) + ############################################ + #echo $myCONF_PFX_HOST_ID > $myPFXHOSTIDPATH + ############################################ break else dialog --backtitle "$myBACKTITLE" --title "[ Try again! ]" --msgbox "\nThis is no regular file." 7 50; fi else + myCONF_PFX_FILE="" + myCONF_PFX_HOST_ID="" + myCONF_PFX_PW="" break fi done @@ -172,16 +191,16 @@ done while true; do dialog --backtitle "$myBACKTITLE" --title "[ NTP server? ]" --yesno "\nDo you want to configure a ntp server?" 7 50 - myADDNTP=$? - if [ "$myADDNTP" = "0" ] + myCONF_NTP_USE=$? + if [ "$myCONF_NTP_USE" = "0" ] then myIPRESULT="false" while [ "$myIPRESULT" = "false" ]; do - myNTPIP=$(dialog --backtitle "$myBACKTITLE" --no-cancel --title "NTP IP?" --inputbox "" 7 50 "1.2.3.4" 3>&1 1>&2 2>&3 3>&-) - if valid_ip $myNTPIP; then myIPRESULT="true"; fi + myCONF_NTP_IP=$(dialog --backtitle "$myBACKTITLE" --no-cancel --title "NTP IP?" --inputbox "" 7 50 "$myCONF_NTP_IP" 3>&1 1>&2 2>&3 3>&-) + if valid_ip $myCONF_NTP_IP; then myIPRESULT="true"; fi done -tee $myNTPCONFPATH < $myCONF_FILE +echo "myCONF_PROXY_USE=\"$myCONF_PROXY_USE\"" >> $myCONF_FILE +echo "myCONF_PROXY_IP=\"$myCONF_PROXY_IP\"" >> $myCONF_FILE +echo "myCONF_PROXY_PORT=\"$myCONF_PROXY_PORT\"" >> $myCONF_FILE +echo "myCONF_SSH_PUBKEY_USE=\"$myCONF_SSH_PUBKEY_USE\"" >> $myCONF_FILE +echo "myCONF_SSH_PUBKEY_FILE=\"$myCONF_SSH_PUBKEY_FILE\"" >> $myCONF_FILE +echo "myCONF_PFX_USE=\"$myCONF_PFX_USE\"" >> $myCONF_FILE +echo "myCONF_PFX_FILE=\"$myCONF_PFX_FILE\"" >> $myCONF_FILE +echo "myCONF_PFX_PW_USE=\"$myCONF_PFX_PW_USE\"" >> $myCONF_FILE +echo "myCONF_PFX_PW=\"$myCONF_PFX_PW\"" >> $myCONF_FILE +echo "myCONF_PFX_HOST_ID=\"$myCONF_PFX_HOST_ID\"" >> $myCONF_FILE +echo "myCONF_NTP_USE=\"$myCONF_NTP_USE\"" >> $myCONF_FILE +echo "myCONF_NTP_IP=\"$myCONF_NTP_IP\"" >> $myCONF_FILE + # Let's download Ubuntu Minimal ISO if [ ! -f $myUBUNTUISO ] then