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

Merge pull request #49 from iiab/master

sync from iiab/iiab
This commit is contained in:
A Holt 2017-12-22 20:48:46 -05:00 committed by GitHub
commit 70fd376bc7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 98 additions and 58 deletions

View file

@ -44,7 +44,7 @@ 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 -e "\nEXITING: 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 "IIAB INSTALL INSTRUCTIONS: https://github.com/iiab/iiab/wiki/IIAB-Installation" echo "IIAB INSTALL INSTRUCTIONS: https://github.com/iiab/iiab/wiki/IIAB-Installation"
@ -54,11 +54,19 @@ fi
# Verify that a recent enough version of Ansible is installed. See #449. The # 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 # "include:" command was inconsistently implemented prior to Ansible 2.4.x.x
CURR_ANSIBLE_VER=0 CURR_ANSIBLE_VER=0
if [[ `type -P ansible` ]]; then #if [ $(grep ubuntu /etc/apt/sources.list) ]; then # FAILS when multiple lines returned, due to single square brackets
CURR_ANSIBLE_VER=`ansible --version | head -1 | sed -e 's/.* //'` #if grep -q ubuntu /etc/apt/sources.list ; then # Works: bypasses need for "> /dev/null" thanks to "grep -q" (quiet)
#if command -v ansible > /dev/null ; then # Works But Wordy!
#if [[ $(command -v ansible) ]]; then # Also Works! $(...) nests more easily than backticks
#if [[ `which ansible` ]]; 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 ansible` ]]; then # "type -P" isn't POSIX compliant; it misses built-in commands like "cd"
if [[ `command -v ansible` ]]; then # "command -v" is POSIX compliant; it catches built-in commands like "cd"
#CURR_ANSIBLE_VER=`ansible --version | head -1 | sed -e 's/.* //'`
#CURR_ANSIBLE_VER=`ansible --version | head -1 | cut -f 2 -d " "`
CURR_ANSIBLE_VER=`ansible --version | head -1 | awk '{print $2}'` # to match scripts/ansible
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 -e "\nEXITING: Ansible "$MIN_ANSIBLE_VER" or higher required." 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 "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 "'ansible --version' and 'apt -a list ansible' can also be useful here. Try"
@ -71,7 +79,7 @@ fi
# (in /etc/iiab/iiab.env) of the highest completed Stage. Avoid repetition! # (in /etc/iiab/iiab.env) of the highest completed Stage. Avoid repetition!
STAGE=0 STAGE=0
if [ -f /etc/iiab/iiab.env ]; then if [ -f /etc/iiab/iiab.env ]; then
if [[ `grep STAGE= /etc/iiab/iiab.env` ]]; then if grep -q STAGE= /etc/iiab/iiab.env ; then
source /etc/iiab/iiab.env source /etc/iiab/iiab.env
echo "Extracted STAGE="$STAGE" (counter) from /etc/iiab/iiab.env" echo "Extracted STAGE="$STAGE" (counter) from /etc/iiab/iiab.env"
if ! [ "$STAGE" -eq "$STAGE" ] 2> /dev/null; then if ! [ "$STAGE" -eq "$STAGE" ] 2> /dev/null; then
@ -83,7 +91,7 @@ if [ -f /etc/iiab/iiab.env ]; then
fi fi
fi fi
# if XSCE is present resolveconf will not be # if XSCE is present resolveconf will not be
if [[ `grep XSCE /etc/iiab/iiab.env` ]]; then if grep -q XSCE /etc/iiab/iiab.env ; then
STAGE=0 STAGE=0
rm /etc/iiab/iiab.env rm /etc/iiab/iiab.env
echo "Removed /etc/iiab/iiab.env effectively resetting STAGE (counter)." echo "Removed /etc/iiab/iiab.env effectively resetting STAGE (counter)."

View file

@ -5,48 +5,71 @@ CWD=`pwd`
export ANSIBLE_LOG_PATH="$CWD/iiab-network.log" export ANSIBLE_LOG_PATH="$CWD/iiab-network.log"
if [ ! -f iiab-network.yml ]; then if [ ! -f iiab-network.yml ]; then
echo "IIAB Playbook not found." echo "iiab-network.yml not found in current directory."
echo "Please run this command from the top level of the git repo." echo "Please rerun this command from the top level of the git repo."
echo "Exiting." echo "Exiting."
exit 1 exit 1
fi fi
if [ ! -f /etc/iiab/config_vars.yml ]; then if [ ! -f /etc/iiab/config_vars.yml ]; then
echo "Creating stub /etc/iiab/config_vars.yml"
mkdir -p /etc/iiab mkdir -p /etc/iiab
echo "{}" > /etc/iiab/config_vars.yml echo "{}" > /etc/iiab/config_vars.yml
fi fi
OS="unknown" # will be overridden below, if /etc/iiab/iiab.env is legit OS="unknown" # will be overridden below, if /etc/iiab/iiab.env is legit
if [ -f /etc/iiab/iiab.env ]; then if [ -f /etc/iiab/iiab.env ]; then
echo "Running /etc/iiab/iiab.env"
source /etc/iiab/iiab.env source /etc/iiab/iiab.env
fi fi
echo "Ansible will now run iiab-network.yml -- monitor log file iiab-network.log"
Start=`date` Start=`date`
ansible-playbook -i ansible_hosts iiab-network.yml --connection=local ansible-playbook -i ansible_hosts iiab-network.yml --connection=local
End=`date` End=`date`
# Record critical diagnostics to [/opt/iiab/iiab/]iiab-network.log # Record critical diagnostics to [/opt/iiab/iiab/]iiab-network.log
echo "" >> iiab-network.log echo "" >> iiab-network.log
# redhat path # redhat path
if [ "OS" == "centos" ] || [ "OS" == "fedora" ]; then # 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.
if [ "$OS" == "centos" ] || [ "$OS" == "fedora" ]; then
ls -la /etc/sys*/net*/ifcfg* >> iiab-network.log ls -la /etc/sys*/net*/ifcfg* >> iiab-network.log
fi fi
# Ubuntu desktop might be using NM - split out.
if [ $(which nmcli) ]; then # Ubuntu desktop/others might be using NM (NetworkManager) - split out.
#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"
nmcli d >> iiab-network.log nmcli d >> iiab-network.log
echo >> iiab-network.log
nmcli c >> iiab-network.log nmcli c >> iiab-network.log
fi fi
echo "" >> iiab-network.log
ip r >> iiab-network.log ip r >> iiab-network.log
echo "" >> iiab-network.log
brctl show >> iiab-network.log brctl show >> iiab-network.log
echo "run start: $Start" >> iiab-network.log echo >> iiab-network.log
echo "run end: $End" >> iiab-network.log echo "iiab-network run start: $Start" >> iiab-network.log
echo "" >> iiab-network.log echo "iiab-network run end: $End" >> iiab-network.log
echo "" >> iiab-network.log echo >> iiab-network.log
echo >> iiab-network.log
# Put the same diagnostics on screen, for live operator # Put the same diagnostics on screen, for live operator
if [[ `command -v nmcli` ]]; then
nmcli d
echo
nmcli c
fi
ip r ip r
brctl show brctl show
echo "run start: $Start" echo
echo "run end: $End" echo "iiab-network run start: $Start"
echo "iiab-network run end: $End"

View file

@ -1,27 +1,34 @@
#!/bin/bash -e #!/bin/bash -e
# required to start loading IIAB with ansible
GOOD_VER="2.4.2" # Installs or upgrades to the best possible Ansible release, so iiab-install
FOUND="" # can proceed. Ensure you're online before running this script!
FAMILY=""
VER="" GOOD_VER="2.4.2" # Ansible version for OLPC, for pip.
# On other OS's we install/upgrade to the latest Ansible.
# Pin all to 2.4.x in future, if really/truly nec?
CURR_VER="undefined"
# FOUND="false" # NOT USED AS OF 2017-12-12
# FAMILY="undefined" # NOT USED AS OF 2017-12-12
# below are unused for future use # below are unused for future use
URL="NA" # URL="NA"
export DEBIAN_FRONTEND=noninteractive export DEBIAN_FRONTEND=noninteractive
if ! [ $(which ansible-playbook) ]; then
if ! which ansible-playbook ; then
echo "Installing --- Please Wait" echo "Installing --- Please Wait"
if [ -f /etc/centos-release ]; then if [ -f /etc/centos-release ]; then
yum -y install ca-certificates nss epel-release yum -y install ca-certificates nss epel-release
yum -y install git bzip2 file findutils gzip hg svn sudo tar which unzip xz zip libselinux-python yum -y install git bzip2 file findutils gzip hg svn sudo tar which unzip xz zip libselinux-python
yum -y install python-pip python-setuptools python-wheel patch yum -y install python-pip python-setuptools python-wheel patch
yum -y install http://releases.ansible.com/ansible/rpm/release/epel-7-x86_64/ansible-2.4.2.0-1.el7.ans.noarch.rpm yum -y install http://releases.ansible.com/ansible/rpm/release/epel-7-x86_64/ansible-2.4.2.0-1.el7.ans.noarch.rpm
FOUND="yes" # FOUND="true"
FAMILY="redhat" # FAMILY="redhat"
# elif [ -f /etc/fedora-release ]; then # elif [ -f /etc/fedora-release ]; then
# VER=`grep VERSION_ID /etc/*elease | cut -d= -f2` # CURR_VER=`grep VERSION_ID /etc/*elease | cut -d= -f2`
# URL=https://github.com/jvonau/iiab/blob/ansible/vars/fedora-$VER.yml # URL=https://github.com/jvonau/iiab/blob/ansible/vars/fedora-$CURR_VER.yml
# dnf -y install ansible git bzip2 file findutils gzip hg svn sudo tar which unzip xz zip libselinux-python # dnf -y install ansible git bzip2 file findutils gzip hg svn sudo tar which unzip xz zip libselinux-python
# dnf -y install python-pip python-setuptools python-wheel patch # dnf -y install python-pip python-setuptools python-wheel patch
# FOUND="yes" # FOUND="true"
# FAMILY="redhat" # FAMILY="redhat"
elif [ -f /etc/olpc-release ]; then elif [ -f /etc/olpc-release ]; then
yum -y install ca-certificates nss yum -y install ca-certificates nss
@ -29,51 +36,53 @@ if ! [ $(which ansible-playbook) ]; then
yum -y install python-pip python-setuptools python-wheel patch yum -y install python-pip python-setuptools python-wheel patch
pip install --upgrade pip setuptools wheel #EOL just do it pip install --upgrade pip setuptools wheel #EOL just do it
pip install ansible==$GOOD_VER --disable-pip-version-check pip install ansible==$GOOD_VER --disable-pip-version-check
FOUND="yes" # FOUND="true"
FAMILY="olpc" # FAMILY="olpc"
elif [ -f /etc/debian_version ] || [ `grep -qi raspbian /etc/*elease` ]; then elif [ -f /etc/debian_version ] || (grep -qi raspbian /etc/*elease) ; then
if [ ! `grep -qi ansible /etc/apt/sources.list` ] && [ ! -f /etc/apt/sources.list.d/ansible ]; then if ( ! grep -qi ansible /etc/apt/sources.list) && [ ! -f /etc/apt/sources.list.d/ansible ]; then
apt-get -y install dirmngr python-pip python-setuptools python-wheel patch apt -y install dirmngr python-pip python-setuptools python-wheel patch
echo "deb http://ppa.launchpad.net/ansible/ansible/ubuntu xenial main" \ echo "deb http://ppa.launchpad.net/ansible/ansible/ubuntu xenial main" \
>> /etc/apt/sources.list.d/ansible.list >> /etc/apt/sources.list.d/ansible.list
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7BB9C367 apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7BB9C367
fi fi
FOUND="yes" # FOUND="true"
FAMILY="debian" # FAMILY="debian"
elif [ `grep -qi ubuntu /etc/lsb-release` ] || [ `grep -qi ubuntu /etc/os-release` ]; then # Parens are optional, but greatly clarify :)
apt-get -y install python-pip python-setuptools python-wheel patch elif (grep -qi ubuntu /etc/lsb-release) || (grep -qi ubuntu /etc/os-release); then
apt -y install python-pip python-setuptools python-wheel patch
apt-add-repository -y ppa:ansible/ansible apt-add-repository -y ppa:ansible/ansible
FOUND="yes" # FOUND="true"
FAMILY="debian" # FAMILY="debian"
fi # fi
if [ ! $FOUND = "yes" ]; then # if [ ! $FOUND = "true" ]; then
echo 'WARN: Could not detect distro or distro unsupported' else
echo "WARN: Could not detect distro or distro unsupported"
exit 1 exit 1
fi fi
else else
VER=`ansible --version|head -n 1|cut -f 2 -d " "` #CURR_VER=`ansible --version | head -n 1 | cut -f 2 -d " "`
echo "Current ansible version installed is $VER" CURR_VER=`ansible --version | head -1 | awk '{print $2}'` # to match iiab-install
echo "Current ansible version installed is $CURR_VER"
if [ -f /etc/centos-release ] || [ -f /etc/fedora-release ]; then if [ -f /etc/centos-release ] || [ -f /etc/fedora-release ]; then
echo "Please use your system's package manager to update ansible" echo "Please use your system's package manager to update ansible"
exit 0 exit 0
fi elif [ -f /etc/olpc-release ]; then
if [ -f /etc/olpc-release ]; then
echo "Please use pip package manager to update ansible" echo "Please use pip package manager to update ansible"
exit 0 exit 0
fi #fi
if [[ `grep -qi ansible /etc/apt/sources.list` ]] || [ -f /etc/apt/sources.list.d/ansible*.list ]; then #if [[ `grep -qi ansible /etc/apt/sources.list` ]] || [ -f /etc/apt/sources.list.d/ansible*.list ]; then
echo "repos found" elif (grep -qi ansible /etc/apt/sources.list) || (ls /etc/apt/sources.list.d/ansible*.list >/dev/null 2>&1) ; then
echo "Ansible repo(s) found within /etc/apt/sources.list*"
else else
echo "Upstream ansible source repo not found, please uninstall ansible and re-run this script" echo "Upstream ansible source repo not found, please uninstall ansible and re-run this script"
exit 1 exit 1
fi fi
fi fi
if [ ! -f /etc/centos-release ] && [ ! -f /etc/fedora-release ] && \ if [ ! -f /etc/centos-release ] && [ ! -f /etc/fedora-release ] && [ ! -f /etc/olpc-release ]; then
[ ! -f /etc/olpc-release ]; then echo "Using apt to check for updates, then install/upgrade ansible"
echo "Using OS package manager to check for ansible updates" apt update
apt-get -y update apt -y install ansible
apt-get -y install ansible
fi fi
# needed? # needed?