From 6df4e6957b701d5ddf15d01a64502a35837a14d6 Mon Sep 17 00:00:00 2001 From: A Holt Date: Mon, 11 Dec 2017 19:33:35 -0500 Subject: [PATCH 01/27] weren't working: -f ansible*.list & grep -q --- scripts/ansible | 62 +++++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/scripts/ansible b/scripts/ansible index 44fd751b6..e90637af6 100755 --- a/scripts/ansible +++ b/scripts/ansible @@ -1,27 +1,29 @@ #!/bin/bash -e # required to start loading IIAB with ansible GOOD_VER="2.4.2" -FOUND="" -FAMILY="" -VER="" +FOUND="false" +# FAMILY="undefined" # NOT USED AS OF 2017-12-11 +VER="undefined" # below are unused for future use -URL="NA" +# URL="NA" + export DEBIAN_FRONTEND=noninteractive -if ! [ $(which ansible-playbook) ]; then + +if ! [ `which ansible-playbook` ]; then echo "Installing --- Please Wait" if [ -f /etc/centos-release ]; then 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 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 - FOUND="yes" - FAMILY="redhat" + FOUND="true" + # FAMILY="redhat" # NOT USED AS OF 2017-12-11 # elif [ -f /etc/fedora-release ]; then # VER=`grep VERSION_ID /etc/*elease | cut -d= -f2` # URL=https://github.com/jvonau/iiab/blob/ansible/vars/fedora-$VER.yml # 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 -# FOUND="yes" +# FOUND="true" # FAMILY="redhat" elif [ -f /etc/olpc-release ]; then yum -y install ca-certificates nss @@ -29,29 +31,29 @@ if ! [ $(which ansible-playbook) ]; then yum -y install python-pip python-setuptools python-wheel patch pip install --upgrade pip setuptools wheel #EOL just do it pip install ansible==$GOOD_VER --disable-pip-version-check - FOUND="yes" - FAMILY="olpc" - 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 - apt-get -y install dirmngr python-pip python-setuptools python-wheel patch + FOUND="true" + # FAMILY="olpc" # NOT USED AS OF 2017-12-11 + elif [ -f /etc/debian_version ] || [[ `grep -i raspbian /etc/*elease` ]]; then + if [[ ! `grep -i ansible /etc/apt/sources.list` ]] && [ ! -f /etc/apt/sources.list.d/ansible ]; then + apt -y install dirmngr python-pip python-setuptools python-wheel patch 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 fi - FOUND="yes" - FAMILY="debian" - elif [ `grep -qi ubuntu /etc/lsb-release` ] || [ `grep -qi ubuntu /etc/os-release` ]; then - apt-get -y install python-pip python-setuptools python-wheel patch + FOUND="true" + # FAMILY="debian" # NOT USED AS OF 2017-12-11 + elif [[ `grep -i 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 - FOUND="yes" - FAMILY="debian" + FOUND="true" + # FAMILY="debian" # NOT USED AS OF 2017-12-11 fi - if [ ! $FOUND = "yes" ]; then - echo 'WARN: Could not detect distro or distro unsupported' + if [ ! $FOUND = "true" ]; then + echo "WARN: Could not detect distro or distro unsupported" exit 1 fi else - VER=`ansible --version|head -n 1|cut -f 2 -d " "` + VER=`ansible --version | head -n 1 | cut -f 2 -d " "` echo "Current ansible version installed is $VER" if [ -f /etc/centos-release ] || [ -f /etc/fedora-release ]; then echo "Please use your system's package manager to update ansible" @@ -61,19 +63,19 @@ else echo "Please use pip package manager to update ansible" exit 0 fi - if [[ `grep -qi ansible /etc/apt/sources.list` ]] || [ -f /etc/apt/sources.list.d/ansible*.list ]; then - echo "repos found" + #if [[ `grep -qi ansible /etc/apt/sources.list` ]] || [ -f /etc/apt/sources.list.d/ansible*.list ]; then + if [[ `grep -i ansible /etc/apt/sources.list` ]] || ls /etc/apt/sources.list.d/ansible*.list >/dev/null 2>&1 ; then + echo "Ansible repo(s) found" else echo "Upstream ansible source repo not found, please uninstall ansible and re-run this script" exit 1 fi fi -if [ ! -f /etc/centos-release ] && [ ! -f /etc/fedora-release ] && \ - [ ! -f /etc/olpc-release ]; then - echo "Using OS package manager to check for ansible updates" - apt-get -y update - apt-get -y install ansible +if [ ! -f /etc/centos-release ] && [ ! -f /etc/fedora-release ] && [ ! -f /etc/olpc-release ]; then + echo "Using apt to check for & install ansible updates" + apt update + apt -y install ansible fi # needed? From cdac219b5ecd0b9d5af65029e3878fd784bfeff5 Mon Sep 17 00:00:00 2001 From: A Holt Date: Mon, 11 Dec 2017 19:40:24 -0500 Subject: [PATCH 02/27] another "grep -qi" -> "grep -i" --- scripts/ansible | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ansible b/scripts/ansible index e90637af6..25d5221c6 100755 --- a/scripts/ansible +++ b/scripts/ansible @@ -42,7 +42,7 @@ if ! [ `which ansible-playbook` ]; then fi FOUND="true" # FAMILY="debian" # NOT USED AS OF 2017-12-11 - elif [[ `grep -i ubuntu /etc/lsb-release` ]] || [[ `grep -qi ubuntu /etc/os-release` ]]; then + elif [[ `grep -i ubuntu /etc/lsb-release` ]] || [[ `grep -q ubuntu /etc/os-release` ]]; then apt -y install python-pip python-setuptools python-wheel patch apt-add-repository -y ppa:ansible/ansible FOUND="true" From 3692b1c2f96bc95ded5abf9af25c35dae7baaf33 Mon Sep 17 00:00:00 2001 From: A Holt Date: Mon, 11 Dec 2017 20:04:59 -0500 Subject: [PATCH 03/27] Update ansible --- scripts/ansible | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ansible b/scripts/ansible index 25d5221c6..ed11610b7 100755 --- a/scripts/ansible +++ b/scripts/ansible @@ -2,8 +2,8 @@ # required to start loading IIAB with ansible GOOD_VER="2.4.2" FOUND="false" -# FAMILY="undefined" # NOT USED AS OF 2017-12-11 VER="undefined" +# FAMILY="undefined" # NOT USED AS OF 2017-12-11 # below are unused for future use # URL="NA" From 5fda074a62f5f0ca5d01fa211728ef6f5396439f Mon Sep 17 00:00:00 2001 From: A Holt Date: Mon, 11 Dec 2017 20:06:10 -0500 Subject: [PATCH 04/27] reverts prior change --- scripts/ansible | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ansible b/scripts/ansible index ed11610b7..25d5221c6 100755 --- a/scripts/ansible +++ b/scripts/ansible @@ -2,8 +2,8 @@ # required to start loading IIAB with ansible GOOD_VER="2.4.2" FOUND="false" -VER="undefined" # FAMILY="undefined" # NOT USED AS OF 2017-12-11 +VER="undefined" # below are unused for future use # URL="NA" From f169946549d2a3d356a3ee1159b4b01d6b8ff14f Mon Sep 17 00:00:00 2001 From: A Holt Date: Mon, 11 Dec 2017 20:10:00 -0500 Subject: [PATCH 05/27] grep -q -> grep -i --- scripts/ansible | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ansible b/scripts/ansible index 25d5221c6..d6ebed813 100755 --- a/scripts/ansible +++ b/scripts/ansible @@ -42,7 +42,7 @@ if ! [ `which ansible-playbook` ]; then fi FOUND="true" # FAMILY="debian" # NOT USED AS OF 2017-12-11 - elif [[ `grep -i ubuntu /etc/lsb-release` ]] || [[ `grep -q ubuntu /etc/os-release` ]]; then + elif [[ `grep -i ubuntu /etc/lsb-release` ]] || [[ `grep -i ubuntu /etc/os-release` ]]; then apt -y install python-pip python-setuptools python-wheel patch apt-add-repository -y ppa:ansible/ansible FOUND="true" From 29225fc590216da5ba241356960425aa5ddb326c Mon Sep 17 00:00:00 2001 From: A Holt Date: Mon, 11 Dec 2017 21:21:39 -0500 Subject: [PATCH 06/27] Improved output for implementers --- scripts/ansible | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/ansible b/scripts/ansible index d6ebed813..8a8f57bae 100755 --- a/scripts/ansible +++ b/scripts/ansible @@ -65,7 +65,7 @@ else fi #if [[ `grep -qi ansible /etc/apt/sources.list` ]] || [ -f /etc/apt/sources.list.d/ansible*.list ]; then if [[ `grep -i ansible /etc/apt/sources.list` ]] || ls /etc/apt/sources.list.d/ansible*.list >/dev/null 2>&1 ; then - echo "Ansible repo(s) found" + echo "Ansible repo(s) found within /etc/apt/sources.list*" else echo "Upstream ansible source repo not found, please uninstall ansible and re-run this script" exit 1 @@ -73,7 +73,7 @@ else fi if [ ! -f /etc/centos-release ] && [ ! -f /etc/fedora-release ] && [ ! -f /etc/olpc-release ]; then - echo "Using apt to check for & install ansible updates" + echo "Using apt to check for updates, then install/upgrade ansible" apt update apt -y install ansible fi From e5c7508354e529e40b7e07ce146e08516a8fdf7e Mon Sep 17 00:00:00 2001 From: A Holt Date: Mon, 11 Dec 2017 21:35:47 -0500 Subject: [PATCH 07/27] Simplified with elif/else --- scripts/ansible | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/scripts/ansible b/scripts/ansible index 8a8f57bae..a36f801ec 100755 --- a/scripts/ansible +++ b/scripts/ansible @@ -1,9 +1,9 @@ #!/bin/bash -e # required to start loading IIAB with ansible GOOD_VER="2.4.2" -FOUND="false" -# FAMILY="undefined" # NOT USED AS OF 2017-12-11 VER="undefined" +# FOUND="false". # NOT USED AS OF 2017-12-11 +# FAMILY="undefined" # NOT USED AS OF 2017-12-11 # below are unused for future use # URL="NA" @@ -16,7 +16,7 @@ if ! [ `which ansible-playbook` ]; then 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 http://releases.ansible.com/ansible/rpm/release/epel-7-x86_64/ansible-2.4.2.0-1.el7.ans.noarch.rpm - FOUND="true" + # FOUND="true" # FAMILY="redhat" # NOT USED AS OF 2017-12-11 # elif [ -f /etc/fedora-release ]; then # VER=`grep VERSION_ID /etc/*elease | cut -d= -f2` @@ -31,7 +31,7 @@ if ! [ `which ansible-playbook` ]; then yum -y install python-pip python-setuptools python-wheel patch pip install --upgrade pip setuptools wheel #EOL just do it pip install ansible==$GOOD_VER --disable-pip-version-check - FOUND="true" + # FOUND="true" # FAMILY="olpc" # NOT USED AS OF 2017-12-11 elif [ -f /etc/debian_version ] || [[ `grep -i raspbian /etc/*elease` ]]; then if [[ ! `grep -i ansible /etc/apt/sources.list` ]] && [ ! -f /etc/apt/sources.list.d/ansible ]; then @@ -40,15 +40,16 @@ if ! [ `which ansible-playbook` ]; then >> /etc/apt/sources.list.d/ansible.list apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7BB9C367 fi - FOUND="true" + # FOUND="true" # FAMILY="debian" # NOT USED AS OF 2017-12-11 elif [[ `grep -i ubuntu /etc/lsb-release` ]] || [[ `grep -i ubuntu /etc/os-release` ]]; then apt -y install python-pip python-setuptools python-wheel patch apt-add-repository -y ppa:ansible/ansible - FOUND="true" + # FOUND="true" # FAMILY="debian" # NOT USED AS OF 2017-12-11 - fi - if [ ! $FOUND = "true" ]; then + # fi + # if [ ! $FOUND = "true" ]; then + else echo "WARN: Could not detect distro or distro unsupported" exit 1 fi @@ -58,13 +59,12 @@ else if [ -f /etc/centos-release ] || [ -f /etc/fedora-release ]; then echo "Please use your system's package manager to update ansible" exit 0 - fi - if [ -f /etc/olpc-release ]; then + elif [ -f /etc/olpc-release ]; then echo "Please use pip package manager to update ansible" exit 0 - fi + #fi #if [[ `grep -qi ansible /etc/apt/sources.list` ]] || [ -f /etc/apt/sources.list.d/ansible*.list ]; then - if [[ `grep -i ansible /etc/apt/sources.list` ]] || ls /etc/apt/sources.list.d/ansible*.list >/dev/null 2>&1 ; then + elif [[ `grep -i 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 echo "Upstream ansible source repo not found, please uninstall ansible and re-run this script" From 904484d9774a3d030ce6b8a079ec21cd2864ad06 Mon Sep 17 00:00:00 2001 From: A Holt Date: Mon, 11 Dec 2017 22:08:17 -0500 Subject: [PATCH 08/27] Explanations added --- scripts/ansible | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/ansible b/scripts/ansible index a36f801ec..fb64140de 100755 --- a/scripts/ansible +++ b/scripts/ansible @@ -1,6 +1,9 @@ #!/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 can proceed. +# Ensure you are online before running this script! + +GOOD_VER="2.4.2". # Ansible version for OLPC. On other OS's we install/upgrade to the latest Ansible. + # Pinning to 2.4.x could be considered in future, if truly nec? VER="undefined" # FOUND="false". # NOT USED AS OF 2017-12-11 # FAMILY="undefined" # NOT USED AS OF 2017-12-11 From 989d52c4a1d0f3df89a6945be1fb0a5ab031a7e2 Mon Sep 17 00:00:00 2001 From: A Holt Date: Mon, 11 Dec 2017 23:29:53 -0500 Subject: [PATCH 09/27] 2 typos due to autocomplete --- scripts/ansible | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/ansible b/scripts/ansible index fb64140de..801b86350 100755 --- a/scripts/ansible +++ b/scripts/ansible @@ -2,10 +2,10 @@ # Installs or upgrades to the best possible Ansible release, so iiab-install can proceed. # Ensure you are online before running this script! -GOOD_VER="2.4.2". # Ansible version for OLPC. On other OS's we install/upgrade to the latest Ansible. +GOOD_VER="2.4.2" # Ansible version for OLPC. On other OS's we install/upgrade to the latest Ansible. # Pinning to 2.4.x could be considered in future, if truly nec? VER="undefined" -# FOUND="false". # NOT USED AS OF 2017-12-11 +# FOUND="false" # NOT USED AS OF 2017-12-11 # FAMILY="undefined" # NOT USED AS OF 2017-12-11 # below are unused for future use # URL="NA" From d7f275448da1cded22c142645f1b417af3916a65 Mon Sep 17 00:00:00 2001 From: A Holt Date: Tue, 12 Dec 2017 01:17:12 -0500 Subject: [PATCH 10/27] Update iiab-network --- iiab-network | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/iiab-network b/iiab-network index b7b42b7d1..9ab689069 100755 --- a/iiab-network +++ b/iiab-network @@ -5,8 +5,8 @@ CWD=`pwd` export ANSIBLE_LOG_PATH="$CWD/iiab-network.log" if [ ! -f iiab-network.yml ]; then - echo "IIAB Playbook not found." - echo "Please run this command from the top level of the git repo." + echo "iiab-network.yml not found in current directory." + echo "Please rerun this command from the top level of the git repo." echo "Exiting." exit 1 fi @@ -28,11 +28,11 @@ End=`date` # Record critical diagnostics to [/opt/iiab/iiab/]iiab-network.log echo "" >> iiab-network.log # redhat path -if [ "OS" == "centos" ] || [ "OS" == "fedora" ]; then +if [ "OS" == "centos" ] || [ "OS" == "fedora" ]; then ls -la /etc/sys*/net*/ifcfg* >> iiab-network.log fi # Ubuntu desktop might be using NM - split out. -if [ $(which nmcli) ]; then +if [[ `which nmcli` ]]; then nmcli d >> iiab-network.log nmcli c >> iiab-network.log fi From ea2c395fc9634d7cddc6c24eec3f0fd210e32eb0 Mon Sep 17 00:00:00 2001 From: A Holt Date: Tue, 12 Dec 2017 09:33:20 -0500 Subject: [PATCH 11/27] shorter: if ; then --- iiab-network | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/iiab-network b/iiab-network index 9ab689069..cff85518c 100755 --- a/iiab-network +++ b/iiab-network @@ -32,7 +32,9 @@ if [ "OS" == "centos" ] || [ "OS" == "fedora" ]; then ls -la /etc/sys*/net*/ifcfg* >> iiab-network.log fi # Ubuntu desktop might be using NM - split out. -if [[ `which nmcli` ]]; then +# if [ $(which nmcli) ]; then +# if [[ `which nmcli` ]]; then +if which nmcli; then nmcli d >> iiab-network.log nmcli c >> iiab-network.log fi From f9593392e13b10acb79d8cf6e94debadc0efd3e3 Mon Sep 17 00:00:00 2001 From: A Holt Date: Tue, 12 Dec 2017 09:40:25 -0500 Subject: [PATCH 12/27] clarif: "if ; then" works with "grep -q" etc --- iiab-network | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iiab-network b/iiab-network index cff85518c..b7067fba0 100755 --- a/iiab-network +++ b/iiab-network @@ -32,9 +32,9 @@ if [ "OS" == "centos" ] || [ "OS" == "fedora" ]; then ls -la /etc/sys*/net*/ifcfg* >> iiab-network.log fi # Ubuntu desktop might be using NM - split out. -# if [ $(which nmcli) ]; then -# if [[ `which nmcli` ]]; then -if which nmcli; then +# if [ $(which nmcli) ]; then # syntax fails when multiple lines returned +# if [[ `which nmcli` ]]; then # syntax also works +if which nmcli; then # syntax works great, with "grep -q" too! nmcli d >> iiab-network.log nmcli c >> iiab-network.log fi From 944fe8b1ec24463b062336d63d173f30d45f6ad2 Mon Sep 17 00:00:00 2001 From: A Holt Date: Tue, 12 Dec 2017 11:09:00 -0500 Subject: [PATCH 13/27] restores "grep -qi" & much cleaner Tested on Ubuntu 16.04 LTS and Raspbian Lite. --- scripts/ansible | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/scripts/ansible b/scripts/ansible index 801b86350..6200bd13a 100755 --- a/scripts/ansible +++ b/scripts/ansible @@ -1,12 +1,14 @@ #!/bin/bash -e -# Installs or upgrades to the best possible Ansible release, so iiab-install can proceed. -# Ensure you are online before running this script! -GOOD_VER="2.4.2" # Ansible version for OLPC. On other OS's we install/upgrade to the latest Ansible. - # Pinning to 2.4.x could be considered in future, if truly nec? -VER="undefined" -# FOUND="false" # NOT USED AS OF 2017-12-11 -# FAMILY="undefined" # NOT USED AS OF 2017-12-11 +# Installs or upgrades to the best possible Ansible release, so iiab-install +# can proceed. Ensure you're online before running this script! + +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 # URL="NA" @@ -20,10 +22,10 @@ if ! [ `which ansible-playbook` ]; then 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 # FOUND="true" - # FAMILY="redhat" # NOT USED AS OF 2017-12-11 + # FAMILY="redhat" # elif [ -f /etc/fedora-release ]; then -# VER=`grep VERSION_ID /etc/*elease | cut -d= -f2` -# URL=https://github.com/jvonau/iiab/blob/ansible/vars/fedora-$VER.yml +# CURR_VER=`grep VERSION_ID /etc/*elease | cut -d= -f2` +# 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 python-pip python-setuptools python-wheel patch # FOUND="true" @@ -35,21 +37,22 @@ if ! [ `which ansible-playbook` ]; then pip install --upgrade pip setuptools wheel #EOL just do it pip install ansible==$GOOD_VER --disable-pip-version-check # FOUND="true" - # FAMILY="olpc" # NOT USED AS OF 2017-12-11 - elif [ -f /etc/debian_version ] || [[ `grep -i raspbian /etc/*elease` ]]; then - if [[ ! `grep -i ansible /etc/apt/sources.list` ]] && [ ! -f /etc/apt/sources.list.d/ansible ]; then + # FAMILY="olpc" + 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 apt -y install dirmngr python-pip python-setuptools python-wheel patch echo "deb http://ppa.launchpad.net/ansible/ansible/ubuntu xenial main" \ >> /etc/apt/sources.list.d/ansible.list apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7BB9C367 fi # FOUND="true" - # FAMILY="debian" # NOT USED AS OF 2017-12-11 - elif [[ `grep -i ubuntu /etc/lsb-release` ]] || [[ `grep -i ubuntu /etc/os-release` ]]; then + # FAMILY="debian" + # Parens are optional, but greatly clarify :) + 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 # FOUND="true" - # FAMILY="debian" # NOT USED AS OF 2017-12-11 + # FAMILY="debian" # fi # if [ ! $FOUND = "true" ]; then else @@ -57,8 +60,8 @@ if ! [ `which ansible-playbook` ]; then exit 1 fi else - VER=`ansible --version | head -n 1 | cut -f 2 -d " "` - echo "Current ansible version installed is $VER" + CURR_VER=`ansible --version | head -n 1 | cut -f 2 -d " "` + echo "Current ansible version installed is $CURR_VER" if [ -f /etc/centos-release ] || [ -f /etc/fedora-release ]; then echo "Please use your system's package manager to update ansible" exit 0 @@ -67,7 +70,7 @@ else exit 0 #fi #if [[ `grep -qi ansible /etc/apt/sources.list` ]] || [ -f /etc/apt/sources.list.d/ansible*.list ]; then - elif [[ `grep -i ansible /etc/apt/sources.list` ]] || ls /etc/apt/sources.list.d/ansible*.list >/dev/null 2>&1 ; then + 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 echo "Upstream ansible source repo not found, please uninstall ansible and re-run this script" From 9d014e620c37e1dd18b3953afb4eb132cd79f98b Mon Sep 17 00:00:00 2001 From: A Holt Date: Tue, 12 Dec 2017 11:33:39 -0500 Subject: [PATCH 14/27] if ! which ansible-playbook ; then --- scripts/ansible | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ansible b/scripts/ansible index 6200bd13a..62f5f1d61 100755 --- a/scripts/ansible +++ b/scripts/ansible @@ -14,7 +14,7 @@ CURR_VER="undefined" export DEBIAN_FRONTEND=noninteractive -if ! [ `which ansible-playbook` ]; then +if ! which ansible-playbook ; then echo "Installing --- Please Wait" if [ -f /etc/centos-release ]; then yum -y install ca-certificates nss epel-release From 85c16b384c832ae62a4ea6761c75444d418f4b6c Mon Sep 17 00:00:00 2001 From: A Holt Date: Wed, 13 Dec 2017 02:52:14 -0500 Subject: [PATCH 15/27] $OS had been typo'd in original, as "OS" --- iiab-network | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iiab-network b/iiab-network index b7067fba0..f7c14e0b7 100755 --- a/iiab-network +++ b/iiab-network @@ -28,7 +28,7 @@ End=`date` # Record critical diagnostics to [/opt/iiab/iiab/]iiab-network.log echo "" >> iiab-network.log # redhat path -if [ "OS" == "centos" ] || [ "OS" == "fedora" ]; then +if [ $OS == "centos" ] || [ $OS == "fedora" ]; then ls -la /etc/sys*/net*/ifcfg* >> iiab-network.log fi # Ubuntu desktop might be using NM - split out. From 05e357cc7aa07926d773166f6cd4322ad354d07a Mon Sep 17 00:00:00 2001 From: A Holt Date: Wed, 13 Dec 2017 02:57:26 -0500 Subject: [PATCH 16/27] Paul Armstrong's Shell Style Guide --- iiab-network | 2 ++ 1 file changed, 2 insertions(+) diff --git a/iiab-network b/iiab-network index f7c14e0b7..a938d5711 100755 --- a/iiab-network +++ b/iiab-network @@ -31,7 +31,9 @@ echo "" >> iiab-network.log if [ $OS == "centos" ] || [ $OS == "fedora" ]; then ls -la /etc/sys*/net*/ifcfg* >> iiab-network.log fi + # Ubuntu desktop might be using NM - split out. +# Paul Armstrong's Shell Style Guide: https://google.github.io/styleguide/shell.xml # if [ $(which nmcli) ]; then # syntax fails when multiple lines returned # if [[ `which nmcli` ]]; then # syntax also works if which nmcli; then # syntax works great, with "grep -q" too! From 299c41091bdd040419f904671f007dad4d8c0922 Mon Sep 17 00:00:00 2001 From: A Holt Date: Wed, 13 Dec 2017 03:15:39 -0500 Subject: [PATCH 17/27] "$OS" is even safer: avoids if-then failing on nullstring --- iiab-network | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iiab-network b/iiab-network index a938d5711..9948c5dd8 100755 --- a/iiab-network +++ b/iiab-network @@ -28,7 +28,7 @@ End=`date` # Record critical diagnostics to [/opt/iiab/iiab/]iiab-network.log echo "" >> iiab-network.log # redhat path -if [ $OS == "centos" ] || [ $OS == "fedora" ]; then +if [ "$OS" == "centos" ] || [ "$OS" == "fedora" ]; then ls -la /etc/sys*/net*/ifcfg* >> iiab-network.log fi From 4797f0805cd72cd00e4725ffda1d1b338d74be50 Mon Sep 17 00:00:00 2001 From: A Holt Date: Wed, 13 Dec 2017 03:56:22 -0500 Subject: [PATCH 18/27] Added live output/explanations --- iiab-network | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/iiab-network b/iiab-network index 9948c5dd8..89faa631c 100755 --- a/iiab-network +++ b/iiab-network @@ -12,34 +12,42 @@ if [ ! -f iiab-network.yml ]; then fi if [ ! -f /etc/iiab/config_vars.yml ]; then + echo "Creating stub /etc/iiab/config_vars.yml" mkdir -p /etc/iiab echo "{}" > /etc/iiab/config_vars.yml fi OS="unknown" # will be overridden below, if /etc/iiab/iiab.env is legit if [ -f /etc/iiab/iiab.env ]; then + echo "Running /etc/iiab/iiab.env" source /etc/iiab/iiab.env fi +echo "Ansible will now run iiab-network.yml -- monitor log file iiab-network.log" Start=`date` ansible-playbook -i ansible_hosts iiab-network.yml --connection=local End=`date` + # Record critical diagnostics to [/opt/iiab/iiab/]iiab-network.log echo "" >> iiab-network.log + # redhat path +# 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 fi -# Ubuntu desktop might be using NM - split out. -# Paul Armstrong's Shell Style Guide: https://google.github.io/styleguide/shell.xml +# Ubuntu desktop/others might be using NM (NetworkManager) - split out. # if [ $(which nmcli) ]; then # syntax fails when multiple lines returned # if [[ `which nmcli` ]]; then # syntax also works if which nmcli; then # syntax works great, with "grep -q" too! nmcli d >> iiab-network.log nmcli c >> iiab-network.log fi + echo "" >> iiab-network.log ip r >> iiab-network.log echo "" >> iiab-network.log @@ -49,7 +57,12 @@ echo "run end: $End" >> iiab-network.log echo "" >> iiab-network.log echo "" >> iiab-network.log + # Put the same diagnostics on screen, for live operator +if which nmcli; then # syntax works great, with "grep -q" too! + nmcli d + nmcli c +fi ip r brctl show echo "run start: $Start" From 8f361d4c513c867812271e5ea33ca12129632c42 Mon Sep 17 00:00:00 2001 From: A Holt Date: Wed, 13 Dec 2017 04:45:04 -0500 Subject: [PATCH 19/27] simplified each [[ `CMD` ]] + ansible version logic --- iiab-install | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/iiab-install b/iiab-install index dd6711709..58ac12191 100755 --- a/iiab-install +++ b/iiab-install @@ -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. CURR_KERN=`uname -r` 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 "PLEASE RUN 'apt update' then 'apt install raspberrypi-kernel' then reboot." echo "IIAB INSTALL INSTRUCTIONS: https://github.com/iiab/iiab/wiki/IIAB-Installation" @@ -54,11 +54,13 @@ 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/.* //'` +if type -P ansible ; then + #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}'` echo "Found Ansible "$CURR_ANSIBLE_VER"" 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 "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" @@ -71,7 +73,7 @@ fi # (in /etc/iiab/iiab.env) of the highest completed Stage. Avoid repetition! STAGE=0 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 echo "Extracted STAGE="$STAGE" (counter) from /etc/iiab/iiab.env" if ! [ "$STAGE" -eq "$STAGE" ] 2> /dev/null; then @@ -83,7 +85,7 @@ if [ -f /etc/iiab/iiab.env ]; then fi fi # 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 rm /etc/iiab/iiab.env echo "Removed /etc/iiab/iiab.env effectively resetting STAGE (counter)." From 4e90c94c9e4140bb9aaed758bafe2fe56fd8ea3a Mon Sep 17 00:00:00 2001 From: A Holt Date: Wed, 13 Dec 2017 04:51:45 -0500 Subject: [PATCH 20/27] ansible version logic standardized w/ iiab-install --- scripts/ansible | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/ansible b/scripts/ansible index 62f5f1d61..dc1513704 100755 --- a/scripts/ansible +++ b/scripts/ansible @@ -60,7 +60,8 @@ if ! which ansible-playbook ; then exit 1 fi else - CURR_VER=`ansible --version | head -n 1 | cut -f 2 -d " "` + #CURR_VER=`ansible --version | head -n 1 | cut -f 2 -d " "` + CURR_VER=`ansible --version | head -1 | awk '{print $2}'` echo "Current ansible version installed is $CURR_VER" if [ -f /etc/centos-release ] || [ -f /etc/fedora-release ]; then echo "Please use your system's package manager to update ansible" From 1a802fcaf1fbbd911d23eb41a7cf48a79352b1a5 Mon Sep 17 00:00:00 2001 From: A Holt Date: Wed, 13 Dec 2017 06:34:12 -0500 Subject: [PATCH 21/27] which nmcli -> [[ `command -v nmcli` ]] --- iiab-network | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/iiab-network b/iiab-network index 89faa631c..1eed85b8f 100755 --- a/iiab-network +++ b/iiab-network @@ -41,9 +41,13 @@ if [ "$OS" == "centos" ] || [ "$OS" == "fedora" ]; then fi # Ubuntu desktop/others might be using NM (NetworkManager) - split out. -# if [ $(which nmcli) ]; then # syntax fails when multiple lines returned -# if [[ `which nmcli` ]]; then # syntax also works -if which nmcli; then # syntax works great, with "grep -q" too! +#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 c >> iiab-network.log fi @@ -59,7 +63,7 @@ echo "" >> iiab-network.log # Put the same diagnostics on screen, for live operator -if which nmcli; then # syntax works great, with "grep -q" too! +if [[ `command -v nmcli` ]]; then # syntax works great, with "grep -q" too! nmcli d nmcli c fi From 896cb0694049647be1ce7f57b2f6e4213ccb74bb Mon Sep 17 00:00:00 2001 From: A Holt Date: Wed, 13 Dec 2017 06:36:29 -0500 Subject: [PATCH 22/27] Update iiab-network --- iiab-network | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iiab-network b/iiab-network index 1eed85b8f..5263ed58c 100755 --- a/iiab-network +++ b/iiab-network @@ -63,7 +63,7 @@ echo "" >> iiab-network.log # Put the same diagnostics on screen, for live operator -if [[ `command -v nmcli` ]]; then # syntax works great, with "grep -q" too! +if [[ `command -v nmcli` ]]; then nmcli d nmcli c fi From 076135db1a48932205bcf3929b1139ef3337bc48 Mon Sep 17 00:00:00 2001 From: A Holt Date: Wed, 13 Dec 2017 06:39:29 -0500 Subject: [PATCH 23/27] like iiab-network: if [[ `command -v ansible` ]]; then --- iiab-install | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/iiab-install b/iiab-install index 58ac12191..d9d62869f 100755 --- a/iiab-install +++ b/iiab-install @@ -54,7 +54,13 @@ 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 +#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 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}'` From 035bc4e26abdb2474bd482ef3848ee96c0fbe466 Mon Sep 17 00:00:00 2001 From: A Holt Date: Wed, 13 Dec 2017 07:02:04 -0500 Subject: [PATCH 24/27] # to match scripts/ansible --- iiab-install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iiab-install b/iiab-install index d9d62869f..867472a36 100755 --- a/iiab-install +++ b/iiab-install @@ -63,7 +63,7 @@ CURR_ANSIBLE_VER=0 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}'` + CURR_ANSIBLE_VER=`ansible --version | head -1 | awk '{print $2}'` # to match scripts/ansible echo "Found Ansible "$CURR_ANSIBLE_VER"" fi if version_gt $MIN_ANSIBLE_VER $CURR_ANSIBLE_VER ; then From 62bdd1ea2a5e695f73cc53f1629261cbb57736a7 Mon Sep 17 00:00:00 2001 From: A Holt Date: Wed, 13 Dec 2017 07:03:01 -0500 Subject: [PATCH 25/27] # to match iiab-install --- scripts/ansible | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ansible b/scripts/ansible index dc1513704..94ebce04e 100755 --- a/scripts/ansible +++ b/scripts/ansible @@ -61,7 +61,7 @@ if ! which ansible-playbook ; then fi else #CURR_VER=`ansible --version | head -n 1 | cut -f 2 -d " "` - CURR_VER=`ansible --version | head -1 | awk '{print $2}'` + 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 echo "Please use your system's package manager to update ansible" From d7cd912d8709605a6f3528aea5b356fc8af3f4f0 Mon Sep 17 00:00:00 2001 From: A Holt Date: Wed, 13 Dec 2017 07:19:44 -0500 Subject: [PATCH 26/27] vertical spacing of diags fixed in iiab-network.log & live output --- iiab-network | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/iiab-network b/iiab-network index 5263ed58c..33dfecfd8 100755 --- a/iiab-network +++ b/iiab-network @@ -49,25 +49,27 @@ fi #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 + echo >> iiab-network.log nmcli c >> iiab-network.log fi -echo "" >> iiab-network.log ip r >> iiab-network.log -echo "" >> iiab-network.log brctl show >> iiab-network.log +echo >> iiab-network.log echo "run start: $Start" >> iiab-network.log echo "run end: $End" >> iiab-network.log -echo "" >> iiab-network.log -echo "" >> iiab-network.log +echo >> iiab-network.log +echo >> iiab-network.log # Put the same diagnostics on screen, for live operator if [[ `command -v nmcli` ]]; then nmcli d + echo nmcli c fi ip r brctl show +echo echo "run start: $Start" echo "run end: $End" From bcac4919fc2fc18201803c47a2ccd40a1f3b1b5a Mon Sep 17 00:00:00 2001 From: A Holt Date: Wed, 13 Dec 2017 07:25:23 -0500 Subject: [PATCH 27/27] Friendlier live output & to iiab-network.log --- iiab-network | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/iiab-network b/iiab-network index 33dfecfd8..3b3b634f1 100755 --- a/iiab-network +++ b/iiab-network @@ -56,8 +56,8 @@ fi ip r >> iiab-network.log brctl show >> iiab-network.log echo >> iiab-network.log -echo "run start: $Start" >> iiab-network.log -echo "run end: $End" >> iiab-network.log +echo "iiab-network run start: $Start" >> iiab-network.log +echo "iiab-network run end: $End" >> iiab-network.log echo >> iiab-network.log echo >> iiab-network.log @@ -71,5 +71,5 @@ fi ip r brctl show echo -echo "run start: $Start" -echo "run end: $End" +echo "iiab-network run start: $Start" +echo "iiab-network run end: $End"