2017-06-09 23:25:56 +00:00
#!/bin/bash
2017-10-30 17:57:55 +00:00
# running from a git repo
# ansible files exist
2017-10-24 16:39:49 +00:00
CWD=`pwd`
2017-10-30 17:57:55 +00:00
export ANSIBLE_LOG_PATH="$CWD/iiab-network.log"
2017-10-24 16:39:49 +00:00
2017-12-05 15:33:35 +00:00
if [ ! -f iiab-network.yml ]; then
2017-12-12 06:17:12 +00:00
echo "iiab-network.yml not found in current directory."
echo "Please rerun this command from the top level of the git repo."
2017-12-05 15:33:35 +00:00
echo "Exiting."
exit 1
2017-06-09 23:25:56 +00:00
fi
2017-12-07 23:56:22 +00:00
OS="unknown" # will be overridden below, if /etc/iiab/iiab.env is legit
2017-12-05 15:33:35 +00:00
if [ -f /etc/iiab/iiab.env ]; then
2018-04-09 00:57:49 +00:00
echo "Reading /etc/iiab/iiab.env"
2020-03-11 20:10:37 +00:00
STAGE=0
2020-03-17 03:43:47 +00:00
source /etc/iiab/iiab.env
2020-03-11 20:10:37 +00:00
if grep -q STAGE= /etc/iiab/iiab.env ; then
echo -e "\nExtracted STAGE=$STAGE (counter) from /etc/iiab/iiab.env"
if ! [ "$STAGE" -eq "$STAGE" ] 2> /dev/null; then
echo -e "\nEXITING: STAGE (counter) value == ""$STAGE"" is non-integer"
exit 1
elif [ "$STAGE" -lt 0 ] || [ "$STAGE" -gt 9 ]; then
echo -e "\nEXITING: STAGE (counter) value == ""$STAGE"" is out-of-range"
exit 1
elif [ "$STAGE" -lt 3 ]; then
echo -e "\nEXITING: STAGE (counter) value == ""$STAGE"
echo -e "\nIIAB Stage 3 not complete."
echo -e "\nPlease run: ./iiab-install"
exit 1
2020-03-17 03:43:47 +00:00
fi
2020-03-11 20:10:37 +00:00
else
echo -e "\nEXITING: STAGE (counter) not found"
echo -e "\nIIAB not installed."
echo -e "\nPlease run: ./iiab-install"
exit 1
fi
else
echo -e "\nEXITING: /etc/iiab/iiab.env not found"
exit 1
2017-06-09 23:25:56 +00:00
fi
2018-04-09 00:57:49 +00:00
echo "Ansible will now run iiab-network.yml -- log file is iiab-network.log"
2017-09-13 11:07:25 +00:00
Start=`date`
2019-10-31 02:38:06 +00:00
ansible -m setup -i ansible_hosts localhost --connection=local | grep python
ansible-playbook -i ansible_hosts iiab-network.yml --connection=local
2017-09-15 16:56:57 +00:00
End=`date`
2017-12-07 23:48:35 +00:00
2017-12-13 08:56:22 +00:00
2017-12-07 23:56:22 +00:00
# Record critical diagnostics to [/opt/iiab/iiab/]iiab-network.log
2017-12-29 07:25:06 +00:00
echo >> iiab-network.log
2017-12-13 08:56:22 +00:00
2017-12-05 15:33:35 +00:00
# redhat path
2017-12-13 08:56:22 +00:00
# Paul Armstrong's Shell Style Guide (https://google.github.io/styleguide/shell.xml)
# prefers "if [[ ... ]]; then" for REGEXP's. Many others prefer "if [ ... ];" then.
# Each approach is sometimes necessary in my experience, working differently indeed.
2017-12-13 08:15:39 +00:00
if [ "$OS" == "centos" ] || [ "$OS" == "fedora" ]; then
2017-12-07 23:48:35 +00:00
ls -la /etc/sys*/net*/ifcfg* >> iiab-network.log
2017-12-05 15:33:35 +00:00
fi
2017-12-13 07:57:26 +00:00
2017-12-13 08:56:22 +00:00
# Ubuntu desktop/others might be using NM (NetworkManager) - split out.
2017-12-13 11:34:12 +00:00
#if [ $(grep ubuntu /etc/apt/sources.list) ]; then # FAILS when multiple lines returned, due to single square brackets
#if grep -q ubuntu /etc/apt/sources.list ; then # Works: bypasses need for "> /dev/null" thanks to "grep -q" (quiet)
#if command -v nmcli > /dev/null ; then # Works But Wordy!
#if [[ $(command -v nmcli) ]]; then # Also Works! $(...) nests more easily than backticks
#if [[ `which nmcli` ]]; then # "which" misses built-in commands like cd, and is RISKY per https://stackoverflow.com/questions/592620/check-if-a-program-exists-from-a-bash-script
#if [[ `type -P nmcli` ]]; then # "type -P" isn't POSIX compliant; it misses built-in commands like "cd"
if [[ `command -v nmcli` ]]; then # "command -v" is POSIX compliant; it catches built-in commands like "cd"
2017-12-07 23:48:35 +00:00
nmcli d >> iiab-network.log
2017-12-13 12:19:44 +00:00
echo >> iiab-network.log
2017-12-07 23:48:35 +00:00
nmcli c >> iiab-network.log
2017-06-09 23:25:56 +00:00
fi
2017-12-13 08:56:22 +00:00
2017-09-15 16:56:57 +00:00
ip r >> iiab-network.log
2021-04-26 21:44:09 +00:00
bridge -d link >> iiab-network.log
2017-12-13 12:19:44 +00:00
echo >> iiab-network.log
2017-12-13 12:25:23 +00:00
echo "iiab-network run start: $Start" >> iiab-network.log
echo "iiab-network run end: $End" >> iiab-network.log
2017-12-13 12:19:44 +00:00
echo >> iiab-network.log
echo >> iiab-network.log
2017-12-07 23:48:35 +00:00
2017-12-13 08:56:22 +00:00
2017-12-07 23:56:22 +00:00
# Put the same diagnostics on screen, for live operator
2017-12-13 11:36:29 +00:00
if [[ `command -v nmcli` ]]; then
2017-12-13 08:56:22 +00:00
nmcli d
2017-12-13 12:19:44 +00:00
echo
2017-12-13 08:56:22 +00:00
nmcli c
fi
2017-09-15 16:56:57 +00:00
ip r
2021-04-26 21:44:09 +00:00
bridge -d link
2017-12-13 12:19:44 +00:00
echo
2017-12-13 12:25:23 +00:00
echo "iiab-network run start: $Start"
echo "iiab-network run end: $End"
2020-10-08 01:08:58 +00:00
echo
2020-10-08 02:57:38 +00:00
echo "Please REBOOT to fully verify your network -- graphical desktops MUST reboot!"
2022-07-14 05:55:11 +00:00
exit 0