Compare commits

..

No commits in common. 'master' and 'NS911116' have entirely different histories.

@ -1,11 +1,11 @@
#!/usr/bin/env bash #!/usr/bin/env sh
#Author: Aaron Johnson #Author: Aaron Johnson
#Comment: This script is not intended to be portable or fail-safe, and is used in my personal provisioning process. #Comment: This script is not intended to be portable or fail-safe, and is used in my personal provisioning process.
name_old=$(cat /etc/hostname) name_old=$(cat /etc/hostname)
#Below command preserved in case it is needed to add older OS support #Below command preserved in case it is needed to add older OS support
#ipadd_old=$(ifconfig | awk '/inet6/{next;} /127.0.0.1/{next;} /inet/{print $2;}' | grep 172.23) #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 -E '172.2[31]') 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}') ipadd_old=$(echo $cidr_old | awk -F '/' '{print $1}')
ipc_present=false ipc_present=false
@ -23,21 +23,21 @@ fi
## Validate CIDR ## Validate CIDR
n='([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])' n='([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])'
m='([0-9]|[12][0-9]|3[012])' m='([0-9]|[12][0-9]|3[012])'
if ! echo $cidr | grep -E "^$n(\.$n){3}/$m$" 2>&1 >/dev/null; then if ! echo $cidr | grep -E "^$n(\.$n){3}/$m$" &>/dev/null; then
printf "\nCIDR input is not valid!\n" printf "\nCIDR input is not valid!\n"
exit 12 exit 12
fi fi
# End input sanity check # End input sanity check
# Test if 'ipcalc' utility is available # Test if 'ipcalc' utility is available
which ipcalc 2>&1 >/dev/null && ipc_present=true which ipcalc &>/dev/null && ipc_present=true
ipadd=$(echo $cidr | awk -F '/' '{print $1}') ipadd=$(echo $cidr | awk -F '/' '{print $1}')
echo echo
printf "Review these changes carefully!\n\n" printf "Review these changes carefully!\n\n"
if [ "$ipc_present" = true ]; then if [ "$ipc_present" = true ]; then
snm=$(ipcalc $cidr | grep Netmask | grep -Eo "($n\.){3}$n") snm=$(ipcalc $cidr | grep Netmask | grep -Eo "($n.){3}$n")
snm_old=$(ipcalc $cidr_old | 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 printf "+,CURRENT,PENDING\nHostname:,$name_old,$name\nAddress:,$ipadd_old,$ipadd\nCIDR:,$cidr_old,$cidr\nNetmask:,$snm_old,$snm" | column -s, -t
else else
printf "+,CURRENT,PENDING\nHostname:,$name_old,$name\nAddress:,$ipadd_old,$ipadd\nCIDR:,$cidr_old,$cidr" | column -s, -t printf "+,CURRENT,PENDING\nHostname:,$name_old,$name\nAddress:,$ipadd_old,$ipadd\nCIDR:,$cidr_old,$cidr" | column -s, -t
@ -67,21 +67,12 @@ sed -i "s/${name_old}/${name}/g" /etc/zabbix/zabbix_agentd.conf && printf "DONE\
# Update IP address # Update IP address
printf "Update IP address... " printf "Update IP address... "
if $(grep 'SUSE' /etc/os-release 2>&1 >/dev/null); then if $(uname -r | grep -E 'el8' &>/dev/null); then
printf "OpenSuSE... "
nmcli con mod ens18 ipv4.addresses $cidr && printf "DONE\n" || exit 1
elif $(uname -r | grep 'arch' 2>&1 >/dev/null); then
printf "Arch Linux... "
sed -i "s_${cidr_old}_${cidr}_g" /etc/netctl/ens18 && printf "DONE\n" || exit 1
elif $(grep -i 'arch' /etc/os-release 2>&1 >/dev/null); then
printf "Arch Linux (alternative kernel)... "
sed -i "s_${cidr_old}_${cidr}_g" /etc/netctl/ens18 && printf "DONE\n" || exit 1
elif $(uname -r | grep -E 'el8' 2>&1 >/dev/null); then
printf "CentOS 8... " printf "CentOS 8... "
nmcli con mod ens18 ipv4.addresses $cidr && printf "DONE\n" || exit 1 nmcli con mod ens18 ipv4.addresses $cidr && printf "DONE\n" || exit 1
elif $(grep 'ubuntu' /etc/os-release 2>&1 >/dev/null); then elif $(uname -r | grep 'arch' &>/dev/null); then
printf "Ubuntu... " printf "Arch Linux... "
sed -i "s_${cidr_old}_${cidr}_g" /etc/netplan/00-installer-config.yaml && printf "DONE\n" || exit 1 sed -i "s_${cidr_old}_${cidr}_g" /etc/netctl/ens18 && printf "DONE\n" || exit 1
else else
printf "FAIL\n\nOS distribution not supported! Update IP address manually before rebooting!\n\n" printf "FAIL\n\nOS distribution not supported! Update IP address manually before rebooting!\n\n"
fi fi

Loading…
Cancel
Save