#!/bin/bash -e # running from a git repo # Add cmdline options for passing to ansible # todo add proper shift to gobble up --debug --reinstall PLAYBOOK="iiab-stages.yml" INVENTORY="ansible_hosts" ARGS="" CWD=`pwd` OS=`grep ^ID= /etc/*release|cut -d= -f2` OS=${OS//\"/} MIN_RPI_KERN=4.9.59-v7+ MIN_ANSIBLE_VER=2.4.1.0 export ANSIBLE_LOG_PATH="$CWD/iiab-install.log" if [ ! -f $PLAYBOOK ]; then echo "Exiting: IIAB Playbook not found." echo "Please run 'iiab-install' from /opt/iiab/iiab (top level of git repo)." exit 1 fi # 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/ # 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"" if [ $OS == "raspbian" ] && version_gt $MIN_RPI_KERN $CURR_KERN; then echo "Kernel "$MIN_RPI_KERN" or higher required with Raspbian." echo "Please run 'apt update' then 'apt install raspberrypi-kernel' then reboot." echo "INSTALL INSTRUCTIONS: https://github.com/iiab/iiab/wiki/IIAB-Installation" exit 1 fi # Verify that a recent enough version of Ansible is installed. See #449. The # "include:" command was inconsistently implemented prior to Ansible 2.4.x.x CURR_ANSIBLE_VER=0 if [[ `type -P ansible` ]]; then CURR_ANSIBLE_VER=`ansible --version | head -1 | sed -e 's/.* //'` echo "Found Ansible "$CURR_ANSIBLE_VER"" fi if version_gt $MIN_ANSIBLE_VER $CURR_ANSIBLE_VER; then echo "IIAB requires Ansible "$MIN_ANSIBLE_VER" or higher. Prior versions can often" echo "be removed with 'apt purge ansible' or 'pip uninstall ansible'. We recommend" echo "you run './scripts/ansible' to install the latest Ansible from PPA or RPM." echo "'apt -a list ansible' can also sometimes be useful to show options!" echo "INSTALL INSTRUCTIONS: https://github.com/iiab/iiab/wiki/IIAB-Installation" exit 1 fi 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 # 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 if [ ! -f /etc/iiab/iiab.env ]; then mkdir -p /etc/iiab else if [[ `grep XSCE /etc/iiab/iiab.env` ]] || [ "$1" == "--reinstall" ]; then rm /etc/iiab/iiab.env echo "Removed /etc/iiab/iiab.env" else if [ "$1" == "--debug" ]; then sed -i 's/^STAGE=.*/STAGE=2/' /etc/iiab/iiab.env echo "Wrote STAGE=2 to /etc/iiab/iiab.env" fi source /etc/iiab/iiab.env echo "Extracted STAGE counter from /etc/iiab/iiab.env" if [ $STAGE == 9 ]; then echo "Exiting: 'iiab-install' already completed, according to /etc/iiab/iiab.env" echo "Use 'iiab-install --reinstall' to run 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." exit 1 fi fi fi # If vars/local_vars.yml is missing, put a default one in place. # See MIN/MEDIUM/BIG options @ http://wiki.iiab.io/local_vars.yml if [ ! -f ./vars/local_vars.yml ]; then case $OS in OLPC | fedora) cp ./vars/olpc.localvars ./vars/local_vars.yml ;; centos | debian | ubuntu | raspbian) cp ./vars/medium.localvars ./vars/local_vars.yml ;; *) echo "Exiting: IIAB requires Raspbian, Debian, Ubuntu, CentOS or OLPC/Fedora." exit 1 ;; esac fi 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" ansible -m setup -i $INVENTORY localhost --connection=local >> /dev/null ansible-playbook -i $INVENTORY $PLAYBOOK ${ARGS} --connection=local