2017-10-30 18:05:19 +00:00
|
|
|
#!/bin/bash -e
|
2017-11-10 10:09:07 +00:00
|
|
|
# Running from a git repo
|
2017-10-30 18:05:19 +00:00
|
|
|
# Add cmdline options for passing to ansible
|
2017-11-10 10:09:07 +00:00
|
|
|
# Todo add proper shift to gobble up --debug --reinstall
|
2017-11-10 08:06:43 +00:00
|
|
|
|
2017-11-05 04:33:15 +00:00
|
|
|
PLAYBOOK="iiab-stages.yml"
|
|
|
|
INVENTORY="ansible_hosts"
|
2017-11-10 01:59:17 +00:00
|
|
|
ARGS=""
|
2017-11-05 04:33:15 +00:00
|
|
|
CWD=`pwd`
|
|
|
|
OS=`grep ^ID= /etc/*release|cut -d= -f2`
|
|
|
|
OS=${OS//\"/}
|
2017-11-10 01:59:17 +00:00
|
|
|
MIN_RPI_KERN=4.9.59-v7+
|
|
|
|
MIN_ANSIBLE_VER=2.4.1.0
|
2017-11-08 07:53:54 +00:00
|
|
|
|
2017-10-30 18:05:19 +00:00
|
|
|
export ANSIBLE_LOG_PATH="$CWD/iiab-install.log"
|
|
|
|
|
2017-11-19 03:29:45 +00:00
|
|
|
if [ ! -f /etc/ansible/facts.d/local_facts.fact ]; then
|
|
|
|
mkdir -p /etc/ansible/facts.d
|
|
|
|
fi
|
|
|
|
cp ./scripts/local_facts.fact /etc/ansible/facts.d/local_facts.fact
|
|
|
|
echo "Placed /etc/ansible/facts.d/local_facts.fact into position."
|
|
|
|
|
2017-11-05 04:41:41 +00:00
|
|
|
if [ ! -f $PLAYBOOK ]; then
|
2017-11-10 08:06:43 +00:00
|
|
|
echo "EXITING: IIAB Playbook not found."
|
2017-11-09 21:52:24 +00:00
|
|
|
echo "Please run 'iiab-install' from /opt/iiab/iiab (top level of git repo)."
|
2017-11-05 04:41:41 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-11-19 03:29:45 +00:00
|
|
|
if [ "$1" != "--debug" ] && [ "$1" != "--reinstall" ] && [ "$1" != "" ]; then
|
|
|
|
echo "Use './iiab-install' for regular installs, or to continue an install."
|
|
|
|
echo "Use './iiab-install --reinstall' to force running all Stages 0-9."
|
|
|
|
echo "Use './iiab-install --debug' to run Stage 0, followed by Stages 3-9."
|
|
|
|
echo "Use './runtags' to run a single Stage or Tag or Role."
|
|
|
|
echo "Use './iiab-network' to run Network sections."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-11-10 02:19:38 +00:00
|
|
|
# Subroutine compares software version numbers. Generates rare false positives
|
|
|
|
# like "1.0 > 1" and "2.4.0 > 2.4". Avoid risks by structuring conditionals w/
|
2017-11-10 01:59:17 +00:00
|
|
|
# a consistent # of decimal points e.g. "if version_gt w.x.y.z a.b.c.d; then"
|
|
|
|
function version_gt() { [ "$(printf '%s\n' "$@" | sort -V | head -1)" != "$1" ]; }
|
|
|
|
|
|
|
|
# Verify that Raspbian is running a recent enough kernel. As Raspbian
|
|
|
|
# updates on 4.9.41-v7+ broke bridging, WiFi AP & OpenVPN in Oct/Nov 2017.
|
|
|
|
CURR_KERN=`uname -r`
|
|
|
|
echo "Found Kernel "$CURR_KERN""
|
2017-11-10 08:06:43 +00:00
|
|
|
if [ "$OS" == "raspbian" ] && version_gt $MIN_RPI_KERN $CURR_KERN; then
|
|
|
|
echo -e "\nEXITING: Kernel "$MIN_RPI_KERN" or higher required with Raspbian."
|
|
|
|
echo "PLEASE RUN 'apt update' then 'apt install raspberrypi-kernel' then reboot."
|
|
|
|
echo "IIAB INSTALL INSTRUCTIONS: https://github.com/iiab/iiab/wiki/IIAB-Installation"
|
2017-11-10 01:59:17 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-11-10 02:19:38 +00:00
|
|
|
# Verify that a recent enough version of Ansible is installed. See #449. The
|
2017-11-10 01:59:17 +00:00
|
|
|
# "include:" command was inconsistently implemented prior to Ansible 2.4.x.x
|
2017-11-10 02:30:48 +00:00
|
|
|
CURR_ANSIBLE_VER=0
|
2017-11-10 01:59:17 +00:00
|
|
|
if [[ `type -P ansible` ]]; then
|
2017-11-10 02:30:48 +00:00
|
|
|
CURR_ANSIBLE_VER=`ansible --version | head -1 | sed -e 's/.* //'`
|
|
|
|
echo "Found Ansible "$CURR_ANSIBLE_VER""
|
2017-11-10 01:59:17 +00:00
|
|
|
fi
|
2017-11-10 02:30:48 +00:00
|
|
|
if version_gt $MIN_ANSIBLE_VER $CURR_ANSIBLE_VER; then
|
2017-11-10 08:06:43 +00:00
|
|
|
echo -e "\nEXITING: Ansible "$MIN_ANSIBLE_VER" or higher required."
|
|
|
|
echo "PLEASE RUN './scripts/ansible' to install the latest Ansible from PPA or RPM."
|
|
|
|
echo "'ansible --version' and 'apt -a list ansible' can also be useful here. Try"
|
|
|
|
echo "to remove prior versions with 'apt purge ansible' or 'pip uninstall ansible'."
|
|
|
|
echo "IIAB INSTALL INSTRUCTIONS: https://github.com/iiab/iiab/wiki/IIAB-Installation"
|
2017-11-10 01:59:17 +00:00
|
|
|
exit 1
|
2017-11-05 04:33:15 +00:00
|
|
|
fi
|
|
|
|
|
2017-11-10 01:59:17 +00:00
|
|
|
# Stage 0 will always be run. From there on up to Stage 9 we keep a counter
|
|
|
|
# (in /etc/iiab/iiab.env) of the highest completed Stage. Avoid repetition!
|
|
|
|
STAGE=0
|
2017-10-30 20:02:23 +00:00
|
|
|
if [ ! -f /etc/iiab/iiab.env ]; then
|
|
|
|
mkdir -p /etc/iiab
|
2017-11-12 01:12:43 +00:00
|
|
|
echo "Ran 'mkdir -p /etc/iiab'"
|
|
|
|
# ./runtags and Admin Console currently require /etc/iiab/config_vars.yml (in future they may be self-sufficient?)
|
|
|
|
if [ ! -f /etc/iiab/config_vars.yml ]; then
|
|
|
|
echo "{}" > /etc/iiab/config_vars.yml
|
|
|
|
echo "Created stub /etc/iiab/config_vars.yml"
|
|
|
|
fi
|
2017-10-30 20:02:23 +00:00
|
|
|
else
|
2017-11-10 10:09:07 +00:00
|
|
|
if [[ `grep STAGE= /etc/iiab/iiab.env` ]]; then
|
|
|
|
source /etc/iiab/iiab.env
|
|
|
|
echo "Extracted 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 in /etc/iiab/iiab.env"
|
|
|
|
exit 1
|
|
|
|
elif [ "$STAGE" -lt 1 ] || [ "$STAGE" -gt 9 ]; then
|
|
|
|
echo -e "\nEXITING: STAGE (counter) value == "$STAGE" is out-of-range in /etc/iiab/iiab.env"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if [[ `grep XSCE /etc/iiab/iiab.env` ]] || [ "$1" == "--reinstall" ]; then
|
2017-11-10 08:06:43 +00:00
|
|
|
STAGE=0
|
2017-10-30 18:05:19 +00:00
|
|
|
rm /etc/iiab/iiab.env
|
2017-11-10 08:06:43 +00:00
|
|
|
echo "Removed /etc/iiab/iiab.env effectively resetting STAGE (counter)."
|
|
|
|
elif [ "$STAGE" -ge 2 ] && [ "$1" == "--debug" ]; then
|
|
|
|
STAGE=2
|
|
|
|
sed -i 's/^STAGE=.*/STAGE=2/' /etc/iiab/iiab.env
|
|
|
|
echo "Wrote STAGE=2 (counter) to /etc/iiab/iiab.env"
|
|
|
|
elif [ "$STAGE" -eq 9 ]; then
|
|
|
|
echo -e "\nEXITING: STAGE (counter) in /etc/iiab/iiab.env shows Stage 9 Is Already Done."
|
2017-11-10 10:09:07 +00:00
|
|
|
echo "Use './iiab-install --reinstall' to force running all Stages 0-9."
|
|
|
|
echo "Use './iiab-install --debug' to run Stage 0, followed by Stages 3-9."
|
2017-11-10 08:06:43 +00:00
|
|
|
echo "Use './runtags' to run a single Stage or Tag or Role."
|
2017-11-10 10:09:07 +00:00
|
|
|
echo "Use './iiab-network' to run Network sections."
|
2017-11-10 08:06:43 +00:00
|
|
|
exit 1
|
2017-10-30 18:05:19 +00:00
|
|
|
fi
|
|
|
|
fi
|
2017-11-10 08:06:43 +00:00
|
|
|
if [ "$STAGE" -lt 2 ] && [ "$1" == "--debug" ]; then
|
|
|
|
echo -e "\n'--debug' *ignored* as STAGE (counter) < 2."
|
|
|
|
fi
|
2017-10-30 18:05:19 +00:00
|
|
|
|
2017-11-10 08:06:43 +00:00
|
|
|
# If vars/local_vars.yml is missing, put a default file in place.
|
2017-10-30 18:05:19 +00:00
|
|
|
if [ ! -f ./vars/local_vars.yml ]; then
|
|
|
|
case $OS in
|
|
|
|
OLPC | fedora)
|
2017-11-05 16:03:17 +00:00
|
|
|
cp ./vars/olpc.localvars ./vars/local_vars.yml
|
2017-11-10 08:06:43 +00:00
|
|
|
echo -e "\nvars/local_vars.yml created from olpc.localvars defaults."
|
2017-11-05 16:03:17 +00:00
|
|
|
;;
|
2017-10-30 18:05:19 +00:00
|
|
|
centos | debian | ubuntu | raspbian)
|
2017-11-05 16:03:17 +00:00
|
|
|
cp ./vars/medium.localvars ./vars/local_vars.yml
|
2017-11-10 08:06:43 +00:00
|
|
|
echo -e "\nvars/local_vars.yml created from medium.localvars defaults."
|
|
|
|
echo "See MIN/MEDIUM/BIG options @ http://wiki.iiab.io/local_vars.yml"
|
2017-11-05 16:03:17 +00:00
|
|
|
;;
|
2017-10-30 18:05:19 +00:00
|
|
|
*)
|
2017-11-10 08:06:43 +00:00
|
|
|
echo -e "\nEXITING: IIAB requires Raspbian, Debian, Ubuntu, CentOS or OLPC/Fedora."
|
2017-11-05 16:03:17 +00:00
|
|
|
exit 1
|
|
|
|
;;
|
2017-10-30 18:05:19 +00:00
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
2017-11-10 01:59:17 +00:00
|
|
|
echo -e "\nTRY TO RERUN './iiab-install' IF IT FAILS DUE TO CONNECTIVITY ISSUES ETC!"
|
|
|
|
echo -e "\nRunning local playbooks....Stage 0 will now run....followed by Stages $(($STAGE + 1))-9"
|
|
|
|
|
2017-10-30 18:05:19 +00:00
|
|
|
ansible -m setup -i $INVENTORY localhost --connection=local >> /dev/null
|
|
|
|
ansible-playbook -i $INVENTORY $PLAYBOOK ${ARGS} --connection=local
|