Compare commits

...

15 Commits

Author SHA1 Message Date
Aaron Johnson aa2ad37d3a Merge pull request 'Exception not needed anymore' (#10) from remove302exception into master
2 years ago
Aaron Johnon c43c5f4183 Exception not needed anymore
2 years ago
Aaron Johnson 2f48382db0 Merge pull request 'added exception for 302 response codes to prevent false positives' (#9) from 302exception into master
2 years ago
Aaron Johnon 2f7e955b29 added exception for 302 response codes to prevent false positives
2 years ago
theissenm 097c96f809 Merge pull request 'ubuntu-and-bash' (#8) from ubuntu-and-bash into master
3 years ago
Aaron Johnon 65168fda38 Swapped Ubuntu's awk for sed like the others
3 years ago
Aaron Johnon 2052130745 Set script to run in BASH environment
3 years ago
Aaron Johnon 5d6eaff1da Fixed regex to function equally in newer versions of ipcalc
3 years ago
Aaron Johnon b1fc0fc340 Removed &> BASHism, set script to use BASH
3 years ago
theissenm dfd9797aa6 Merge pull request 'Simplification of Kniod subnet filtering' (#6) from kniod-subnet into master
3 years ago
Aaron Johnon 271485e170 Simplification of Kniod subnet filtering
3 years ago
Aaron Johnson dadefd9560 Merge pull request 'Added the Kniod subnet to the network portion.' (#5) from kniod-subnet into master
3 years ago
Matt Theissen 79647bd226 Added the Kniod subnet to the network portion.
3 years ago
theissenm ff3d1190c6 Merge pull request 'Added support for SuSE' (#4) from suse_prov into master
4 years ago
Aaron Johnon 6f02c993b3 Added support for SuSE
4 years ago

@ -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

Loading…
Cancel
Save