Merge pull request 'ubuntu-and-bash' (#8) from ubuntu-and-bash into master

Reviewed-on: http://git.skyfall.tech/skyfall/internal-scripts/pulls/8
Reviewed-by: theissenm <matt@skyfalltech.com>
pull/10/head
theissenm 3 years ago
commit 097c96f809

@ -1,4 +1,4 @@
#!/usr/bin/env sh #!/usr/bin/env bash
#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.
@ -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$" &>/dev/null; then if ! echo $cidr | grep -E "^$n(\.$n){3}/$m$" 2>&1 >/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 &>/dev/null && ipc_present=true which ipcalc 2>&1 >/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,18 +67,21 @@ 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 &>/dev/null); then if $(grep 'SUSE' /etc/os-release 2>&1 >/dev/null); then
printf "OpenSuSE... " printf "OpenSuSE... "
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 $(uname -r | grep 'arch' &>/dev/null); then elif $(uname -r | grep 'arch' 2>&1 >/dev/null); then
printf "Arch Linux... " printf "Arch Linux... "
sed -i "s_${cidr_old}_${cidr}_g" /etc/netctl/ens18 && printf "DONE\n" || exit 1 sed -i "s_${cidr_old}_${cidr}_g" /etc/netctl/ens18 && printf "DONE\n" || exit 1
elif $(grep -i 'arch' /etc/os-release &>/dev/null); then elif $(grep -i 'arch' /etc/os-release 2>&1 >/dev/null); then
printf "Arch Linux (alternative kernel)... " printf "Arch Linux (alternative kernel)... "
sed -i "s_${cidr_old}_${cidr}_g" /etc/netctl/ens18 && printf "DONE\n" || exit 1 sed -i "s_${cidr_old}_${cidr}_g" /etc/netctl/ens18 && printf "DONE\n" || exit 1
elif $(uname -r | grep -E 'el8' &>/dev/null); then 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
printf "Ubuntu... "
sed -i "s_${cidr_old}_${cidr}_g" /etc/netplan/00-installer-config.yaml && 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