1
0
Fork 0
mirror of https://github.com/iiab/iiab.git synced 2025-03-09 15:40:17 +00:00

Verifies CLI flags & /etc/iiab/iiab.env input. Explanatory output enhanced.

This commit is contained in:
A Holt 2017-11-10 03:06:43 -05:00 committed by GitHub
parent 17e0896547
commit 2410f7eeba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,6 +2,15 @@
# running from a git repo # running from a git repo
# Add cmdline options for passing to ansible # Add cmdline options for passing to ansible
# todo add proper shift to gobble up --debug --reinstall # todo add proper shift to gobble up --debug --reinstall
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."
exit 1
fi
PLAYBOOK="iiab-stages.yml" PLAYBOOK="iiab-stages.yml"
INVENTORY="ansible_hosts" INVENTORY="ansible_hosts"
ARGS="" ARGS=""
@ -14,7 +23,7 @@ MIN_ANSIBLE_VER=2.4.1.0
export ANSIBLE_LOG_PATH="$CWD/iiab-install.log" export ANSIBLE_LOG_PATH="$CWD/iiab-install.log"
if [ ! -f $PLAYBOOK ]; then if [ ! -f $PLAYBOOK ]; then
echo "Exiting: IIAB Playbook not found." echo "EXITING: IIAB Playbook not found."
echo "Please run 'iiab-install' from /opt/iiab/iiab (top level of git repo)." echo "Please run 'iiab-install' from /opt/iiab/iiab (top level of git repo)."
exit 1 exit 1
fi fi
@ -28,10 +37,10 @@ function version_gt() { [ "$(printf '%s\n' "$@" | sort -V | head -1)" != "$1" ];
# updates on 4.9.41-v7+ broke bridging, WiFi AP & OpenVPN in Oct/Nov 2017. # updates on 4.9.41-v7+ broke bridging, WiFi AP & OpenVPN in Oct/Nov 2017.
CURR_KERN=`uname -r` CURR_KERN=`uname -r`
echo "Found Kernel "$CURR_KERN"" echo "Found Kernel "$CURR_KERN""
if [ $OS == "raspbian" ] && version_gt $MIN_RPI_KERN $CURR_KERN; then if [ "$OS" == "raspbian" ] && version_gt $MIN_RPI_KERN $CURR_KERN; then
echo "Kernel "$MIN_RPI_KERN" or higher required with Raspbian." 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 "PLEASE RUN 'apt update' then 'apt install raspberrypi-kernel' then reboot."
echo "INSTALL INSTRUCTIONS: https://github.com/iiab/iiab/wiki/IIAB-Installation" echo "IIAB INSTALL INSTRUCTIONS: https://github.com/iiab/iiab/wiki/IIAB-Installation"
exit 1 exit 1
fi fi
@ -43,11 +52,11 @@ if [[ `type -P ansible` ]]; then
echo "Found Ansible "$CURR_ANSIBLE_VER"" echo "Found Ansible "$CURR_ANSIBLE_VER""
fi fi
if version_gt $MIN_ANSIBLE_VER $CURR_ANSIBLE_VER; then if version_gt $MIN_ANSIBLE_VER $CURR_ANSIBLE_VER; then
echo "IIAB requires Ansible "$MIN_ANSIBLE_VER" or higher. Prior versions can often" echo -e "\nEXITING: Ansible "$MIN_ANSIBLE_VER" or higher required."
echo "be removed with 'apt purge ansible' or 'pip uninstall ansible'. We recommend" echo "PLEASE RUN './scripts/ansible' to install the latest Ansible from PPA or RPM."
echo "you 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 "'apt -a list ansible' can also sometimes be useful to show options!" echo "to remove prior versions with 'apt purge ansible' or 'pip uninstall ansible'."
echo "INSTALL INSTRUCTIONS: https://github.com/iiab/iiab/wiki/IIAB-Installation" echo "IIAB INSTALL INSTRUCTIONS: https://github.com/iiab/iiab/wiki/IIAB-Installation"
exit 1 exit 1
fi fi
@ -55,6 +64,7 @@ if [ ! -f /etc/ansible/facts.d/local_facts.fact ]; then
mkdir -p /etc/ansible/facts.d mkdir -p /etc/ansible/facts.d
fi fi
cp ./scripts/local_facts.fact /etc/ansible/facts.d/local_facts.fact cp ./scripts/local_facts.fact /etc/ansible/facts.d/local_facts.fact
echo "Placed /etc/ansible/facts.d/local_facts.fact into position."
# Stage 0 will always be run. From there on up to Stage 9 we keep a counter # 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! # (in /etc/iiab/iiab.env) of the highest completed Stage. Avoid repetition!
@ -62,38 +72,48 @@ STAGE=0
if [ ! -f /etc/iiab/iiab.env ]; then if [ ! -f /etc/iiab/iiab.env ]; then
mkdir -p /etc/iiab mkdir -p /etc/iiab
else else
if [[ `grep XSCE /etc/iiab/iiab.env` ]] || [ "$1" == "--reinstall" ]; 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
elif [[ `grep XSCE /etc/iiab/iiab.env` ]] || [ "$1" == "--reinstall" ]; then
STAGE=0
rm /etc/iiab/iiab.env rm /etc/iiab/iiab.env
echo "Removed /etc/iiab/iiab.env" echo "Removed /etc/iiab/iiab.env effectively resetting STAGE (counter)."
else elif [ "$STAGE" -ge 2 ] && [ "$1" == "--debug" ]; then
if [ "$1" == "--debug" ]; then STAGE=2
sed -i 's/^STAGE=.*/STAGE=2/' /etc/iiab/iiab.env sed -i 's/^STAGE=.*/STAGE=2/' /etc/iiab/iiab.env
echo "Wrote STAGE=2 to /etc/iiab/iiab.env" echo "Wrote STAGE=2 (counter) to /etc/iiab/iiab.env"
fi elif [ "$STAGE" -eq 9 ]; then
source /etc/iiab/iiab.env echo -e "\nEXITING: STAGE (counter) in /etc/iiab/iiab.env shows Stage 9 Is Already Done."
echo "Extracted STAGE counter from /etc/iiab/iiab.env" echo "Use 'iiab-install --reinstall' to force running all Stages 0-9."
if [ $STAGE == 9 ]; then echo "Use 'iiab-install --debug' to run Stage 0, followed by Stages 3-9."
echo "Exiting: 'iiab-install' already completed, according to /etc/iiab/iiab.env" echo "Use './runtags' to run a single Stage or Tag or Role."
echo "Use 'iiab-install --reinstall' to run all Stages 0-9." exit 1
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
fi fi
if [ "$STAGE" -lt 2 ] && [ "$1" == "--debug" ]; then
echo -e "\n'--debug' *ignored* as STAGE (counter) < 2."
fi
# If vars/local_vars.yml is missing, put a default one in place. # If vars/local_vars.yml is missing, put a default file in place.
# See MIN/MEDIUM/BIG options @ http://wiki.iiab.io/local_vars.yml
if [ ! -f ./vars/local_vars.yml ]; then if [ ! -f ./vars/local_vars.yml ]; then
case $OS in case $OS in
OLPC | fedora) OLPC | fedora)
cp ./vars/olpc.localvars ./vars/local_vars.yml cp ./vars/olpc.localvars ./vars/local_vars.yml
echo -e "\nvars/local_vars.yml created from olpc.localvars defaults."
;; ;;
centos | debian | ubuntu | raspbian) centos | debian | ubuntu | raspbian)
cp ./vars/medium.localvars ./vars/local_vars.yml cp ./vars/medium.localvars ./vars/local_vars.yml
echo -e "\nvars/local_vars.yml created from medium.localvars defaults."
echo "See MIN/MEDIUM/BIG options @ http://wiki.iiab.io/local_vars.yml"
;; ;;
*) *)
echo "Exiting: IIAB requires Raspbian, Debian, Ubuntu, CentOS or OLPC/Fedora." echo -e "\nEXITING: IIAB requires Raspbian, Debian, Ubuntu, CentOS or OLPC/Fedora."
exit 1 exit 1
;; ;;
esac esac