diff --git a/provision_new_server.sh b/provision_new_server.sh index 1b6c1ba..c370665 100755 --- a/provision_new_server.sh +++ b/provision_new_server.sh @@ -7,6 +7,7 @@ name_old=$(cat /etc/hostname) #ipadd_old=$(ifconfig | awk '/inet6/{next;} /127.0.0.1/{next;} /inet/{print $2;}' | grep 172.23) cidr_old=$(ip a | awk '/inet6/{next;} /127.0.0.1/{next;} /inet/{print $2;}' | grep 172.23) ipadd_old=$(echo $cidr_old | awk -F '/' '{print $1}') +ipc_present=false # Get user input echo "Enter new host information." @@ -27,11 +28,20 @@ if ! echo $cidr | grep -E "^$n(\.$n){3}/$m$" &>/dev/null; then exit 12 fi # End input sanity check + +# Test if 'ipcalc' utility is available +which ipcalc &>/dev/null && ipc_present=true + ipadd=$(echo $cidr | awk -F '/' '{print $1}') echo - printf "Review these changes carefully!\n\n" -printf "+,CURRENT,PENDING\nHostname:,$name_old,$name\nAddress:,$ipadd_old,$ipadd\nCIDR:,$cidr_old,$cidr" | column -s, -t +if [ "$ipc_present" = true ]; then + snm=$(ipcalc $cidr | grep Netmask | grep -Eo "($n.){3}$n") + snm_old=$(ipcalc $cidr_old | grep Netmask | grep -Eo "($n.){3}$n") + printf "+,CURRENT,PENDING\nHostname:,$name_old,$name\nAddress:,$ipadd_old,$ipadd\nCIDR:,$cidr_old,$cidr\nNetmask:,$snm_old,$snm" | column -s, -t +else + printf "+,CURRENT,PENDING\nHostname:,$name_old,$name\nAddress:,$ipadd_old,$ipadd\nCIDR:,$cidr_old,$cidr" | column -s, -t +fi echo read -p "Are you sure you want to apply the changes above? (y/N)" -n 1 -r if echo $REPLY | grep -Eq '^[Yy]$'; then