diff --git a/iiab-network b/iiab-network index 9ac41f986..54e781a66 100755 --- a/iiab-network +++ b/iiab-network @@ -4,11 +4,15 @@ CWD=`pwd` export ANSIBLE_LOG_PATH="$CWD/iiab-network.log" -if [ ! -f iiab-network.yml ]; then - echo "iiab-network.yml not found in current directory." - echo "Please rerun this command from the top level of the git repo." - echo "Exiting." +exit_error() { + echo -e "\nEXITING: "$@ | tee -a /opt/iiab/iiab/iiab-network.log exit 1 +} + +if [ ! -f iiab-network.yml ]; then + exit_error "iiab-network.yml not found in current directory." \ + "Please rerun this command from the top level of the git repo." \ + "Exiting." fi OS="unknown" # will be overridden below, if /etc/iiab/iiab.env is legit @@ -19,26 +23,21 @@ if [ -f /etc/iiab/iiab.env ]; then if grep -q STAGE= /etc/iiab/iiab.env ; then echo -e "\nExtracted STAGE=$STAGE (counter) from /etc/iiab/iiab.env" if ! [ "$STAGE" -eq "$STAGE" ] 2> /dev/null; then - echo -e "\nEXITING: STAGE (counter) value == ""$STAGE"" is non-integer" - exit 1 + exit_error "STAGE (counter) value == ""$STAGE"" is non-integer" elif [ "$STAGE" -lt 0 ] || [ "$STAGE" -gt 9 ]; then - echo -e "\nEXITING: STAGE (counter) value == ""$STAGE"" is out-of-range" - exit 1 + exit_error "STAGE (counter) value == ""$STAGE"" is out-of-range" elif [ "$STAGE" -lt 3 ]; then - echo -e "\nEXITING: STAGE (counter) value == ""$STAGE" - echo -e "\nIIAB Stage 3 not complete." - echo -e "\nPlease run: ./iiab-install" - exit 1 + exit_error "STAGE (counter) value == ""$STAGE" \ + "\nIIAB Stage 3 not complete." \ + "\nPlease run: ./iiab-install" fi else - echo -e "\nEXITING: STAGE (counter) not found" - echo -e "\nIIAB not installed." - echo -e "\nPlease run: ./iiab-install" - exit 1 + exit_error "STAGE (counter) not found" \ + "\nIIAB not installed." \ + "\nPlease run: ./iiab-install" fi else - echo -e "\nEXITING: /etc/iiab/iiab.env not found" - exit 1 + exit_error "/etc/iiab/iiab.env not found" fi echo "Ansible will now run iiab-network.yml -- log file is iiab-network.log" diff --git a/roles/network/templates/netwarn/netwarn b/roles/network/templates/netwarn/netwarn index 146c41725..fc4c8f4bb 100755 --- a/roles/network/templates/netwarn/netwarn +++ b/roles/network/templates/netwarn/netwarn @@ -1,13 +1,4 @@ -#!/bin/sh - -# Some OS's like Ubuntu with LightDM *IGNORE* the above shebang line when this -# script is invcked from /usr/share/mate/autostart/netwarn-iiab-network.desktop -# -# WHAT HAPPENS: sh (dash) NOT BASH will always be run! As confirmed by: -# -# ps -p $$ # Whereas 'echo $SHELL' DOES NOT show the actual running shell! -# -# RECAP: We hard-code the above '#!/bin/sh' for uniformity across all distros. +#!/bin/bash if [ -f /etc/iiab/install-flags/iiab-network-complete ]; then exit @@ -15,18 +6,19 @@ fi zenity --question --width=360 --text="IIAB needs to configure networking:\n\n► Internet must be live before you begin.\n►You might be prompted for your password.\n\nContinue? (This can take 2-3 minutes)" rc=$? -if [ "$rc" != "0" ]; then +if [[ $rc != "0" ]]; then exit $rc fi -x-terminal-emulator -e /usr/local/bin/iiab-network -rc=$? -if [ "$rc" != "0" ] && [ ! -f /usr/bin/mate-terminal ]; then +# mate-terminal always returns 255 w/ autostart, so intercept/record return code +x-terminal-emulator -e "bash -c '/usr/local/bin/iiab-network; echo \"\$?\" > /tmp/iiab-network.rc'" +rc=$(cat /tmp/iiab-network.rc) +if [[ $rc != "0" ]]; then zenity --warning --width=360 --text="iiab-network exited with error: $rc\n\nPlease review /opt/iiab/iiab/iiab-network.log" exit $rc fi zenity --question --width=360 --text="iiab-network complete.\n\nWould you like to REBOOT now? (Recommended)" -if [ "$?" = "0" ]; then +if [[ $? == "0" ]]; then x-terminal-emulator -e "sudo reboot" fi