From 403d4a2ebc23493caa27553a29602fc0c26fb48b Mon Sep 17 00:00:00 2001 From: A Holt Date: Mon, 13 May 2019 11:42:28 -0400 Subject: [PATCH 1/6] Rename ansible-2.6.x to ansible-2.6.x-deprecated --- scripts/{ansible-2.6.x => ansible-2.6.x-deprecated} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename scripts/{ansible-2.6.x => ansible-2.6.x-deprecated} (100%) diff --git a/scripts/ansible-2.6.x b/scripts/ansible-2.6.x-deprecated similarity index 100% rename from scripts/ansible-2.6.x rename to scripts/ansible-2.6.x-deprecated From 72e21fad87aabd2b4aae4a0c964ba7f3654fc997 Mon Sep 17 00:00:00 2001 From: A Holt Date: Mon, 13 May 2019 11:43:36 -0400 Subject: [PATCH 2/6] Create ansible-2.8.x --- scripts/ansible-2.8.x | 104 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 scripts/ansible-2.8.x diff --git a/scripts/ansible-2.8.x b/scripts/ansible-2.8.x new file mode 100644 index 000000000..6b7105225 --- /dev/null +++ b/scripts/ansible-2.8.x @@ -0,0 +1,104 @@ +#!/bin/bash -e + +CURR_VER="undefined" # Ansible version you currently have installed +GOOD_VER="2.8.0" # For XO laptops (pip install) & CentOS (yum install rpm) +# On other OS's we attempt the latest from PPA, which might be more recent + +export DEBIAN_FRONTEND=noninteractive + +echo -e "\n\nYOU ARE RUNNING: /opt/iiab/iiab/scripts/ansible-2.8.x (TO INSTALL ANSIBLE)" +echo -e 'Alternative: /opt/iiab/iiab/scripts/ansible ("for the very latest Ansible")\n' + +echo -e "RECOMMENDED PREREQUISITES:" +echo -e "(1) Verify you're online" +echo -e "(2) Remove all prior versions of Ansible using" +echo -e " 'apt purge ansible' and/or 'pip uninstall ansible'" +echo -e "(3) Remove all lines containing 'ansible' from" +echo -e " /etc/apt/sources.list and /etc/apt/sources.list.d/*\n" + +echo -e "COMPLETE INSTALL INSTRUCTIONS:" +echo -e "https://github.com/iiab/iiab/wiki/IIAB-Installation#do-everything-from-scratch\n" + +if [ $(command -v ansible-playbook) ]; then # "command -v" is POSIX compliant; also catches built-in commands like "cd" + CURR_VER=`ansible --version | head -1 | awk '{print $2}'` # To match iiab-install. Was: CURR_VER=`ansible --version | head -n 1 | cut -f 2 -d " "` + echo -e "CURRENTLY INSTALLED ANSIBLE: $CURR_VER -- LET'S TRY TO UPGRADE IT!" + echo -e "(Internet-in-a-Box requests Ansible $GOOD_VER or higher)\n" + if [ -f /etc/centos-release ] || [ -f /etc/fedora-release ]; then + echo "Please use your system's package manager (or pip if nec) to update Ansible.\n" + exit 0 + elif [ -f /etc/olpc-release ]; then + echo "Please use pip package manager to update Ansible.\n" + exit 0 + fi +else + echo -e "ANSIBLE NOT FOUND ON THIS COMPUTER -- LET'S TRY TO INSTALL IT!" + echo -e "(Internet-in-a-Box requests Ansible $GOOD_VER or higher)\n" +fi + +if [ -f /etc/olpc-release ]; then + yum -y install ca-certificates nss + 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 + # Can above 3 lines be merged into 1 line? + pip install --upgrade pip setuptools wheel #EOL just do it + pip install ansible==$GOOD_VER --disable-pip-version-check +elif [ -f /etc/centos-release ]; then + yum -y install ansible +# 2018-09-07: the next 4 lines aren't needed according to https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#latest-release-via-dnf-or-yum +# 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 https://releases.ansible.com/ansible/rpm/release/epel-7-x86_64/ansible-$GOOD_VER-1.el7.ans.noarch.rpm +#elif [ -f /etc/fedora-release ]; then +# 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 +## Parens are optional, but greatly clarify :) +#elif (grep -qi ubuntu /etc/lsb-release 2> /dev/null) || (grep -qi ubuntu /etc/os-release); then +# apt update +# #apt -y install python-pip python-setuptools python-wheel patch # 2018-09-05: fails on @kananigit's Ubuntu 18.04/Server. Fix @ https://github.com/iiab/iiab/pull/1091 +# apt -y install software-properties-common # adds command "apt-add-repository" +# apt-add-repository -y ppa:ansible/ansible # adds correct line to correct file e.g. adds line "deb http://ppa.launchpad.net/ansible/ansible/ubuntu bionic main" to /etc/apt/sources.list.d/ansible-ubuntu-ansible-bionic.list +## elif UBUNTU MUST REMAIN ABOVE (as Ubuntu ALSO contains /etc/debian_version, which would trigger the line just below) +#elif [ -f /etc/debian_version ] || (grep -qi raspbian /etc/*elease) ; then +#elif [ ! -f /etc/centos-release ] && [ ! -f /etc/fedora-release ] && [ ! -f /etc/olpc-release ]; then +elif [ -f /etc/debian_version ]; then # Includes Debian, Ubuntu & Raspbian + + echo -e "\napt update; install dirmngr; PPA to /etc/apt/sources.list.d/iiab-ansible.list\n" + apt update + apt -y install dirmngr # Raspbian needs. Formerly: python-pip python-setuptools python-wheel patch + echo "deb http://ppa.launchpad.net/ansible/ansible-2.7/ubuntu xenial main" \ + > /etc/apt/sources.list.d/iiab-ansible.list + + echo -e '\nIF YOU FACE ERROR "signatures couldn'"'"'t be verified because the public key is not available" THEN REPEATEDLY RE-RUN "sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 93C4A3FD7BB9C367"\n' + apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 93C4A3FD7BB9C367 + + echo -e "\napt update; apt install ansible\n" + apt update + apt -y --allow-downgrades install ansible + echo -e "\nSUCCESS: verify Ansible using 'ansible --version' and/or 'apt -a list ansible'\n\n" + + # TEMPORARILY USE ANSIBLE 2.4.4 (REMOVE IT WITH "pip uninstall ansible") + #pip install ansible==2.4.4 + + # TEMPORARILY USE ANSIBLE 2.4.2 DUE TO 2.4.3 MEMORY BUG. DETAILS @ https://github.com/iiab/iiab/issues/669 + #echo "Install http://download.iiab.io/packages/ansible_2.4.2.0-1ppa~xenial_all.deb" + #cd /tmp + #wget http://download.iiab.io/packages/ansible_2.4.2.0-1ppa~xenial_all.deb + #apt -y --allow-downgrades install ./ansible_2.4.2.0-1ppa~xenial_all.deb + + echo -e 'PPA source "deb http://ppa.launchpad.net/ansible/ansible-2.7/ubuntu xenial main"' + echo -e "successfully saved to /etc/apt/sources.list.d/iiab-ansible.list\n" + + echo -e "IF *OTHER* ANSIBLE SOURCES APPEAR BELOW, PLEASE MANUALLY REMOVE THEM TO" + echo -e "ENSURE ANSIBLE UPDATES CLEANLY: (then re-run this script to be sure!)\n" + grep '^deb .*ansible' /etc/apt/sources.list /etc/apt/sources.list.d/*.list | grep -v '^/etc/apt/sources.list.d/iiab-ansible.list:' || true # Override bash -e (instead of aborting at 1st error) +else + echo -e "\nEXITING: Could not detect your OS (unsupported?)\n" + exit 1 +fi + +# Needed? +mkdir -p /etc/ansible +echo -e '[local]\nlocalhost\n' > /etc/ansible/hosts From 2d03c202f0503400d198d3b77727cbf545e2ff90 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 13 May 2019 11:59:12 -0400 Subject: [PATCH 3/6] scripts/ansible-2.8.x 644 -> 755 --- scripts/ansible-2.8.x | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 scripts/ansible-2.8.x diff --git a/scripts/ansible-2.8.x b/scripts/ansible-2.8.x old mode 100644 new mode 100755 From 359e35f5361a44a0d4c7585495dc91a1543e0833 Mon Sep 17 00:00:00 2001 From: A Holt Date: Mon, 13 May 2019 12:08:01 -0400 Subject: [PATCH 4/6] fix PPA URL's from ansible-2.7 -> ansible-2.8 --- scripts/ansible-2.8.x | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/ansible-2.8.x b/scripts/ansible-2.8.x index 6b7105225..ddb3621a3 100755 --- a/scripts/ansible-2.8.x +++ b/scripts/ansible-2.8.x @@ -68,7 +68,7 @@ elif [ -f /etc/debian_version ]; then # Includes Debian, Ubuntu & Raspbian echo -e "\napt update; install dirmngr; PPA to /etc/apt/sources.list.d/iiab-ansible.list\n" apt update apt -y install dirmngr # Raspbian needs. Formerly: python-pip python-setuptools python-wheel patch - echo "deb http://ppa.launchpad.net/ansible/ansible-2.7/ubuntu xenial main" \ + echo "deb http://ppa.launchpad.net/ansible/ansible-2.8/ubuntu xenial main" \ > /etc/apt/sources.list.d/iiab-ansible.list echo -e '\nIF YOU FACE ERROR "signatures couldn'"'"'t be verified because the public key is not available" THEN REPEATEDLY RE-RUN "sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 93C4A3FD7BB9C367"\n' @@ -88,7 +88,7 @@ elif [ -f /etc/debian_version ]; then # Includes Debian, Ubuntu & Raspbian #wget http://download.iiab.io/packages/ansible_2.4.2.0-1ppa~xenial_all.deb #apt -y --allow-downgrades install ./ansible_2.4.2.0-1ppa~xenial_all.deb - echo -e 'PPA source "deb http://ppa.launchpad.net/ansible/ansible-2.7/ubuntu xenial main"' + echo -e 'PPA source "deb http://ppa.launchpad.net/ansible/ansible-2.8/ubuntu xenial main"' echo -e "successfully saved to /etc/apt/sources.list.d/iiab-ansible.list\n" echo -e "IF *OTHER* ANSIBLE SOURCES APPEAR BELOW, PLEASE MANUALLY REMOVE THEM TO" From 45769b15b820b465d476411083e2ba905803dd27 Mon Sep 17 00:00:00 2001 From: Tim Moody Date: Mon, 13 May 2019 14:02:25 -0400 Subject: [PATCH 5/6] don't add to menu unless new --- .../osm-vector-maps/templates/iiab-update-map | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/roles/osm-vector-maps/templates/iiab-update-map b/roles/osm-vector-maps/templates/iiab-update-map index ffd7de2db..02ca0e02d 100755 --- a/roles/osm-vector-maps/templates/iiab-update-map +++ b/roles/osm-vector-maps/templates/iiab-update-map @@ -32,15 +32,20 @@ map_doc_root = '/library/www/osm-vector-maps' # map_catalog will be global, assumed always available map_catalog = {} map_menu_def_list = [] +previous_idx = {} # track new regions so we don't thrash on adding to menu def main(): global map_menu_def_list + global previous_idx + get_map_catalog() #print(json.dumps(map_catalog,indent=2)) map_menu_def_list = get_menu_def_names() print(json.dumps(map_menu_def_list,indent=2)) + read_vector_map_idx() + installed_maps = get_installed_regions() print(installed_maps) @@ -59,13 +64,13 @@ def main(): else: item = map_catalog['regions'][region] menu_ref = item['perma_ref'] - if not (region in map_menu_def_list): + if not (menu_ref in map_menu_def_list): print('creating menu def for %s'%item['perma_ref']) create_menu_def(region,item['perma_ref'] + '.json') - if fetch_menu_json_value('autoupdate_menu'): + # if autoupdate allowed and this is a new region then add to home menu + if fetch_menu_json_value('autoupdate_menu') and item['perma_ref'] not in previous_idx: print('autoudate of menu items is enabled:%s. Adding %s'%(\ fetch_menu_json_value('autoupdate_menu'),region,)) - # verify this menu def is on home page menus.update_menu_json(menu_ref) def get_map_catalog(): @@ -90,9 +95,9 @@ def get_menu_def_names(intended_use='map'): print(readstr) if data.get('intended_use','') != intended_use: continue - map_name = data.get('name','') + map_name = data.get('map_name','') if map_name != '': - menu_def_list.append(data['name']) + menu_def_list.append(map_name) return menu_def_list def get_installed_regions(): @@ -107,6 +112,12 @@ def get_installed_regions(): installed.append('maplist') return installed +def read_vector_map_idx(): + global previous_idx + with open(vector_map_idx_dir + '/vector-map-idx.json','r') as idx: + str = idx.read() + previous_idx = json.loads(str) + def write_vector_map_idx(installed_maps): map_dict ={} idx_dict = {} From fadba3c7b35acab3d117d4cf41f9dc72b6619c6d Mon Sep 17 00:00:00 2001 From: Tim Moody Date: Mon, 13 May 2019 14:23:14 -0400 Subject: [PATCH 6/6] handle first time when idx file does not exist --- roles/osm-vector-maps/templates/iiab-update-map | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/roles/osm-vector-maps/templates/iiab-update-map b/roles/osm-vector-maps/templates/iiab-update-map index 02ca0e02d..3d72bba62 100755 --- a/roles/osm-vector-maps/templates/iiab-update-map +++ b/roles/osm-vector-maps/templates/iiab-update-map @@ -114,9 +114,12 @@ def get_installed_regions(): def read_vector_map_idx(): global previous_idx - with open(vector_map_idx_dir + '/vector-map-idx.json','r') as idx: - str = idx.read() - previous_idx = json.loads(str) + try: # will fail first time + with open(vector_map_idx_dir + '/vector-map-idx.json','r') as idx: + str = idx.read() + previous_idx = json.loads(str) + except: + pass def write_vector_map_idx(installed_maps): map_dict ={}