mirror of
https://github.com/iiab/iiab.git
synced 2025-02-13 11:42:08 +00:00
Merge pull request #509 from holta/master
iiab-install: checks Ansible version & explains what it's doing
This commit is contained in:
commit
47e69c55aa
3 changed files with 101 additions and 60 deletions
129
iiab-install
129
iiab-install
|
@ -1,90 +1,131 @@
|
|||
#!/bin/bash -e
|
||||
# running from a git repo
|
||||
# Running from a git repo
|
||||
# Add cmdline options for passing to ansible
|
||||
# todo add proper shift to gobble up --debug --reinstall
|
||||
ARGS=""
|
||||
OLD_RPI_KERN="4.9.41-v7+"
|
||||
# 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."
|
||||
echo "Use './iiab-network' to run Network sections."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
PLAYBOOK="iiab-stages.yml"
|
||||
INVENTORY="ansible_hosts"
|
||||
ARGS=""
|
||||
CWD=`pwd`
|
||||
OS=`grep ^ID= /etc/*release|cut -d= -f2`
|
||||
OS=${OS//\"/}
|
||||
|
||||
function version_gt() { [ "$(printf '%s\n' "$@" | sort -V | head -1)" != "$1" ]; }
|
||||
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 "IIAB Playbook not found."
|
||||
echo "Please run this command from the top level of the git repo."
|
||||
echo "Exiting."
|
||||
echo "EXITING: IIAB Playbook not found."
|
||||
echo "Please run 'iiab-install' from /opt/iiab/iiab (top level of git repo)."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ $OS == "raspbian" ]; then
|
||||
echo "Found Raspbian"
|
||||
CURRENT_KERN=`uname -r`
|
||||
if version_gt $CURRENT_KERN $OLD_RPI_KERN ; then
|
||||
echo "Kernel looks ok - continuing"
|
||||
else
|
||||
echo "Kernel "$CURRENT_KERN" is too old. Before running './iiab-install' you first need"
|
||||
echo "to update your system with 'apt update' then 'apt dist-upgrade' then reboot."
|
||||
echo "INSTALL INSTRUCTIONS: https://github.com/iiab/iiab/wiki/IIAB-Installation"
|
||||
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 -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"
|
||||
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 -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"
|
||||
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
|
||||
echo "Placed /etc/ansible/facts.d/local_facts.fact into position."
|
||||
|
||||
STAGE=""
|
||||
|
||||
# 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
|
||||
# ./scripts/ansible # needs discussion
|
||||
else
|
||||
OLD=`grep XSCE /etc/iiab/iiab.env | wc -l`
|
||||
if [ "$OLD" != 0 ] || [ "$1" == "--reinstall" ]; then
|
||||
echo "Found old XSCE install - re-installing from scratch"
|
||||
rm /etc/iiab/iiab.env
|
||||
# check ansible version here and force ansible upgrade if needed
|
||||
else
|
||||
if [[ `grep STAGE= /etc/iiab/iiab.env` ]]; then
|
||||
source /etc/iiab/iiab.env
|
||||
if [ "$1" == "--debug" ]; then
|
||||
echo "Entering debug mode"
|
||||
sed -i -e 's/^STAGE=.*/STAGE=2/' /etc/iiab/iiab.env
|
||||
elif [ ! $STAGE == 9 ]; then
|
||||
echo "Restarting *after* STAGE $STAGE..as soon as Stage 0 completes. Stage 9 comes last."
|
||||
elif [ $STAGE == 9 ]; then
|
||||
# place keeper add read response
|
||||
# "offer 'Y' or stage number dialog box option to override"
|
||||
echo "'iiab-install' has already been completed."
|
||||
echo "Use --debug to override."
|
||||
#echo "In demo mode not preventing second run"
|
||||
echo "Exiting."
|
||||
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
|
||||
STAGE=0
|
||||
rm /etc/iiab/iiab.env
|
||||
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."
|
||||
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
|
||||
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 - First Run
|
||||
# If vars/local_vars.yml is missing, put a default file in place.
|
||||
if [ ! -f ./vars/local_vars.yml ]; then
|
||||
case $OS in
|
||||
OLPC | fedora)
|
||||
cp ./vars/olpc.localvars ./vars/local_vars.yml
|
||||
echo -e "\nvars/local_vars.yml created from olpc.localvars defaults."
|
||||
;;
|
||||
centos | debian | ubuntu | raspbian)
|
||||
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 "IIAB supports raspbian, debian, ubuntu, centos, and OLPC - exiting now..."
|
||||
echo -e "\nEXITING: IIAB requires Raspbian, Debian, Ubuntu, CentOS or OLPC/Fedora."
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
echo "Running local playbooks!"
|
||||
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
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
#- name: Loading computed_vars
|
||||
# include_tasks: roles/0-init/tasks/computed_vars.yml
|
||||
- name: re-read local_facts.facts from /etc/ansible/facts.d
|
||||
- name: Re-read local_facts.facts from /etc/ansible/facts.d
|
||||
setup: filter=ansible_local
|
||||
|
||||
# set top level variables from local facts for convenience
|
||||
|
@ -27,7 +27,7 @@
|
|||
iiab_stage: '{{ ansible_local.local_facts.stage }}'
|
||||
|
||||
# Networking uses a different file for the rpi
|
||||
- name: Discover if this is a rpi -- assume if so it is running raspbian
|
||||
- name: Discover if this is a RPi -- if so assume it is running Raspbian
|
||||
set_fact:
|
||||
rpi_model: "rpi"
|
||||
is_rpi: True
|
||||
|
@ -116,12 +116,12 @@
|
|||
docker_enabled: True
|
||||
when: schooltool_enabled or schooltool_install
|
||||
|
||||
- name: Set python_path for is_redhat
|
||||
- name: Set python_path (redhat)
|
||||
set_fact:
|
||||
python_path: /usr/lib/python2.7/site-packages/
|
||||
when: is_redhat
|
||||
|
||||
- name: Set python_path for is_debuntu
|
||||
- name: Set python_path (debuntu)
|
||||
set_fact:
|
||||
python_path: /usr/local/lib/python2.7/dist-packages/
|
||||
when: is_debuntu
|
||||
|
@ -134,14 +134,14 @@
|
|||
set_fact:
|
||||
mysql_service: mariadb
|
||||
|
||||
- name: Set mysqld_service to mysqld for Fedora 18
|
||||
- name: Set mysqld_service to mysqld (etc) for Fedora 18
|
||||
set_fact:
|
||||
mysql_service: mysqld
|
||||
no_NM_reload: True
|
||||
is_F18: True
|
||||
when: ansible_distribution_release == "based on Fedora 18" or ansible_distribution_version == "18"
|
||||
|
||||
- name: Set mysql_service to mysql for Debian
|
||||
- name: Set mysql_service to mysql (debuntu)
|
||||
set_fact:
|
||||
mysql_service: mysql
|
||||
when: is_debuntu
|
||||
|
@ -156,7 +156,7 @@
|
|||
FQDN_changed: True
|
||||
when: iiab_fqdn != ansible_fqdn
|
||||
|
||||
- name: add version section
|
||||
- name: Add version section
|
||||
ini_file: dest='{{ iiab_config_file }}'
|
||||
section=runtime
|
||||
option='{{ item.option }}'
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# Assume we only get here if elgg_install: True
|
||||
# Assume mysql is running
|
||||
|
||||
- name: Download current version from our copy
|
||||
- name: Download current version from our site
|
||||
shell: wget {{ iiab_download_url }}/elgg-{{ elgg_version }}.zip -c -P {{ downloads_dir }}
|
||||
creates={{ downloads_dir }}/elgg-{{ elgg_version }}.zip
|
||||
when: internet_available
|
||||
|
@ -54,7 +54,7 @@
|
|||
- name: Change permissions on engine directory so Apache can write
|
||||
file: path=/opt/elgg/engine/ owner={{ apache_user }} mode=0755 state=directory
|
||||
|
||||
- name: Create an upload directory that Apache can write in or elgg
|
||||
- name: Create an upload directory that Apache can write in or Elgg
|
||||
file: path={{ elgg_upload_path }} state=directory owner={{ apache_user }}
|
||||
|
||||
- name: Change ownership
|
||||
|
@ -83,7 +83,7 @@
|
|||
# tar up a mysqldump of freshly installed database and use it in the install to avoid the startup
|
||||
# form, which worries me a lot. (/var/lib/mysql/elggdb)
|
||||
|
||||
- name: Load elgg database dump
|
||||
- name: Load Elgg database dump
|
||||
mysql_db: name={{ dbname }}
|
||||
state=import
|
||||
target=/tmp/elggdb.sql
|
||||
|
@ -92,26 +92,26 @@
|
|||
- name: Remove database dump after load
|
||||
file: name=/tmp/elggdb.sql state=absent
|
||||
|
||||
- name: Install config file for elgg in Apache
|
||||
- name: Install config file for Elgg in Apache
|
||||
template: src=elgg.conf dest=/etc/{{ apache_config_dir }}/elgg.conf
|
||||
|
||||
- name: Enable Elgg for debuntu (will already be enabled above for Redhat)
|
||||
- name: Enable Elgg for debuntu (will already be enabled above for redhat)
|
||||
file: path=/etc/apache2/sites-enabled/elgg.conf
|
||||
src=/etc/apache2/sites-available/elgg.conf
|
||||
state=link
|
||||
when: elgg_enabled and is_debuntu
|
||||
|
||||
- name: Disable Elgg for debuntu
|
||||
- name: Disable Elgg - remove config file for Elgg in Apache (debuntu)
|
||||
file: path=/etc/apache2/sites-enabled/elgg.conf
|
||||
state=absent
|
||||
when: not elgg_enabled and is_debuntu
|
||||
|
||||
- name: Disable Elgg for Redhat - remove config file for Elgg in Apache
|
||||
- name: Disable Elgg - remove config file for Elgg in Apache (redhat)
|
||||
file: dest=/etc/{{ apache_config_dir }}/elgg.conf
|
||||
state=absent
|
||||
when: not elgg_enabled and is_redhat
|
||||
|
||||
- name: Add Elgg to service list
|
||||
- name: Add 'elgg' to service list
|
||||
ini_file: dest='{{ service_filelist }}'
|
||||
section=elgg
|
||||
option='{{ item.option }}'
|
||||
|
@ -126,5 +126,5 @@
|
|||
- option: enabled
|
||||
value: "{{ elgg_enabled }}"
|
||||
|
||||
- name: Restart apache, so it picks up the new aliases
|
||||
- name: Restart Apache, so it picks up the new aliases
|
||||
service: name={{ apache_service }} state=restarted
|
||||
|
|
Loading…
Reference in a new issue