|
|
|
@ -1,11 +1,11 @@
|
|
|
|
|
#!/usr/bin/env sh
|
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
#Author: Aaron Johnson
|
|
|
|
|
#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)
|
|
|
|
|
#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)
|
|
|
|
|
cidr_old=$(ip a | 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]')
|
|
|
|
|
ipadd_old=$(echo $cidr_old | awk -F '/' '{print $1}')
|
|
|
|
|
ipc_present=false
|
|
|
|
|
|
|
|
|
@ -23,21 +23,21 @@ fi
|
|
|
|
|
## Validate CIDR
|
|
|
|
|
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])'
|
|
|
|
|
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"
|
|
|
|
|
exit 12
|
|
|
|
|
fi
|
|
|
|
|
# End input sanity check
|
|
|
|
|
|
|
|
|
|
# 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}')
|
|
|
|
|
echo
|
|
|
|
|
printf "Review these changes carefully!\n\n"
|
|
|
|
|
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")
|
|
|
|
|
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
|
|
|
|
@ -67,15 +67,21 @@ sed -i "s/${name_old}/${name}/g" /etc/zabbix/zabbix_agentd.conf && printf "DONE\
|
|
|
|
|
|
|
|
|
|
# Update IP address
|
|
|
|
|
printf "Update IP address... "
|
|
|
|
|
if $(uname -r | grep -E 'el8' &>/dev/null); then
|
|
|
|
|
printf "CentOS 8... "
|
|
|
|
|
if $(grep 'SUSE' /etc/os-release 2>&1 >/dev/null); then
|
|
|
|
|
printf "OpenSuSE... "
|
|
|
|
|
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... "
|
|
|
|
|
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)... "
|
|
|
|
|
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... "
|
|
|
|
|
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
|
|
|
|
|
printf "FAIL\n\nOS distribution not supported! Update IP address manually before rebooting!\n\n"
|
|
|
|
|
fi
|
|
|
|
|