From d4ed2cfa9830f86cb3045194fa7d212f52a4a8d7 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Wed, 21 Aug 2019 13:31:45 -0500 Subject: [PATCH 01/43] move repo creation --- iiab | 23 +---------------------- install.txt | 27 +++++++++++++++++++++++---- 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/iiab b/iiab index 0f331869..b17acaa7 100755 --- a/iiab +++ b/iiab @@ -181,28 +181,7 @@ if [ -e /dev/mmcblk0p2 ]; then fi # H. Clone 3 IIAB repos -echo -e "\n\nDOWNLOAD (CLONE) IIAB'S 3 KEY REPOS INTO $BASEDIR ...\n" -$APT_PATH/apt -y install git -mkdir -p $BASEDIR -cd $BASEDIR -echo -if [ -d iiab ]; then - echo -e "REPO EXISTS? Consider 'cd /opt/iiab/iiab; git pull'" -else - git clone https://github.com/iiab/iiab --depth 1 -fi -echo -if [ -d iiab-admin-console ]; then - echo -e "REPO EXISTS? Consider 'cd /opt/iiab/iiab-admin-console; git pull'" -else - git clone https://github.com/iiab/iiab-admin-console --depth 1 -fi -echo -if [ -d iiab-factory ]; then - echo -e "REPO EXISTS? Consider 'cd /opt/iiab/iiab-factory; git pull'" -else - git clone https://github.com/iiab/iiab-factory --depth 1 -fi +# moved to install.txt # I. Install Ansible + 2 IIAB repos echo -e "\n\nINSTALL ANSIBLE + CORE IIAB SOFTWARE + ADMIN CONSOLE / CONTENT PACK MENUS...\n" diff --git a/install.txt b/install.txt index df9fc545..0e59060e 100644 --- a/install.txt +++ b/install.txt @@ -44,10 +44,29 @@ set -e # Exit on error (avoids snowballing) export DEBIAN_FRONTEND=noninteractive # Bypass (most!) interactive questions -# Save script to /usr/sbin/iiab (easy resume/continue mnemonic 'sudo iiab') -mv /usr/sbin/iiab /usr/sbin/iiab.old || true # Overrides 'set -e' -curl https://raw.githubusercontent.com/iiab/iiab-factory/master/iiab > /usr/sbin/iiab -chmod 0744 /usr/sbin/iiab +-# H. Clone 3 IIAB repos +echo -e "\n\nDOWNLOAD (CLONE) IIAB'S 3 KEY REPOS INTO /opt/iiab ...\n" +apt -y install git +mkdir -p /opt/iiab +cd /opt/iiab/ +echo +if [ -d iiab ]; then + echo -e "REPO EXISTS? Consider 'cd /opt/iiab/iiab; git pull'" +else + git clone https://github.com/iiab/iiab --depth 1 +fi +echo +if [ -d iiab-admin-console ]; then + echo -e "REPO EXISTS? Consider 'cd /opt/iiab/iiab-admin-console; git pull'" +else + git clone https://github.com/iiab/iiab-admin-console --depth 1 +fi +echo +if [ -d iiab-factory ]; then + echo -e "REPO EXISTS? Consider 'cd /opt/iiab/iiab-factory; git pull'" +else + git clone https://github.com/iiab/iiab-factory --depth 1 + ln -s iiab /usr/sbin/iiab # Run install script! /usr/sbin/iiab From 9641f6ab478f793ca58304a3e5d241c7d3f23cef Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Wed, 21 Aug 2019 14:11:10 -0500 Subject: [PATCH 02/43] cp in place of wget, timeout for automation, make editing opt-in --- iiab | 18 +++++++++--------- install.txt | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/iiab b/iiab index b17acaa7..3be15dd6 100755 --- a/iiab +++ b/iiab @@ -114,27 +114,27 @@ else echo -e '(IIAB apps) are suggested during installation?" within http://FAQ.IIAB.IO\n' echo -n "Please type 1, 2 or 3 then press [ENTER]: " - read local_vars_size < /dev/tty + read -t 5 local_vars_size < /dev/tty echo case $local_vars_size in 1) - wget -O local_vars.yml https://github.com/iiab/iiab/raw/master/vars/local_vars_min.yml + cp vars/local_vars_min.yml local_vars.yml ;; 3) - wget -O local_vars.yml https://github.com/iiab/iiab/raw/master/vars/local_vars_big.yml + cp vars/local_vars_big.yml local_vars.yml ;; *) - wget -O local_vars.yml https://github.com/iiab/iiab/raw/master/vars/local_vars_medium.yml + cp vars/local_vars_medium.yml local_vars.yml ;; esac echo -en "\nEdit $CONFDIR/local_vars.yml to customize your Internet-in-a-Box? [Y/n] " read ans < /dev/tty - if [ "$ans" != "n" ] && [ "$ans" != "N" ]; then - echo -e "\n1) PLEASE RUN: sudo nano $CONFDIR/local_vars.yml\n" - - echo -e "2) After you're done editing, RUN 'sudo iiab' TO CONTINUE!\n" - exit 0 + echo -en "\nEdit /etc/iiab/local_vars.yml to customize your Internet-in-a-Box? [Y/n] " + read -t 5 ans < /dev/tty + if [ "$ans" == "y" ] || [ "$ans" == "Y" ]; then + echo "ctrl x to save and exit" + nano /etc/iiab/local_vars.yml\n" fi fi diff --git a/install.txt b/install.txt index 0e59060e..7a18e896 100644 --- a/install.txt +++ b/install.txt @@ -46,7 +46,7 @@ export DEBIAN_FRONTEND=noninteractive # Bypass (most!) interactive questions -# H. Clone 3 IIAB repos echo -e "\n\nDOWNLOAD (CLONE) IIAB'S 3 KEY REPOS INTO /opt/iiab ...\n" -apt -y install git +apt -y install git nano mkdir -p /opt/iiab cd /opt/iiab/ echo From d4dae2fc21c6ca63d15d63b04bab07c75ea7226c Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Wed, 21 Aug 2019 14:57:47 -0500 Subject: [PATCH 03/43] introduce --reinstall to iiab --- iiab | 22 +++++++++++++++------- install.txt | 22 ++++++++++++++-------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/iiab b/iiab index 3be15dd6..31a7fd2f 100755 --- a/iiab +++ b/iiab @@ -128,8 +128,6 @@ else ;; esac - echo -en "\nEdit $CONFDIR/local_vars.yml to customize your Internet-in-a-Box? [Y/n] " - read ans < /dev/tty echo -en "\nEdit /etc/iiab/local_vars.yml to customize your Internet-in-a-Box? [Y/n] " read -t 5 ans < /dev/tty if [ "$ans" == "y" ] || [ "$ans" == "Y" ]; then @@ -180,9 +178,19 @@ if [ -e /dev/mmcblk0p2 ]; then tune2fs -m 1 /dev/mmcblk0p2 fi -# H. Clone 3 IIAB repos -# moved to install.txt - +# H. update 2 IIAB repos +if [ $1 == --reinstall ]; then + cd $BASEDIR + if [ -d iiab ]; then + cd iiab + git pull + fi + cd $BASEDIR + if [ -d iiab-admin-console ]; then + cd iiab-admin-console + git pull + fi +fi # I. Install Ansible + 2 IIAB repos echo -e "\n\nINSTALL ANSIBLE + CORE IIAB SOFTWARE + ADMIN CONSOLE / CONTENT PACK MENUS...\n" @@ -199,9 +207,9 @@ echo -e "│ echo -e "│ child script ./iiab-install -- both avoid repeating any of the 9 stages. │" echo -e "│ │" echo -e "└──────────────────────────────────────────────────────────────────────────────┘" -cd $BASEDIR/iiab/ -./iiab-install $@ +cd $BASEDIR/iiab/ +./iiab-install $1 echo -e "Install Admin Console... (also runs iiab-get-kiwix-cat to d/l Kiwix catalog, and installs Dynamic Menuing for /library/www/html/home/index.html)\n" if [ ! -f $FLAGDIR/iiab-admin-console-complete ]; then cd $BASEDIR/iiab-admin-console diff --git a/install.txt b/install.txt index 7a18e896..198a6d16 100644 --- a/install.txt +++ b/install.txt @@ -50,23 +50,29 @@ apt -y install git nano mkdir -p /opt/iiab cd /opt/iiab/ echo +if [ -d iiab-factory ]; then + echo -e "REPO iiab-factory EXISTS? -- updating" + cd iiab-factory + git pull +else + echo -e "Cloning iiab-factory" + git clone https://github.com/iiab/iiab-factory --depth 1 + ln -s iiab /usr/sbin/iiab +fi +cd /opt/iiab/ +echo if [ -d iiab ]; then - echo -e "REPO EXISTS? Consider 'cd /opt/iiab/iiab; git pull'" + echo -e "REPO iiab EXISTS? Consider 'sudo iiab --reinstall'" else git clone https://github.com/iiab/iiab --depth 1 fi +cd /opt/iiab/ echo if [ -d iiab-admin-console ]; then - echo -e "REPO EXISTS? Consider 'cd /opt/iiab/iiab-admin-console; git pull'" + echo -e "REPO iiab-admin-console EXISTS? Consider 'sudo iiab --reinstall'" else git clone https://github.com/iiab/iiab-admin-console --depth 1 fi -echo -if [ -d iiab-factory ]; then - echo -e "REPO EXISTS? Consider 'cd /opt/iiab/iiab-factory; git pull'" -else - git clone https://github.com/iiab/iiab-factory --depth 1 - ln -s iiab /usr/sbin/iiab # Run install script! /usr/sbin/iiab From 291dbe441c53e2cfbced1da127bd8c964fbd9e0c Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Wed, 21 Aug 2019 15:00:57 -0500 Subject: [PATCH 04/43] timeout for automation2 --- iiab | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iiab b/iiab index 31a7fd2f..e0696a17 100755 --- a/iiab +++ b/iiab @@ -167,7 +167,7 @@ fi cat /tmp/apt.stdout # "All packages are up to date.\n" echo -ne "\nHit [ENTER] to confirm you'll TRY TO RERUN 'sudo iiab' IF THERE IS A PROBLEM: " -read ans < /dev/tty +read -t 5 ans < /dev/tty ######################### INTERACTIVE STUFF IS ABOVE ######################### From d717b816f0e7966b22c8b678de9f2ebcb21bda03 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Wed, 21 Aug 2019 15:05:55 -0500 Subject: [PATCH 05/43] timeout for automation3 --- iiab | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iiab b/iiab index e0696a17..50faeb42 100755 --- a/iiab +++ b/iiab @@ -63,7 +63,7 @@ if check_user_pwd "pi" "raspberry"; then echo -e "\n\nRaspberry Pi's are COMPROMISED often if the default password is not changed!\n" echo -n "What password do you want for GNU/Linux user 'pi' ? " - read ans < /dev/tty # Whines but doesn't change password if [Enter] + read -t 5 ans < /dev/tty # Whines but doesn't change password if [Enter] echo pi:"$ans" | chpasswd || true # Overrides 'set -e' fi @@ -80,7 +80,7 @@ if check_user_pwd "iiab-admin" "g0adm1n"; then echo -e "This is for login to Internet-in-a-Box's Admin Console (http://box.lan/admin)\n" echo -n "What password do you want for GNU/Linux user 'iiab-admin' ? " - read ans < /dev/tty # Whines but doesn't change password if [Enter] + read -t 5 ans < /dev/tty # Whines but doesn't change password if [Enter] echo iiab-admin:"$ans" | chpasswd || true # Overrides 'set -e' fi From e335b1c16a34ab99c0b2821ba49557344dcc7433 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sat, 24 Aug 2019 16:11:06 -0500 Subject: [PATCH 06/43] port post-install --- iiab | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/iiab b/iiab index 50faeb42..442b1131 100755 --- a/iiab +++ b/iiab @@ -47,6 +47,12 @@ BASEDIR=/opt/iiab CONFDIR=/etc/iiab FLAGDIR=$CONFDIR/install-flags APT_PATH=/usr/bin # Avoids problematic /usr/local/bin/apt on Linux Mint +REINSTALL="" + +if [ "$1" = "--reinstall" ]; then + rm $FLAGS/*complete + REINSTALL="--reinstall" +fi # A. Subroutine for B. and D. Returns true (0) if username ($1) exists with password ($2) check_user_pwd() { @@ -118,24 +124,24 @@ else echo case $local_vars_size in 1) - cp vars/local_vars_min.yml local_vars.yml + cp $BASE/iiab/vars/local_vars_min.yml local_vars.yml ;; 3) - cp vars/local_vars_big.yml local_vars.yml + cp $BASE/iiab/vars/local_vars_big.yml local_vars.yml ;; *) - cp vars/local_vars_medium.yml local_vars.yml + cp $BASE/iiab/vars/local_vars_medium.yml local_vars.yml ;; esac echo -en "\nEdit /etc/iiab/local_vars.yml to customize your Internet-in-a-Box? [Y/n] " read -t 5 ans < /dev/tty if [ "$ans" == "y" ] || [ "$ans" == "Y" ]; then - echo "ctrl x to save and exit" - nano /etc/iiab/local_vars.yml\n" + echo -en "ctrl x to save and exit" + sleep 2 + nano /etc/iiab/local_vars.yml fi fi - # F. Mandate OS SECURITY/UPDATES if 'apt update' has any (IF SO REBOOT) # Educate implementer while waiting for 'apt update' echo -e "\n\n ██████████████████████████████████████████████████████████████████████████████" @@ -143,6 +149,9 @@ echo -e " ██ echo -e " ██ RUN 'sudo iiab' IF THIS INSTALL SCRIPT EVER FAILS, TO TRY TO CONTINUE! ██" echo -e " ██ ██" echo -e " ██████████████████████████████████████████████████████████████████████████████" +if [ -f $FLAGS/iiab-complete ]; then + echo -e " IIAB completed successfully nothing to do.." +fi echo -e "\n\n'apt update' is checking for OS updates...\n" #echo -e "2019-07-11 TEMP WORKAROUND FOR RASPBIAN BUSTER'S testing->stable apt GLITCH...\nDetails @ https://github.com/iiab/iiab/issues/1856\n" @@ -179,7 +188,7 @@ if [ -e /dev/mmcblk0p2 ]; then fi # H. update 2 IIAB repos -if [ $1 == --reinstall ]; then +if [ $REINSTALL == --reinstall ]; then cd $BASEDIR if [ -d iiab ]; then cd iiab @@ -191,6 +200,7 @@ if [ $1 == --reinstall ]; then git pull fi fi + # I. Install Ansible + 2 IIAB repos echo -e "\n\nINSTALL ANSIBLE + CORE IIAB SOFTWARE + ADMIN CONSOLE / CONTENT PACK MENUS...\n" @@ -207,9 +217,9 @@ echo -e "│ echo -e "│ child script ./iiab-install -- both avoid repeating any of the 9 stages. │" echo -e "│ │" echo -e "└──────────────────────────────────────────────────────────────────────────────┘" - cd $BASEDIR/iiab/ -./iiab-install $1 +./iiab-install $REINSTALL + echo -e "Install Admin Console... (also runs iiab-get-kiwix-cat to d/l Kiwix catalog, and installs Dynamic Menuing for /library/www/html/home/index.html)\n" if [ ! -f $FLAGDIR/iiab-admin-console-complete ]; then cd $BASEDIR/iiab-admin-console From 9be7fa0bc434ff9d8ab4d154fe1d18270bc5861a Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sat, 24 Aug 2019 16:18:04 -0500 Subject: [PATCH 07/43] update flags/readme --- flags/readme | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 flags/readme diff --git a/flags/readme b/flags/readme new file mode 100644 index 00000000..36c41cc9 --- /dev/null +++ b/flags/readme @@ -0,0 +1,5 @@ +The stages of completion are tracked here iiab-install has a built-in tracker so nothing is needed there +iiab-admin-console-complete +kalite-zone-complete +kalite-en.zip-complete +iiab-complete From fddc0ac502b028de5e79eacd03c900defa4542b6 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sat, 24 Aug 2019 21:33:47 -0500 Subject: [PATCH 08/43] always update master branch --- install.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/install.txt b/install.txt index 198a6d16..3fbba26f 100644 --- a/install.txt +++ b/install.txt @@ -51,8 +51,9 @@ mkdir -p /opt/iiab cd /opt/iiab/ echo if [ -d iiab-factory ]; then - echo -e "REPO iiab-factory EXISTS? -- updating" + echo -e "REPO iiab-factory EXISTS? -- updating master branch" cd iiab-factory + git checkout master git pull else echo -e "Cloning iiab-factory" From 1c5b0a1a4795034e3ead54edfe683e65a7df6b8a Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sat, 24 Aug 2019 21:36:21 -0500 Subject: [PATCH 09/43] always update master branch 2 --- iiab | 2 ++ 1 file changed, 2 insertions(+) diff --git a/iiab b/iiab index 442b1131..a9c6856c 100755 --- a/iiab +++ b/iiab @@ -192,11 +192,13 @@ if [ $REINSTALL == --reinstall ]; then cd $BASEDIR if [ -d iiab ]; then cd iiab + git checkout master git pull fi cd $BASEDIR if [ -d iiab-admin-console ]; then cd iiab-admin-console + git checkout master git pull fi fi From 0104d8f1972e67cdb2fb131c7937bc4deec2f67b Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sat, 24 Aug 2019 22:20:12 -0500 Subject: [PATCH 10/43] revert this when mainlined --- install.txt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/install.txt b/install.txt index 3fbba26f..dc0ee784 100644 --- a/install.txt +++ b/install.txt @@ -55,9 +55,16 @@ if [ -d iiab-factory ]; then cd iiab-factory git checkout master git pull + git checkout jv-pi-gen + git pull https://github.com/jvonau/iiab-factory.git pi-gen + else echo -e "Cloning iiab-factory" - git clone https://github.com/iiab/iiab-factory --depth 1 +# git clone https://github.com/iiab/iiab-factory --depth 1 + git clone https://github.com/iiab/iiab-factory + cd iiab-factory + git checkout -b jv-pi-gen master + git pull https://github.com/jvonau/iiab-factory.git pi-gen ln -s iiab /usr/sbin/iiab fi cd /opt/iiab/ From 4907d50d21be09c1a761ee32c9bce789697e2c77 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sat, 24 Aug 2019 22:39:58 -0500 Subject: [PATCH 11/43] revert this when mainlined in iiab --- install.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/install.txt b/install.txt index dc0ee784..ea441c05 100644 --- a/install.txt +++ b/install.txt @@ -72,7 +72,9 @@ echo if [ -d iiab ]; then echo -e "REPO iiab EXISTS? Consider 'sudo iiab --reinstall'" else - git clone https://github.com/iiab/iiab --depth 1 + git clone https://github.com/iiab/iiab --depth 10 + git checkout -b jv-pi-gen master + git pull https://github.com/jvonau/iiab.git pi-gen fi cd /opt/iiab/ echo From a22ec10aea6d16839493a387d6586c0e8ce370f3 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sat, 24 Aug 2019 22:22:57 -0500 Subject: [PATCH 12/43] force iiab symlink creation --- install.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/install.txt b/install.txt index ea441c05..253ed374 100644 --- a/install.txt +++ b/install.txt @@ -57,6 +57,7 @@ if [ -d iiab-factory ]; then git pull git checkout jv-pi-gen git pull https://github.com/jvonau/iiab-factory.git pi-gen + ln -sf iiab /usr/sbin/iiab else echo -e "Cloning iiab-factory" @@ -65,7 +66,7 @@ else cd iiab-factory git checkout -b jv-pi-gen master git pull https://github.com/jvonau/iiab-factory.git pi-gen - ln -s iiab /usr/sbin/iiab + ln -sf iiab /usr/sbin/iiab fi cd /opt/iiab/ echo From bc2612fac164df8c135e277f081d6388d2cec1eb Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sun, 25 Aug 2019 00:02:42 -0500 Subject: [PATCH 13/43] exit if complete & kalite zip feedback --- iiab | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/iiab b/iiab index a9c6856c..3bf14520 100755 --- a/iiab +++ b/iiab @@ -89,6 +89,11 @@ if check_user_pwd "iiab-admin" "g0adm1n"; then read -t 5 ans < /dev/tty # Whines but doesn't change password if [Enter] echo iiab-admin:"$ans" | chpasswd || true # Overrides 'set -e' fi +if [ -f $FLAGSDIR/iiab-complete ]; then + echo -e " IIAB completed successfully nothing to do.." + echo -e " iiab --reinstall if you really want to start over" + exit 0 +fi mkdir -p $FLAGDIR if [ -f $FLAGDIR/iiab-complete ]; then @@ -149,10 +154,6 @@ echo -e " ██ echo -e " ██ RUN 'sudo iiab' IF THIS INSTALL SCRIPT EVER FAILS, TO TRY TO CONTINUE! ██" echo -e " ██ ██" echo -e " ██████████████████████████████████████████████████████████████████████████████" -if [ -f $FLAGS/iiab-complete ]; then - echo -e " IIAB completed successfully nothing to do.." -fi - echo -e "\n\n'apt update' is checking for OS updates...\n" #echo -e "2019-07-11 TEMP WORKAROUND FOR RASPBIAN BUSTER'S testing->stable apt GLITCH...\nDetails @ https://github.com/iiab/iiab/issues/1856\n" #apt -y update || true # Overrides 'set -e' @@ -264,6 +265,8 @@ if [ -d /library/ka-lite ]; then echo -e 'Now installing /tmp/en.zip into /library/ka-lite/content/*\n' kalite manage retrievecontentpack local en en.zip touch $FLAGDIR/kalite-en.zip-complete + else + echo -e 'kalite zip already done' fi fi # WARNING: /tmp/en.zip (and all stuff in /tmp) is auto-deleted during reboots From 7e9a86d5e521d4a203e13ad7311b02a2f52811d0 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sun, 25 Aug 2019 01:25:50 -0500 Subject: [PATCH 14/43] extend timeout for password change and and enter hint --- iiab | 4 +++- install.txt | 10 +++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/iiab b/iiab index 3bf14520..0975a163 100755 --- a/iiab +++ b/iiab @@ -86,7 +86,9 @@ if check_user_pwd "iiab-admin" "g0adm1n"; then echo -e "This is for login to Internet-in-a-Box's Admin Console (http://box.lan/admin)\n" echo -n "What password do you want for GNU/Linux user 'iiab-admin' ? " - read -t 5 ans < /dev/tty # Whines but doesn't change password if [Enter] + echo -n "press [Enter] for no change" + + read -t 15 ans < /dev/tty # Whines but doesn't change password if [Enter] echo iiab-admin:"$ans" | chpasswd || true # Overrides 'set -e' fi if [ -f $FLAGSDIR/iiab-complete ]; then diff --git a/install.txt b/install.txt index 253ed374..9bc85b38 100644 --- a/install.txt +++ b/install.txt @@ -44,7 +44,6 @@ set -e # Exit on error (avoids snowballing) export DEBIAN_FRONTEND=noninteractive # Bypass (most!) interactive questions --# H. Clone 3 IIAB repos echo -e "\n\nDOWNLOAD (CLONE) IIAB'S 3 KEY REPOS INTO /opt/iiab ...\n" apt -y install git nano mkdir -p /opt/iiab @@ -55,18 +54,19 @@ if [ -d iiab-factory ]; then cd iiab-factory git checkout master git pull - git checkout jv-pi-gen + git branch -D jv-pi-gen || true + git checkout -b jv-pi-gen git pull https://github.com/jvonau/iiab-factory.git pi-gen - ln -sf iiab /usr/sbin/iiab + ln -sf /opt/iiab/iiab-factory/iiab /usr/sbin/iiab else echo -e "Cloning iiab-factory" # git clone https://github.com/iiab/iiab-factory --depth 1 git clone https://github.com/iiab/iiab-factory cd iiab-factory - git checkout -b jv-pi-gen master + git checkout -b jv-pi-gen git pull https://github.com/jvonau/iiab-factory.git pi-gen - ln -sf iiab /usr/sbin/iiab + ln -sf /opt/iiab/iiab-factory/iiab /usr/sbin/iiab fi cd /opt/iiab/ echo From 03d30da43b5a70f43c52257756a067aadd73eaaf Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sun, 25 Aug 2019 02:17:49 -0500 Subject: [PATCH 15/43] --non-interactive --- iiab | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/iiab b/iiab index 0975a163..9a61a2e0 100755 --- a/iiab +++ b/iiab @@ -48,6 +48,11 @@ CONFDIR=/etc/iiab FLAGDIR=$CONFDIR/install-flags APT_PATH=/usr/bin # Avoids problematic /usr/local/bin/apt on Linux Mint REINSTALL="" +INTERACTIVE=1 +if [ "$1" = "--non-interactive" ]; then + shift 1 + INTERACTIVE=0 +fi if [ "$1" = "--reinstall" ]; then rm $FLAGS/*complete @@ -84,12 +89,12 @@ if check_user_pwd "iiab-admin" "g0adm1n"; then echo -e "\n\nUser 'iiab-admin' retains default password 'g0adm1n' per http://FAQ.IIAB.IO\n" echo -e "This is for login to Internet-in-a-Box's Admin Console (http://box.lan/admin)\n" - - echo -n "What password do you want for GNU/Linux user 'iiab-admin' ? " - echo -n "press [Enter] for no change" - - read -t 15 ans < /dev/tty # Whines but doesn't change password if [Enter] - echo iiab-admin:"$ans" | chpasswd || true # Overrides 'set -e' + if [ $INTERACTIVE == 1 ]; then + echo -n "What password do you want for GNU/Linux user 'iiab-admin' ? " + echo -n "press [Enter] for no change" + read -t 15 ans < /dev/tty # Whines but doesn't change password if [Enter] + echo iiab-admin:"$ans" | chpasswd || true # Overrides 'set -e' + fi fi if [ -f $FLAGSDIR/iiab-complete ]; then echo -e " IIAB completed successfully nothing to do.." @@ -167,20 +172,22 @@ if [ $(wc -c < /tmp/apt.stderr) -gt 82 ]; then # apt.stderr typically contain exit 1 elif grep -q 'apt list --upgradable' /tmp/apt.stdout; then # apt.stdout typically contains {"All packages are up to date.\n" [even if primary locale is French & Hindi!], "Todos los paquetes están actualizados.\n", "所有软件包均为最新。\n"} ...OR... {"5 packages can be upgraded. Run 'apt list --upgradable' to see them.\n" [even if primary locale is French & Hindi!], "Se puede actualizar 1 paquete. Ejecute «apt list --upgradable» para verlo.\n", "有 1 个软件包可以升级。请执行 ‘apt list --upgradable’ 来查看它们。\n"} cat /tmp/apt.stdout - echo -e "\nYour OS will now be upgraded...this takes time. THEN IT WILL AUTO-REBOOT.\n" - - echo -n "Hit [ENTER] to confirm you'll RUN 'sudo iiab' AFTER IT REBOOTS: " - read ans < /dev/tty - echo - $APT_PATH/apt -y dist-upgrade - reboot - exit 0 # Nec to avoid both output lines below (that confuse implementers!) + if [ "$INTERACTIVE" == 1 ]; then + echo -e "\nYour OS will now be upgraded...this takes time. THEN IT WILL AUTO-REBOOT.\n" + echo -n "Hit [ENTER] to confirm you'll RUN 'sudo iiab' AFTER IT REBOOTS: " + read ans < /dev/tty + echo + apt -y dist-upgrade + reboot + exit 0 # Nec to avoid both output lines below (that confuse implementers!) + fi fi cat /tmp/apt.stdout # "All packages are up to date.\n" -echo -ne "\nHit [ENTER] to confirm you'll TRY TO RERUN 'sudo iiab' IF THERE IS A PROBLEM: " -read -t 5 ans < /dev/tty - +if [ $INTERACTIVE == 1 ]; then + echo -ne "\nHit [ENTER] to confirm you'll TRY TO RERUN 'sudo iiab' IF THERE IS A PROBLEM: " + read -t 5 ans < /dev/tty +fi ######################### INTERACTIVE STUFF IS ABOVE ######################### # G. If RPi, lower reserve disk space from ~5% to 1% From 3c44c75fbbab19d4d8d75658482369aa8cf5b910 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sat, 5 Oct 2019 17:05:01 -0500 Subject: [PATCH 16/43] clone off of release branch and setup master --- install.txt | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/install.txt b/install.txt index 9bc85b38..3e1dcc83 100644 --- a/install.txt +++ b/install.txt @@ -41,48 +41,52 @@ # IIAB Development Team # http://FAQ.IIAB.IO +# Copied from: https://github.com/jvonau/iiab-factory/blob/jv-pi-gen/install.txt set -e # Exit on error (avoids snowballing) export DEBIAN_FRONTEND=noninteractive # Bypass (most!) interactive questions +BASE=/opt/iiab -echo -e "\n\nDOWNLOAD (CLONE) IIAB'S 3 KEY REPOS INTO /opt/iiab ...\n" +echo -e "\n\nDOWNLOAD (CLONE) IIAB'S 3 KEY REPOS INTO $BASE ...\n" apt -y install git nano -mkdir -p /opt/iiab -cd /opt/iiab/ +mkdir -p $BASE +cd $BASE echo if [ -d iiab-factory ]; then echo -e "REPO iiab-factory EXISTS? -- updating master branch" cd iiab-factory git checkout master git pull - git branch -D jv-pi-gen || true - git checkout -b jv-pi-gen - git pull https://github.com/jvonau/iiab-factory.git pi-gen - ln -sf /opt/iiab/iiab-factory/iiab /usr/sbin/iiab - + git branch -D release-7.2 || true + git checkout -b release-7.2 + cp /opt/iiab/iiab-factory/iiab /usr/sbin/iiab else echo -e "Cloning iiab-factory" -# git clone https://github.com/iiab/iiab-factory --depth 1 - git clone https://github.com/iiab/iiab-factory + git clone https://github.com/iiab/iiab-factory --depth 1 cd iiab-factory - git checkout -b jv-pi-gen - git pull https://github.com/jvonau/iiab-factory.git pi-gen - ln -sf /opt/iiab/iiab-factory/iiab /usr/sbin/iiab + git checkout -b release-7.2 + cp /opt/iiab/iiab-factory/iiab /usr/sbin/iiab fi -cd /opt/iiab/ +cd $BASE echo if [ -d iiab ]; then echo -e "REPO iiab EXISTS? Consider 'sudo iiab --reinstall'" else - git clone https://github.com/iiab/iiab --depth 10 - git checkout -b jv-pi-gen master - git pull https://github.com/jvonau/iiab.git pi-gen + git clone https://github.com/iiab/iiab --depth 10 --branch release-7.2 + git checkout -b master + git config branch.master.remote origin + git config branch.master.merge refs/heads/master + git checkout release-7.2 fi -cd /opt/iiab/ +cd $BASE echo if [ -d iiab-admin-console ]; then echo -e "REPO iiab-admin-console EXISTS? Consider 'sudo iiab --reinstall'" else - git clone https://github.com/iiab/iiab-admin-console --depth 1 + git clone https://github.com/iiab/iiab-admin-console --depth 1 --branch master + git checkout -b release-7.2 +# git config branch.master.remote origin +# git config branch.master.merge refs/heads/master +# git checkout v0.3.7 fi # Run install script! From dd1e259e86b77846ea087ce5ac49c218cc9fab33 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sat, 5 Oct 2019 19:36:28 -0500 Subject: [PATCH 17/43] setup git upgrade path --- iiab | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 62 insertions(+), 5 deletions(-) diff --git a/iiab b/iiab index 9a61a2e0..8bd61504 100755 --- a/iiab +++ b/iiab @@ -49,16 +49,78 @@ FLAGDIR=$CONFDIR/install-flags APT_PATH=/usr/bin # Avoids problematic /usr/local/bin/apt on Linux Mint REINSTALL="" INTERACTIVE=1 +UPGRADE=0 if [ "$1" = "--non-interactive" ]; then shift 1 INTERACTIVE=0 fi +if [ "$1" = "--upgrade" ]; then + shift 1 + rm $FLAGS/*complete + REINSTALL="--reinstall" + UPGRADE=1 +fi + if [ "$1" = "--reinstall" ]; then rm $FLAGS/*complete REINSTALL="--reinstall" fi +if [ -f $FLAGS/iiab-complete ]; then + echo -e " IIAB completed successfully nothing to do.." + echo -e " iiab --reinstall if you really want to start over" + exit 0 +fi + +check_branch(){ + git branch | grep release-7 | wc -l +} + +use_master(){ + cd $BASE + if [ -d iiab ]; then + cd iiab + git checkout -b master || true # covers older curls of release-7.0 + git config branch.master.remote origin # covers older curls of release-7.0 + git config branch.master.merge refs/heads/master # covers older curls of release-7.0 + git checkout master + git pull + fi + cd $BASE + if [ -d iiab-admin-console ]; then + cd iiab-admin-console + git checkout -b master || true # covers older curls of release-7.0 + git config branch.master.remote origin # covers older curls of release-7.0 + git config branch.master.merge refs/heads/master # covers older curls of release-7.0 + git checkout master + git pull + fi +} + +if check_branch == 1; then + echo -e "found release-7.X branch would you like (re)install using the latest master?[Y/n]" + ans="" + if [ $INTERACTIVE == 1 ]; then + read -t 5 ans < /dev/tty + fi + if [ "$ans" == "y" ] || [ "$ans" == "Y" ]; then + use_master + else + echo "remaning on release-7.X branch updating" + cd $BASE/iiab + git checkout release-7.0 + git pull + cd $BASE/iiab-admin-console + git checkout v0.3.7 + git pull + fi +fi + +if [ $UPGRADE == 1 ]; then + use_master +fi + # A. Subroutine for B. and D. Returns true (0) if username ($1) exists with password ($2) check_user_pwd() { # $meth (hashing method) is typically '6' which implies 5000 rounds @@ -96,11 +158,6 @@ if check_user_pwd "iiab-admin" "g0adm1n"; then echo iiab-admin:"$ans" | chpasswd || true # Overrides 'set -e' fi fi -if [ -f $FLAGSDIR/iiab-complete ]; then - echo -e " IIAB completed successfully nothing to do.." - echo -e " iiab --reinstall if you really want to start over" - exit 0 -fi mkdir -p $FLAGDIR if [ -f $FLAGDIR/iiab-complete ]; then From 3c477f2a0aad03b5eb6679ea38cfa0e94f3ea8b3 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sat, 5 Oct 2019 19:54:11 -0500 Subject: [PATCH 18/43] use true for file that may not be present --- iiab | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/iiab b/iiab index 8bd61504..adac3747 100755 --- a/iiab +++ b/iiab @@ -57,22 +57,16 @@ fi if [ "$1" = "--upgrade" ]; then shift 1 - rm $FLAGS/*complete + rm $FLAGS/iiab*complete || true REINSTALL="--reinstall" UPGRADE=1 fi if [ "$1" = "--reinstall" ]; then - rm $FLAGS/*complete + rm $FLAGS/iiab*complete || true REINSTALL="--reinstall" fi -if [ -f $FLAGS/iiab-complete ]; then - echo -e " IIAB completed successfully nothing to do.." - echo -e " iiab --reinstall if you really want to start over" - exit 0 -fi - check_branch(){ git branch | grep release-7 | wc -l } @@ -121,6 +115,12 @@ if [ $UPGRADE == 1 ]; then use_master fi +if [ -f $FLAGS/iiab-complete ]; then + echo -e " IIAB completed successfully nothing to do.." + echo -e " iiab --reinstall if you really want to start over" + exit 0 +fi + # A. Subroutine for B. and D. Returns true (0) if username ($1) exists with password ($2) check_user_pwd() { # $meth (hashing method) is typically '6' which implies 5000 rounds From df83182df120b17fb1333b7c8221dce42563bd18 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Mon, 14 Oct 2019 22:04:37 -0500 Subject: [PATCH 19/43] refactor git branching --- iiab | 48 +++++++++++++++++++----------------------------- 1 file changed, 19 insertions(+), 29 deletions(-) diff --git a/iiab b/iiab index adac3747..6517cd8d 100755 --- a/iiab +++ b/iiab @@ -49,17 +49,16 @@ FLAGDIR=$CONFDIR/install-flags APT_PATH=/usr/bin # Avoids problematic /usr/local/bin/apt on Linux Mint REINSTALL="" INTERACTIVE=1 -UPGRADE=0 +UPDATE=0 if [ "$1" = "--non-interactive" ]; then shift 1 INTERACTIVE=0 fi -if [ "$1" = "--upgrade" ]; then +if [ "$1" = "--update" ]; then shift 1 rm $FLAGS/iiab*complete || true - REINSTALL="--reinstall" - UPGRADE=1 + UPDATE=1 fi if [ "$1" = "--reinstall" ]; then @@ -68,6 +67,7 @@ if [ "$1" = "--reinstall" ]; then fi check_branch(){ + cd $BASE/iiab git branch | grep release-7 | wc -l } @@ -78,8 +78,6 @@ use_master(){ git checkout -b master || true # covers older curls of release-7.0 git config branch.master.remote origin # covers older curls of release-7.0 git config branch.master.merge refs/heads/master # covers older curls of release-7.0 - git checkout master - git pull fi cd $BASE if [ -d iiab-admin-console ]; then @@ -87,6 +85,19 @@ use_master(){ git checkout -b master || true # covers older curls of release-7.0 git config branch.master.remote origin # covers older curls of release-7.0 git config branch.master.merge refs/heads/master # covers older curls of release-7.0 + fi +} + +update_master(){ + cd $BASEDIR + if [ -d iiab ]; then + cd iiab + git checkout master + git pull + fi + cd $BASEDIR + if [ -d iiab-admin-console ]; then + cd iiab-admin-console git checkout master git pull fi @@ -104,15 +115,10 @@ if check_branch == 1; then echo "remaning on release-7.X branch updating" cd $BASE/iiab git checkout release-7.0 - git pull - cd $BASE/iiab-admin-console - git checkout v0.3.7 - git pull - fi fi -if [ $UPGRADE == 1 ]; then - use_master +if [ $UPDATE == 1 ]; then + update_master fi if [ -f $FLAGS/iiab-complete ]; then @@ -254,22 +260,6 @@ if [ -e /dev/mmcblk0p2 ]; then tune2fs -m 1 /dev/mmcblk0p2 fi -# H. update 2 IIAB repos -if [ $REINSTALL == --reinstall ]; then - cd $BASEDIR - if [ -d iiab ]; then - cd iiab - git checkout master - git pull - fi - cd $BASEDIR - if [ -d iiab-admin-console ]; then - cd iiab-admin-console - git checkout master - git pull - fi -fi - # I. Install Ansible + 2 IIAB repos echo -e "\n\nINSTALL ANSIBLE + CORE IIAB SOFTWARE + ADMIN CONSOLE / CONTENT PACK MENUS...\n" From 0918e078acb077882a4318faabe83297f43ae54c Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Wed, 8 Apr 2020 06:54:32 -0500 Subject: [PATCH 20/43] disable some questions --- iiab | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/iiab b/iiab index 6517cd8d..1abcfc97 100755 --- a/iiab +++ b/iiab @@ -103,19 +103,19 @@ update_master(){ fi } -if check_branch == 1; then - echo -e "found release-7.X branch would you like (re)install using the latest master?[Y/n]" - ans="" - if [ $INTERACTIVE == 1 ]; then - read -t 5 ans < /dev/tty - fi - if [ "$ans" == "y" ] || [ "$ans" == "Y" ]; then - use_master - else - echo "remaning on release-7.X branch updating" - cd $BASE/iiab - git checkout release-7.0 -fi +#if check_branch == 1; then +# echo -e "found release-7.X branch would you like (re)install using the latest master?[Y/n]" +# ans="" +# if [ $INTERACTIVE == 1 ]; then +# read -t 5 ans < /dev/tty +# fi +# if [ "$ans" == "y" ] || [ "$ans" == "Y" ]; then +# use_master +# else +# echo "remaning on release-7.X branch updating" +# cd $BASE/iiab +# git checkout release-7.0 +#fi if [ $UPDATE == 1 ]; then update_master @@ -195,7 +195,7 @@ else echo -e '(IIAB apps) are suggested during installation?" within http://FAQ.IIAB.IO\n' echo -n "Please type 1, 2 or 3 then press [ENTER]: " - read -t 5 local_vars_size < /dev/tty + read local_vars_size < /dev/tty echo case $local_vars_size in 1) @@ -209,13 +209,13 @@ else ;; esac - echo -en "\nEdit /etc/iiab/local_vars.yml to customize your Internet-in-a-Box? [Y/n] " - read -t 5 ans < /dev/tty - if [ "$ans" == "y" ] || [ "$ans" == "Y" ]; then - echo -en "ctrl x to save and exit" - sleep 2 - nano /etc/iiab/local_vars.yml - fi +# echo -en "\nEdit /etc/iiab/local_vars.yml to customize your Internet-in-a-Box? [Y/n] " +# read -t 5 ans < /dev/tty +# if [ "$ans" == "y" ] || [ "$ans" == "Y" ]; then +# echo -en "ctrl x to save and exit" +# sleep 2 +# nano /etc/iiab/local_vars.yml +# fi fi # F. Mandate OS SECURITY/UPDATES if 'apt update' has any (IF SO REBOOT) # Educate implementer while waiting for 'apt update' From 0329994552e26be3dc9cac2caf2643f397af2de8 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Wed, 8 Apr 2020 07:17:41 -0500 Subject: [PATCH 21/43] --upgrade will do reinstall --- iiab | 80 ++++++++++++++++++++++++++++------------------------- install.txt | 1 + 2 files changed, 44 insertions(+), 37 deletions(-) diff --git a/iiab b/iiab index 1abcfc97..d64ea74b 100755 --- a/iiab +++ b/iiab @@ -50,15 +50,17 @@ APT_PATH=/usr/bin # Avoids problematic /usr/local/bin/apt on Linux Mint REINSTALL="" INTERACTIVE=1 UPDATE=0 + if [ "$1" = "--non-interactive" ]; then shift 1 INTERACTIVE=0 fi -if [ "$1" = "--update" ]; then +if [ "$1" = "--upgrade" ]; then shift 1 rm $FLAGS/iiab*complete || true UPDATE=1 + REINSTALL="--reinstall" fi if [ "$1" = "--reinstall" ]; then @@ -67,24 +69,23 @@ if [ "$1" = "--reinstall" ]; then fi check_branch(){ - cd $BASE/iiab - git branch | grep release-7 | wc -l + git -C $BASEDIR/iiab branch | grep \* | grep release-7 | wc -l } use_master(){ - cd $BASE + cd $BASEDIR if [ -d iiab ]; then cd iiab - git checkout -b master || true # covers older curls of release-7.0 - git config branch.master.remote origin # covers older curls of release-7.0 - git config branch.master.merge refs/heads/master # covers older curls of release-7.0 + git checkout -b master &> /dev/null || true # covers older curls of release-7.0 + git config branch.master.remote origin || true # covers older curls of release-7.0 + git config branch.master.merge refs/heads/master || true # covers older curls of release-7.0 fi - cd $BASE + cd $BASEDIR if [ -d iiab-admin-console ]; then cd iiab-admin-console - git checkout -b master || true # covers older curls of release-7.0 - git config branch.master.remote origin # covers older curls of release-7.0 - git config branch.master.merge refs/heads/master # covers older curls of release-7.0 + git checkout -b master &> /dev/null || true # covers older curls of release-7.0 + git config branch.master.remote origin || true # covers older curls of release-7.0 + git config branch.master.merge refs/heads/master || true # covers older curls of release-7.0 fi } @@ -92,38 +93,43 @@ update_master(){ cd $BASEDIR if [ -d iiab ]; then cd iiab + echo -e "\nUpdating iiab" git checkout master git pull fi cd $BASEDIR if [ -d iiab-admin-console ]; then + echo -e "\nUpdating iiab-admin-console" cd iiab-admin-console git checkout master git pull fi } -#if check_branch == 1; then -# echo -e "found release-7.X branch would you like (re)install using the latest master?[Y/n]" -# ans="" -# if [ $INTERACTIVE == 1 ]; then -# read -t 5 ans < /dev/tty -# fi -# if [ "$ans" == "y" ] || [ "$ans" == "Y" ]; then -# use_master -# else -# echo "remaning on release-7.X branch updating" -# cd $BASE/iiab -# git checkout release-7.0 -#fi +if [ `check_branch` -gt 0 ]; then + echo -e "\nFound release-7.X branch would you like (re)install using the latest master?" + echo -e "[Y/n]\n" + ans="n" + if [ $INTERACTIVE == 1 ]; then + read -t 5 ans < /dev/tty + fi + if [ "$ans" == "y" ] || [ "$ans" == "Y" ]; then + UPDATE=1 + else + echo "remaning on release-7.X branch updating" + cd $BASEDIR/iiab + git pull + fi +fi if [ $UPDATE == 1 ]; then + use_master update_master fi if [ -f $FLAGS/iiab-complete ]; then echo -e " IIAB completed successfully nothing to do.." - echo -e " iiab --reinstall if you really want to start over" +# echo -e " iiab --reinstall if you really want to start over" exit 0 fi @@ -140,7 +146,6 @@ check_user_pwd() { # B. Ask for password change if pi/raspberry default remains if check_user_pwd "pi" "raspberry"; then echo -e "\n\nRaspberry Pi's are COMPROMISED often if the default password is not changed!\n" - echo -n "What password do you want for GNU/Linux user 'pi' ? " read -t 5 ans < /dev/tty # Whines but doesn't change password if [Enter] echo pi:"$ans" | chpasswd || true # Overrides 'set -e' @@ -199,23 +204,25 @@ else echo case $local_vars_size in 1) - cp $BASE/iiab/vars/local_vars_min.yml local_vars.yml + cp $BASEDIR/iiab/vars/local_vars_min.yml local_vars.yml ;; 3) - cp $BASE/iiab/vars/local_vars_big.yml local_vars.yml + cp $BASEDIR/iiab/vars/local_vars_big.yml local_vars.yml ;; *) - cp $BASE/iiab/vars/local_vars_medium.yml local_vars.yml + cp $BASEDIR/iiab/vars/local_vars_medium.yml local_vars.yml ;; esac -# echo -en "\nEdit /etc/iiab/local_vars.yml to customize your Internet-in-a-Box? [Y/n] " -# read -t 5 ans < /dev/tty -# if [ "$ans" == "y" ] || [ "$ans" == "Y" ]; then + echo -en "\nEdit /etc/iiab/local_vars.yml to customize your Internet-in-a-Box? [Y/n] " + ans="n" + read -t 5 ans < /dev/tty + if [ "$ans" == "y" ] || [ "$ans" == "Y" ]; then + exit 0 # echo -en "ctrl x to save and exit" # sleep 2 # nano /etc/iiab/local_vars.yml -# fi + fi fi # F. Mandate OS SECURITY/UPDATES if 'apt update' has any (IF SO REBOOT) # Educate implementer while waiting for 'apt update' @@ -240,7 +247,7 @@ elif grep -q 'apt list --upgradable' /tmp/apt.stdout; then # apt.stdout typic echo -n "Hit [ENTER] to confirm you'll RUN 'sudo iiab' AFTER IT REBOOTS: " read ans < /dev/tty echo - apt -y dist-upgrade + $APT_PATH -y dist-upgrade reboot exit 0 # Nec to avoid both output lines below (that confuse implementers!) fi @@ -264,8 +271,7 @@ fi echo -e "\n\nINSTALL ANSIBLE + CORE IIAB SOFTWARE + ADMIN CONSOLE / CONTENT PACK MENUS...\n" echo -e "Install Ansible..." -cd $BASEDIR/iiab/scripts/ -./ansible +$BASEDIR/iiab/scripts/ansible echo -e "\n┌──────────────────────────────────────────────────────────────────────────────┐" echo -e "│ │" @@ -280,7 +286,7 @@ cd $BASEDIR/iiab/ ./iiab-install $REINSTALL echo -e "Install Admin Console... (also runs iiab-get-kiwix-cat to d/l Kiwix catalog, and installs Dynamic Menuing for /library/www/html/home/index.html)\n" -if [ ! -f $FLAGDIR/iiab-admin-console-complete ]; then +if [ ! -f $FLAGDIR/iiab-admin-console-complete ] || [ UPDATE == 1 ]; then cd $BASEDIR/iiab-admin-console ./install touch $FLAGDIR/iiab-admin-console-complete diff --git a/install.txt b/install.txt index 3e1dcc83..0661b5d2 100644 --- a/install.txt +++ b/install.txt @@ -71,6 +71,7 @@ echo if [ -d iiab ]; then echo -e "REPO iiab EXISTS? Consider 'sudo iiab --reinstall'" else + cd iiab git clone https://github.com/iiab/iiab --depth 10 --branch release-7.2 git checkout -b master git config branch.master.remote origin From 353d2784ec65a063c498d8cadcb0d71e469649fb Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Tue, 1 Sep 2020 12:34:57 +0100 Subject: [PATCH 22/43] https://github.com/iiab/iiab-factory/pull/133 --- iiab | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/iiab b/iiab index d64ea74b..a4bee85f 100755 --- a/iiab +++ b/iiab @@ -258,6 +258,27 @@ if [ $INTERACTIVE == 1 ]; then echo -ne "\nHit [ENTER] to confirm you'll TRY TO RERUN 'sudo iiab' IF THERE IS A PROBLEM: " read -t 5 ans < /dev/tty 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" +version_gt() { [ "$(printf '%s\n' "$@" | sort -V | head -1)" != "$1" ]; } + +# Verify that Raspbian is running a recent enough kernel. As Raspbian +# kernel 1333 has wifi issues https://github.com/iiab/iiab/issues/2497. +#MIN_RPI_KERN=1336 +MIN_RPI_KERN=1340 +CURR_KERN=`uname -v | awk '{print $1}' | sed -e s'/#//'` +echo "Found Kernel ""$CURR_KERN" +if [ -f /etc/rpi-issue ] && version_gt $MIN_RPI_KERN $CURR_KERN; then + echo -e "\033[31;5mWARNING: Kernel ""$MIN_RPI_KERN"" or higher required with Raspbian.\033[0m" +# echo -e "\033[31;5mPLEASE RUN 'apt update' then 'apt install raspberrypi-kernel' then reboot.\033[0m" + echo -e "\033[31;5mTHEN IF NEC run 'rpi-update' to install a more recent kernel post-install, then reboot.\033[0m" + echo -e "'enter' to continue" + read -t 10 ans < /dev/tty +fi + + ######################### INTERACTIVE STUFF IS ABOVE ######################### # G. If RPi, lower reserve disk space from ~5% to 1% From 4fdfe02ae3b16fd27608f0057585b70aa9aad9a4 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Tue, 1 Sep 2020 15:00:12 +0100 Subject: [PATCH 23/43] Paths --- install.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/install.txt b/install.txt index 0661b5d2..9b629337 100644 --- a/install.txt +++ b/install.txt @@ -47,7 +47,7 @@ export DEBIAN_FRONTEND=noninteractive # Bypass (most!) interactive questions BASE=/opt/iiab echo -e "\n\nDOWNLOAD (CLONE) IIAB'S 3 KEY REPOS INTO $BASE ...\n" -apt -y install git nano +/usr/bin/apt -y install git nano mkdir -p $BASE cd $BASE echo @@ -58,13 +58,13 @@ if [ -d iiab-factory ]; then git pull git branch -D release-7.2 || true git checkout -b release-7.2 - cp /opt/iiab/iiab-factory/iiab /usr/sbin/iiab + cp $BASE/iiab-factory/iiab /usr/sbin/iiab else echo -e "Cloning iiab-factory" git clone https://github.com/iiab/iiab-factory --depth 1 cd iiab-factory git checkout -b release-7.2 - cp /opt/iiab/iiab-factory/iiab /usr/sbin/iiab + cp $BASE/iiab-factory/iiab /usr/sbin/iiab fi cd $BASE echo From ef7c014217f58894c71e2fd7be8e28ba9aee910b Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Tue, 1 Sep 2020 15:19:00 +0100 Subject: [PATCH 24/43] more $INTERACTIVE --- iiab | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/iiab b/iiab index a4bee85f..2bd6313b 100755 --- a/iiab +++ b/iiab @@ -200,7 +200,10 @@ else echo -e '(IIAB apps) are suggested during installation?" within http://FAQ.IIAB.IO\n' echo -n "Please type 1, 2 or 3 then press [ENTER]: " - read local_vars_size < /dev/tty + local_vars_size="" + if [ "$INTERACTIVE" == 1 ]; then + read local_vars_size < /dev/tty + fi echo case $local_vars_size in 1) @@ -216,7 +219,9 @@ else echo -en "\nEdit /etc/iiab/local_vars.yml to customize your Internet-in-a-Box? [Y/n] " ans="n" - read -t 5 ans < /dev/tty + if [ "$INTERACTIVE" == 1 ]; then + read -t 5 ans < /dev/tty + fi if [ "$ans" == "y" ] || [ "$ans" == "Y" ]; then exit 0 # echo -en "ctrl x to save and exit" @@ -250,6 +255,8 @@ elif grep -q 'apt list --upgradable' /tmp/apt.stdout; then # apt.stdout typic $APT_PATH -y dist-upgrade reboot exit 0 # Nec to avoid both output lines below (that confuse implementers!) + else + $APT_PATH -y dist-upgrade fi fi cat /tmp/apt.stdout # "All packages are up to date.\n" @@ -307,7 +314,7 @@ cd $BASEDIR/iiab/ ./iiab-install $REINSTALL echo -e "Install Admin Console... (also runs iiab-get-kiwix-cat to d/l Kiwix catalog, and installs Dynamic Menuing for /library/www/html/home/index.html)\n" -if [ ! -f $FLAGDIR/iiab-admin-console-complete ] || [ UPDATE == 1 ]; then +if [ ! -f $FLAGDIR/iiab-admin-console-complete ] || [ $UPDATE == 1 ]; then cd $BASEDIR/iiab-admin-console ./install touch $FLAGDIR/iiab-admin-console-complete @@ -399,8 +406,9 @@ echo -e "global community, learning from other initiatives in your region and be #echo -e "(over Wi-Fi anyway) until you later run 'iiab-hotspot-off'. CAVEAT: these" #echo -e "two commands only work with Raspberry Pi as of 2019-09-30.\n" -echo -ne "HIT [Enter] TO REBOOT, CONFIRMING YOU'VE" '"photographed" THE ABOVE PARAGRAPHS: ' -read ans < /dev/tty - -# Sets hostname, improves RTC + memory mgmt, starts BitTorrents if needed, etc! -reboot +if [ $INTERACTIVE == 1 ]; then + echo -ne "HIT [Enter] TO REBOOT, CONFIRMING YOU'VE" '"photographed" THE ABOVE PARAGRAPHS: ' + read ans < /dev/tty + # Sets hostname, improves RTC + memory mgmt, starts BitTorrents if needed, etc! + reboot +fi From 6ab4775334ec18eb771798efbf6e1d5b8e431012 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Tue, 1 Sep 2020 15:53:40 +0100 Subject: [PATCH 25/43] use master & branch - sugggest iiab --upgrade --- install.txt | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/install.txt b/install.txt index 9b629337..c1c93abd 100644 --- a/install.txt +++ b/install.txt @@ -56,7 +56,7 @@ if [ -d iiab-factory ]; then cd iiab-factory git checkout master git pull - git branch -D release-7.2 || true + git branch -D release-7.2 &> /dev/null || true git checkout -b release-7.2 cp $BASE/iiab-factory/iiab /usr/sbin/iiab else @@ -69,19 +69,21 @@ fi cd $BASE echo if [ -d iiab ]; then - echo -e "REPO iiab EXISTS? Consider 'sudo iiab --reinstall'" + echo -e "REPO iiab EXISTS? Consider 'sudo iiab --upgrade'" else cd iiab - git clone https://github.com/iiab/iiab --depth 10 --branch release-7.2 - git checkout -b master - git config branch.master.remote origin - git config branch.master.merge refs/heads/master - git checkout release-7.2 + git clone https://github.com/iiab/iiab --depth 10 --branch master +# git clone https://github.com/iiab/iiab --depth 10 --branch release-7.2 +# git checkout -b master +# git config branch.master.remote origin +# git config branch.master.merge refs/heads/master +# git checkout release-7.2 + git checkout -b release-7.2 fi cd $BASE echo if [ -d iiab-admin-console ]; then - echo -e "REPO iiab-admin-console EXISTS? Consider 'sudo iiab --reinstall'" + echo -e "REPO iiab-admin-console EXISTS? Consider 'sudo iiab --upgrade'" else git clone https://github.com/iiab/iiab-admin-console --depth 1 --branch master git checkout -b release-7.2 From e5e1dd99652615778de3f99c7fbf4d3689fab1ce Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Tue, 1 Sep 2020 15:53:40 +0100 Subject: [PATCH 26/43] use master & branch - suggest iiab --upgrade --- install.txt | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/install.txt b/install.txt index 9b629337..c1c93abd 100644 --- a/install.txt +++ b/install.txt @@ -56,7 +56,7 @@ if [ -d iiab-factory ]; then cd iiab-factory git checkout master git pull - git branch -D release-7.2 || true + git branch -D release-7.2 &> /dev/null || true git checkout -b release-7.2 cp $BASE/iiab-factory/iiab /usr/sbin/iiab else @@ -69,19 +69,21 @@ fi cd $BASE echo if [ -d iiab ]; then - echo -e "REPO iiab EXISTS? Consider 'sudo iiab --reinstall'" + echo -e "REPO iiab EXISTS? Consider 'sudo iiab --upgrade'" else cd iiab - git clone https://github.com/iiab/iiab --depth 10 --branch release-7.2 - git checkout -b master - git config branch.master.remote origin - git config branch.master.merge refs/heads/master - git checkout release-7.2 + git clone https://github.com/iiab/iiab --depth 10 --branch master +# git clone https://github.com/iiab/iiab --depth 10 --branch release-7.2 +# git checkout -b master +# git config branch.master.remote origin +# git config branch.master.merge refs/heads/master +# git checkout release-7.2 + git checkout -b release-7.2 fi cd $BASE echo if [ -d iiab-admin-console ]; then - echo -e "REPO iiab-admin-console EXISTS? Consider 'sudo iiab --reinstall'" + echo -e "REPO iiab-admin-console EXISTS? Consider 'sudo iiab --upgrade'" else git clone https://github.com/iiab/iiab-admin-console --depth 1 --branch master git checkout -b release-7.2 From eb9efdfb91946a27f812c6cf27081777907e7200 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Tue, 1 Sep 2020 18:35:15 +0100 Subject: [PATCH 27/43] RELEASE, update_self, softcode SCRIPT, ordering --- iiab | 66 ++++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 49 insertions(+), 17 deletions(-) diff --git a/iiab b/iiab index 2bd6313b..74affbe2 100755 --- a/iiab +++ b/iiab @@ -43,6 +43,8 @@ set -e # Exit on error (avoids snowballing) export DEBIAN_FRONTEND=noninteractive # Bypass (most!) interactive questions +SCRIPT=iiab +RELEASE=1 BASEDIR=/opt/iiab CONFDIR=/etc/iiab FLAGDIR=$CONFDIR/install-flags @@ -50,7 +52,10 @@ APT_PATH=/usr/bin # Avoids problematic /usr/local/bin/apt on Linux Mint REINSTALL="" INTERACTIVE=1 UPDATE=0 +MIN_RPI_KERN=1336 +SELFUPDATE_SCRIPT="/tmp/.updateScript.sh" +# scrape the command line if [ "$1" = "--non-interactive" ]; then shift 1 INTERACTIVE=0 @@ -68,11 +73,17 @@ if [ "$1" = "--reinstall" ]; then REINSTALL="--reinstall" fi +# cleanup +#if [ -f $SELFUPDATE_SCRIPT ]; then +# rm $SELFUPDATE_SCRIPT +#fi + +# Subroutines for upgrade logic check_branch(){ git -C $BASEDIR/iiab branch | grep \* | grep release-7 | wc -l } -use_master(){ +function use_master(){ cd $BASEDIR if [ -d iiab ]; then cd iiab @@ -89,7 +100,7 @@ use_master(){ fi } -update_master(){ +function update_master(){ cd $BASEDIR if [ -d iiab ]; then cd iiab @@ -108,8 +119,8 @@ update_master(){ if [ `check_branch` -gt 0 ]; then echo -e "\nFound release-7.X branch would you like (re)install using the latest master?" - echo -e "[Y/n]\n" - ans="n" + echo -e "[Y/n]\n Y default 5 second timeout" + ans="y" if [ $INTERACTIVE == 1 ]; then read -t 5 ans < /dev/tty fi @@ -122,16 +133,31 @@ if [ `check_branch` -gt 0 ]; then fi fi -if [ $UPDATE == 1 ]; then - use_master - update_master -fi +function update_self() { + cat > "$SELFUPDATE_SCRIPT" << EOF + #!/bin/bash + echo " *** Performing self-update" + cd $BASEDIR + if [ -d iiab-factory ]; then + echo -e "\nUpdating iiab-factory" + cd iiab-factory + git checkout master + git pull + fi + VERSION=$RELEASE + NEW_VERSION=`grep RELEASE /opt/iiab/iiab-factory/$SCRIPT | awk -F = '{print $2}' | head -n 1` -if [ -f $FLAGS/iiab-complete ]; then - echo -e " IIAB completed successfully nothing to do.." -# echo -e " iiab --reinstall if you really want to start over" - exit 0 -fi + if [ $NEW_VERSION -gt $VERSION ]; then + cp /opt/iiab/iiab-factory/$SCRIPT /usr/sbin/$SCRIPT + echo "Latest $SCRIPT now installed" + else + echo "Latest $SCRIPT is already installed" + fi + exec env /bin/bash /usr/sbin/$SCRIPT +EOF + echo " *** Relaunching $SCRIPT after update" + exec /bin/bash $SELFUPDATE_SCRIPT +} # A. Subroutine for B. and D. Returns true (0) if username ($1) exists with password ($2) check_user_pwd() { @@ -170,13 +196,13 @@ if check_user_pwd "iiab-admin" "g0adm1n"; then fi fi -mkdir -p $FLAGDIR if [ -f $FLAGDIR/iiab-complete ]; then echo -e "\n\nIIAB INSTALLATION (/usr/sbin/iiab) IS ALREADY COMPLETE -- per existence of:" echo -e "$FLAGDIR/iiab-complete -- nothing to do.\n" exit 0 fi +mkdir -p $FLAGDIR # E. Position & customize $CONFDIR/local_vars.yml cd $CONFDIR if [ -f local_vars.yml ]; then @@ -229,6 +255,12 @@ else # nano /etc/iiab/local_vars.yml fi fi + +if [ $UPDATE == 1 ]; then + use_master + update_master +fi + # F. Mandate OS SECURITY/UPDATES if 'apt update' has any (IF SO REBOOT) # Educate implementer while waiting for 'apt update' echo -e "\n\n ██████████████████████████████████████████████████████████████████████████████" @@ -273,8 +305,6 @@ version_gt() { [ "$(printf '%s\n' "$@" | sort -V | head -1)" != "$1" ]; } # Verify that Raspbian is running a recent enough kernel. As Raspbian # kernel 1333 has wifi issues https://github.com/iiab/iiab/issues/2497. -#MIN_RPI_KERN=1336 -MIN_RPI_KERN=1340 CURR_KERN=`uname -v | awk '{print $1}' | sed -e s'/#//'` echo "Found Kernel ""$CURR_KERN" if [ -f /etc/rpi-issue ] && version_gt $MIN_RPI_KERN $CURR_KERN; then @@ -282,7 +312,9 @@ if [ -f /etc/rpi-issue ] && version_gt $MIN_RPI_KERN $CURR_KERN; then # echo -e "\033[31;5mPLEASE RUN 'apt update' then 'apt install raspberrypi-kernel' then reboot.\033[0m" echo -e "\033[31;5mTHEN IF NEC run 'rpi-update' to install a more recent kernel post-install, then reboot.\033[0m" echo -e "'enter' to continue" - read -t 10 ans < /dev/tty + if [ $INTERACTIVE == 1 ]; then + read -t 10 ans < /dev/tty + fi fi From ee51f00c9c7a063ab4e6319f226a3696681e6863 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Tue, 1 Sep 2020 19:04:47 +0100 Subject: [PATCH 28/43] softcode BRANCH --- install.txt | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/install.txt b/install.txt index c1c93abd..6759b503 100644 --- a/install.txt +++ b/install.txt @@ -45,7 +45,7 @@ set -e # Exit on error (avoids snowballing) export DEBIAN_FRONTEND=noninteractive # Bypass (most!) interactive questions BASE=/opt/iiab - +BRANCH=release-7.2 echo -e "\n\nDOWNLOAD (CLONE) IIAB'S 3 KEY REPOS INTO $BASE ...\n" /usr/bin/apt -y install git nano mkdir -p $BASE @@ -56,14 +56,14 @@ if [ -d iiab-factory ]; then cd iiab-factory git checkout master git pull - git branch -D release-7.2 &> /dev/null || true - git checkout -b release-7.2 + git branch -D $BRANCH &> /dev/null || true + git checkout -b $BRANCH cp $BASE/iiab-factory/iiab /usr/sbin/iiab else echo -e "Cloning iiab-factory" git clone https://github.com/iiab/iiab-factory --depth 1 cd iiab-factory - git checkout -b release-7.2 + git checkout -b $BRANCH cp $BASE/iiab-factory/iiab /usr/sbin/iiab fi cd $BASE @@ -73,12 +73,13 @@ if [ -d iiab ]; then else cd iiab git clone https://github.com/iiab/iiab --depth 10 --branch master -# git clone https://github.com/iiab/iiab --depth 10 --branch release-7.2 + git checkout -b $BRANCH +# post branching below +# git clone https://github.com/iiab/iiab --depth 10 --branch $BRANCH # git checkout -b master # git config branch.master.remote origin # git config branch.master.merge refs/heads/master -# git checkout release-7.2 - git checkout -b release-7.2 +# git checkout $BRANCH fi cd $BASE echo @@ -86,7 +87,7 @@ if [ -d iiab-admin-console ]; then echo -e "REPO iiab-admin-console EXISTS? Consider 'sudo iiab --upgrade'" else git clone https://github.com/iiab/iiab-admin-console --depth 1 --branch master - git checkout -b release-7.2 + git checkout -b $BRANCH # git config branch.master.remote origin # git config branch.master.merge refs/heads/master # git checkout v0.3.7 From f27c7cc3e71d8d5c2ee04ce392ef2cccc39121a1 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Tue, 1 Sep 2020 19:22:00 +0100 Subject: [PATCH 29/43] misc --- iiab | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/iiab b/iiab index 74affbe2..6e41967c 100755 --- a/iiab +++ b/iiab @@ -48,9 +48,9 @@ RELEASE=1 BASEDIR=/opt/iiab CONFDIR=/etc/iiab FLAGDIR=$CONFDIR/install-flags -APT_PATH=/usr/bin # Avoids problematic /usr/local/bin/apt on Linux Mint +APT_PATH=/usr/bin/apt # Avoids problematic /usr/local/bin/apt on Linux Mint REINSTALL="" -INTERACTIVE=1 +INTERACTIVE=0 UPDATE=0 MIN_RPI_KERN=1336 SELFUPDATE_SCRIPT="/tmp/.updateScript.sh" @@ -119,11 +119,12 @@ function update_master(){ if [ `check_branch` -gt 0 ]; then echo -e "\nFound release-7.X branch would you like (re)install using the latest master?" - echo -e "[Y/n]\n Y default 5 second timeout" - ans="y" - if [ $INTERACTIVE == 1 ]; then - read -t 5 ans < /dev/tty - fi + echo -e "[Y/n]\n n default 5 second timeout" + ans="n" +# if [ $INTERACTIVE == 1 ]; then +# read -t 5 ans < /dev/tty +# fi + read -t 5 ans < /dev/tty if [ "$ans" == "y" ] || [ "$ans" == "Y" ]; then UPDATE=1 else @@ -257,6 +258,7 @@ else fi if [ $UPDATE == 1 ]; then + update_self use_master update_master fi @@ -272,7 +274,7 @@ echo -e "\n\n'apt update' is checking for OS updates...\n" #echo -e "2019-07-11 TEMP WORKAROUND FOR RASPBIAN BUSTER'S testing->stable apt GLITCH...\nDetails @ https://github.com/iiab/iiab/issues/1856\n" #apt -y update || true # Overrides 'set -e' #echo -e "\nNOW THE REAL 'apt update' WILL RUN...\n" -$APT_PATH/apt -qq update > /tmp/apt.stdout 2> /tmp/apt.stderr || true # Overrides 'set -e' +$APT_PATH -qq update > /tmp/apt.stdout 2> /tmp/apt.stderr || true # Overrides 'set -e' if [ $(wc -c < /tmp/apt.stderr) -gt 82 ]; then # apt.stderr typically contains exactly 82 characters when there are no errors, no matter the primary locale, i.e. 3-line file "\nWARNING: apt does not have a stable CLI interface. Use with caution in scripts.\n\n" ...OR... in other cases more than 82, e.g. many lines of errors when apt is busy/locked/offline/etc echo -e "'apt update' FAILED. VERIFY YOU'RE ONLINE and resolve all errors below:\n" cat /tmp/apt.stderr From 6b07a901a96e216b8534fd856e6b6883c3ae1df5 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Tue, 1 Sep 2020 21:34:16 +0100 Subject: [PATCH 30/43] iiab-upgrade --- iiab-upgrade | 408 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 408 insertions(+) create mode 100755 iiab-upgrade diff --git a/iiab-upgrade b/iiab-upgrade new file mode 100755 index 00000000..35f163f0 --- /dev/null +++ b/iiab-upgrade @@ -0,0 +1,408 @@ +#!/bin/bash +# jvonau +set -e # Exit on error (avoids snowballing) +export DEBIAN_FRONTEND=noninteractive # Bypass (most!) interactive questions +SCRIPT=iiab-upgrade +RELEASE=1 +BASEDIR=/opt/iiab +CONFDIR=/etc/iiab +FLAGDIR=$CONFDIR/install-flags +APT_PATH=/usr/bin/apt # Avoids problematic /usr/local/bin/apt on Linux Mint +REINSTALL="" +INTERACTIVE=0 +UPDATE=0 +MIN_RPI_KERN=1336 +SELFUPDATE_SCRIPT="/tmp/.updateScript.sh" +# scrape the command line +if [ "$1" = "--non-interactive" ]; then + shift 1 + INTERACTIVE=0 +fi + +if [ "$1" = "--upgrade" ]; then + shift 1 + rm $FLAGS/iiab*complete || true + UPDATE=1 + REINSTALL="--reinstall" +fi + +if [ "$1" = "--reinstall" ]; then + rm $FLAGS/iiab*complete || true + REINSTALL="--reinstall" +fi + +# cleanup +#if [ -f $SELFUPDATE_SCRIPT ]; then +# rm $SELFUPDATE_SCRIPT +#fi + +# Subroutines for upgrade logic +check_branch(){ + git -C $BASEDIR/iiab branch | grep \* | grep release-7 | wc -l +} + +function use_master(){ + cd $BASEDIR + if [ -d iiab ]; then + cd iiab + git checkout -b master &> /dev/null || true # covers older curls of release-7.0 + git config branch.master.remote origin || true # covers older curls of release-7.0 + git config branch.master.merge refs/heads/master || true # covers older curls of release-7.0 + fi + cd $BASEDIR + if [ -d iiab-admin-console ]; then + cd iiab-admin-console + git checkout -b master &> /dev/null || true # covers older curls of release-7.0 + git config branch.master.remote origin || true # covers older curls of release-7.0 + git config branch.master.merge refs/heads/master || true # covers older curls of release-7.0 + fi +} + +function update_master(){ + cd $BASEDIR + if [ -d iiab ]; then + cd iiab + echo -e "\nUpdating iiab" + git checkout master + git pull + fi + cd $BASEDIR + if [ -d iiab-admin-console ]; then + echo -e "\nUpdating iiab-admin-console" + cd iiab-admin-console + git checkout master + git pull + fi +} + +function update_self() { + echo " *** Performing self-update" + cd $BASEDIR + if [ -d iiab-factory ]; then + echo -e "\nUpdating iiab-factory" + cd iiab-factory + git checkout master + git pull + fi + + NEW_VERSION=$(grep RELEASE /opt/iiab/iiab-factory/$SCRIPT | awk -F = '{print $2}' | head -n 1) + if [ $NEW_VERSION -gt $RELEASE ]; then + cp /opt/iiab/iiab-factory/$SCRIPT /usr/sbin/$SCRIPT + echo "Latest $SCRIPT now installed" + cat > "$SELFUPDATE_SCRIPT" << EOF + #!/bin/bash + echo " *** Relaunching $SCRIPT after update" +# exec env /bin/bash /usr/sbin/$SCRIPT + exec /usr/sbin/$SCRIPT +EOF + exec /bin/bash $SELFUPDATE_SCRIPT + else + echo " Latest $SCRIPT is already installed" + fi +} + +# start exec here +update_self + +if [ `check_branch` -gt 0 ]; then + echo -e "\nFound release-7.X branch would you like (re)install using the latest master?" + echo -e "[Y/n]\n n default 5 second timeout" + ans="n" +# if [ $INTERACTIVE == 1 ]; then +# read -t 5 ans < /dev/tty +# fi + read -t 5 ans < /dev/tty + if [ "$ans" == "y" ] || [ "$ans" == "Y" ]; then + UPDATE=1 + else + echo "remaning on release-7.X branch updating" + cd $BASEDIR/iiab + git pull + fi +fi + +# A. Subroutine for B. and D. Returns true (0) if username ($1) exists with password ($2) +check_user_pwd() { + # $meth (hashing method) is typically '6' which implies 5000 rounds + # of SHA-512 per /etc/login.defs -> /etc/pam.d/common-password + meth=$(grep "^$1:" /etc/shadow | cut -d: -f2 | cut -d$ -f2) + salt=$(grep "^$1:" /etc/shadow | cut -d: -f2 | cut -d$ -f3) + hash=$(grep "^$1:" /etc/shadow | cut -d: -f2 | cut -d$ -f4) + [ $(python3 -c "import crypt; print(crypt.crypt('$2', '\$$meth\$$salt'))") == "\$$meth\$$salt\$$hash" ] +} + +# B. Ask for password change if pi/raspberry default remains +if check_user_pwd "pi" "raspberry"; then + echo -e "\n\nRaspberry Pi's are COMPROMISED often if the default password is not changed!\n" + echo -n "What password do you want for GNU/Linux user 'pi' ? " + read -t 5 ans < /dev/tty # Whines but doesn't change password if [Enter] + echo pi:"$ans" | chpasswd || true # Overrides 'set -e' +fi + +# C. Create user 'iiab-admin' as nec, with default password +if ! id -u iiab-admin > /dev/null 2> /dev/null; then + useradd iiab-admin + echo iiab-admin:g0adm1n | chpasswd +fi + +# D. Ask for password change if iiab-admin/g0adm1n default remains +if check_user_pwd "iiab-admin" "g0adm1n"; then + echo -e "\n\nUser 'iiab-admin' retains default password 'g0adm1n' per http://FAQ.IIAB.IO\n" + + echo -e "This is for login to Internet-in-a-Box's Admin Console (http://box.lan/admin)\n" + if [ $INTERACTIVE == 1 ]; then + echo -n "What password do you want for GNU/Linux user 'iiab-admin' ? " + echo -n "press [Enter] for no change" + read -t 15 ans < /dev/tty # Whines but doesn't change password if [Enter] + echo iiab-admin:"$ans" | chpasswd || true # Overrides 'set -e' + fi +fi + +if [ -f $FLAGDIR/iiab-complete ]; then + echo -e "\n\nIIAB INSTALLATION (/usr/sbin/iiab) IS ALREADY COMPLETE -- per existence of:" + echo -e "$FLAGDIR/iiab-complete -- nothing to do.\n" + exit 0 +fi + +mkdir -p $FLAGDIR +# E. Position & customize $CONFDIR/local_vars.yml +cd $CONFDIR +if [ -f local_vars.yml ]; then + + # FUTURE: Test if their local_vars.yml is sufficiently version-compatible ! + + echo -e "\n\n EXISTING $CONFDIR/local_vars.yml is being used to install Internet-in-a-Box\n" + + echo -e " 🚂 🚃 🚄 🚅 🚆 🚇 🚈 🚉 🚊 🚋 🚌 🚍 🚎 🚏 🚐 🚑 🚒 🚚 🚛 🚜 🚞 🚟 🚠 🚡 🚲\n" + + echo -e " Google 'local_vars.yml' to learn more!" +else + echo -e "\n\nInstalling Internet-in-a-Box requires $CONFDIR/local_vars.yml" + echo -e "Do you want (1) 🚵 MIN-sized (2) 🚢🚣 MEDIUM-sized or (3) 🚂🚃🚃 BIG-sized?\n" + + echo -e "These take about 1, 2 or 3 hours on an older Raspberry Pi 3 or 3 B+, depending" + echo -e "on Internet speed, CPU speed/temperature and microSD card/disk speed. Please" + echo -e "use a Raspberry Pi 4 or x86_64 to install in about an hour or less !\n" + + echo -e 'See "What can I do with E-books and Internet-in-a-Box?" and "What services' + echo -e '(IIAB apps) are suggested during installation?" within http://FAQ.IIAB.IO\n' + + echo -n "Please type 1, 2 or 3 then press [ENTER]: " + local_vars_size="" + if [ "$INTERACTIVE" == 1 ]; then + read local_vars_size < /dev/tty + fi + echo + case $local_vars_size in + 1) + cp $BASEDIR/iiab/vars/local_vars_min.yml local_vars.yml + ;; + 3) + cp $BASEDIR/iiab/vars/local_vars_big.yml local_vars.yml + ;; + *) + cp $BASEDIR/iiab/vars/local_vars_medium.yml local_vars.yml + ;; + esac + + echo -en "\nEdit /etc/iiab/local_vars.yml to customize your Internet-in-a-Box? [Y/n] " + ans="n" + if [ "$INTERACTIVE" == 1 ]; then + read -t 5 ans < /dev/tty + fi + if [ "$ans" == "y" ] || [ "$ans" == "Y" ]; then + exit 0 +# echo -en "ctrl x to save and exit" +# sleep 2 +# nano /etc/iiab/local_vars.yml + fi +fi + +if [ $UPDATE == 1 ]; then + use_master + update_master +fi + +# F. Mandate OS SECURITY/UPDATES if 'apt update' has any (IF SO REBOOT) +# Educate implementer while waiting for 'apt update' +echo -e "\n\n ██████████████████████████████████████████████████████████████████████████████" +echo -e " ██ ██" +echo -e " ██ RUN 'sudo iiab' IF THIS INSTALL SCRIPT EVER FAILS, TO TRY TO CONTINUE! ██" +echo -e " ██ ██" +echo -e " ██████████████████████████████████████████████████████████████████████████████" +echo -e "\n\n'apt update' is checking for OS updates...\n" +#echo -e "2019-07-11 TEMP WORKAROUND FOR RASPBIAN BUSTER'S testing->stable apt GLITCH...\nDetails @ https://github.com/iiab/iiab/issues/1856\n" +#apt -y update || true # Overrides 'set -e' +#echo -e "\nNOW THE REAL 'apt update' WILL RUN...\n" +$APT_PATH -qq update > /tmp/apt.stdout 2> /tmp/apt.stderr || true # Overrides 'set -e' +if [ $(wc -c < /tmp/apt.stderr) -gt 82 ]; then # apt.stderr typically contains exactly 82 characters when there are no errors, no matter the primary locale, i.e. 3-line file "\nWARNING: apt does not have a stable CLI interface. Use with caution in scripts.\n\n" ...OR... in other cases more than 82, e.g. many lines of errors when apt is busy/locked/offline/etc + echo -e "'apt update' FAILED. VERIFY YOU'RE ONLINE and resolve all errors below:\n" + cat /tmp/apt.stderr + exit 1 +elif grep -q 'apt list --upgradable' /tmp/apt.stdout; then # apt.stdout typically contains {"All packages are up to date.\n" [even if primary locale is French & Hindi!], "Todos los paquetes están actualizados.\n", "所有软件包均为最新。\n"} ...OR... {"5 packages can be upgraded. Run 'apt list --upgradable' to see them.\n" [even if primary locale is French & Hindi!], "Se puede actualizar 1 paquete. Ejecute «apt list --upgradable» para verlo.\n", "有 1 个软件包可以升级。请执行 ‘apt list --upgradable’ 来查看它们。\n"} + cat /tmp/apt.stdout + if [ "$INTERACTIVE" == 1 ]; then + echo -e "\nYour OS will now be upgraded...this takes time. THEN IT WILL AUTO-REBOOT.\n" + echo -n "Hit [ENTER] to confirm you'll RUN 'sudo iiab' AFTER IT REBOOTS: " + read ans < /dev/tty + echo + $APT_PATH -y dist-upgrade + reboot + exit 0 # Nec to avoid both output lines below (that confuse implementers!) + else + $APT_PATH -y dist-upgrade + fi +fi +cat /tmp/apt.stdout # "All packages are up to date.\n" + +if [ $INTERACTIVE == 1 ]; then + echo -ne "\nHit [ENTER] to confirm you'll TRY TO RERUN 'sudo iiab' IF THERE IS A PROBLEM: " + read -t 5 ans < /dev/tty +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" +version_gt() { [ "$(printf '%s\n' "$@" | sort -V | head -1)" != "$1" ]; } + +# Verify that Raspbian is running a recent enough kernel. As Raspbian +# kernel 1333 has wifi issues https://github.com/iiab/iiab/issues/2497. +CURR_KERN=`uname -v | awk '{print $1}' | sed -e s'/#//'` +echo "Found Kernel ""$CURR_KERN" +if [ -f /etc/rpi-issue ] && version_gt $MIN_RPI_KERN $CURR_KERN; then + echo -e "\033[31;5mWARNING: Kernel ""$MIN_RPI_KERN"" or higher required with Raspbian.\033[0m" +# echo -e "\033[31;5mPLEASE RUN 'apt update' then 'apt install raspberrypi-kernel' then reboot.\033[0m" + echo -e "\033[31;5mTHEN IF NEC run 'rpi-update' to install a more recent kernel post-install, then reboot.\033[0m" + echo -e "'enter' to continue" + if [ $INTERACTIVE == 1 ]; then + read -t 10 ans < /dev/tty + fi +fi + + +######################### INTERACTIVE STUFF IS ABOVE ######################### + +# G. If RPi, lower reserve disk space from ~5% to 1% +#if [ -f /proc/device-tree/model ] && grep -qi raspberry /proc/device-tree/model; then +if [ -e /dev/mmcblk0p2 ]; then + echo -e "\n\nFound microSD card /dev/mmcblk0p2: Lower its reserve disk space from ~5% to 1%\n" + tune2fs -m 1 /dev/mmcblk0p2 +fi + +# I. Install Ansible + 2 IIAB repos +echo -e "\n\nINSTALL ANSIBLE + CORE IIAB SOFTWARE + ADMIN CONSOLE / CONTENT PACK MENUS...\n" + +echo -e "Install Ansible..." +$BASEDIR/iiab/scripts/ansible + +echo -e "\n┌──────────────────────────────────────────────────────────────────────────────┐" +echo -e "│ │" +echo -e "│ NOW INSTALL IIAB SOFTWARE! If glitches arise (connectivity or otherwise) │" +echo -e "│ │" +echo -e "│ PLEASE TRY TO CONTINUE BY RE-RUNNING PARENT SCRIPT 'sudo iiab' -- or run │" +echo -e "│ │" +echo -e "│ child script ./iiab-install -- both avoid repeating any of the 9 stages. │" +echo -e "│ │" +echo -e "└──────────────────────────────────────────────────────────────────────────────┘" +cd $BASEDIR/iiab/ +./iiab-install $REINSTALL + +echo -e "Install Admin Console... (also runs iiab-get-kiwix-cat to d/l Kiwix catalog, and installs Dynamic Menuing for /library/www/html/home/index.html)\n" +if [ ! -f $FLAGDIR/iiab-admin-console-complete ] || [ $UPDATE == 1 ]; then + cd $BASEDIR/iiab-admin-console + ./install + touch $FLAGDIR/iiab-admin-console-complete +else + echo -e "ADMIN CONSOLE INSTALLATION IS ALREADY COMPLETE -- per existence of:" + echo -e "$FLAGDIR/iiab-admin-console-complete\n" +fi + +# J. KA Lite prep +if [ -d /library/ka-lite ]; then + echo -e "\n\nKA LITE REQUIRES 2 THINGS...\n" + + echo -e "Register with KA Lite - just the anonymous registration...\n" + # /usr/bin/kalite venv wrapper invokes 'export KALITE_HOME=/library/ka-lite' + if [ ! -f $FLAGDIR/kalite-zone-complete ]; then + echo -e "Now running 'kalite manage generate_zone' ...\n" + kalite manage generate_zone || true # Overrides 'set -e' + touch $FLAGDIR/kalite-zone-complete + else + echo -e "'kalite manage generate_zone' IS ALREADY COMPLETE -- per existence of:" + echo -e "$FLAGDIR/kalite-zone-complete\n" + fi + + echo -e "\nInstall KA Lite's mandatory 0.9 GB English Pack... (en.zip)\n" + if [ ! -f $FLAGDIR/kalite-en.zip-complete ]; then + #echo -e 'Now retrieving it...\n' + cd /tmp + if [ -f en.zip ]; then + if [ $(wc -c < en.zip) -ne 929916955 ]; then + echo -e "\nERROR: /tmp/en.zip must be 929,916,955 bytes to proceed.\n" >&2 + exit 1 + else + echo -e "\nUsing existing /tmp/en.zip whose 929,916,955 byte size is correct!\n" + fi + else + wget http://pantry.learningequality.org/downloads/ka-lite/0.17/content/contentpacks/en.zip + fi + echo -e 'Now installing /tmp/en.zip into /library/ka-lite/content/*\n' + kalite manage retrievecontentpack local en en.zip + touch $FLAGDIR/kalite-en.zip-complete + else + echo -e 'kalite zip already done' + fi +fi +# WARNING: /tmp/en.zip (and all stuff in /tmp) is auto-deleted during reboots +# NEW WAY ABOVE - since 2018-07-03 - installs KA Lite's mandatory English Pack +# +# kalite manage retrievecontentpack download en +# OLD WAY ABOVE - fails w/ sev ISPs per https://github.com/iiab/iiab/issues/871 + +# K. Start BitTorrent downloads, e.g. if $CONFDIR/local_vars.yml requested any +if (systemctl -q is-active transmission-daemon) then + echo -e "\n\nSTARTING BITTORRENT DOWNLOAD(S) for KA Lite...Please Monitor: http://box:9091\n" + transmission-remote -n Admin:changeme -t all --start +fi + +touch $FLAGDIR/iiab-complete + +# L. Educate Implementers prior to rebooting! +echo -e "\n\n ┌───────────────────────────────────────────────────────────┐" +echo -e " │ │" +echo -e " │ INTERNET-IN-A-BOX (IIAB) SOFTWARE INSTALL IS COMPLETE │" +echo -e " │ │" +echo -e " └───────────────────────────────────────────────────────────┘\n" + +echo -e "(1A) A couple minutes after you reboot (below) try to connect any laptop to" +echo -e 'Wi-Fi hotspot "Internet in a Box". If this works, verify that you can browse' +echo -e "to http://box or http://box.lan or http://172.18.96.1\n" + +echo -e "(1B) IF THOSE 3 DON'T WORK, try http://box.local from any device connected to" +echo -e "your usual network. Or try http://localhost from your IIAB itself!\n" + +echo -e "(1C) IF ALL 5 ABOVE DON'T WORK, ask the person who set up the network/router" +echo -e "in your building for the IP address of your IIAB, so you can browse to it" +echo -e "using (something like) http://192.168.0.100\n" + +echo -e '(2) ADD CONTENT using http://box.lan/admin (changing "box.lan" to be as above!)' +echo -e 'PLEASE READ "What are the default passwords?" and "How do I customize my' +echo -e 'Internet-in-a-Box home page?" at http://FAQ.IIAB.IO\n' + +echo -e "(3) Please run the 'iiab-diagnostics' command, to generate a URL summarizing" +echo -e "your IIAB configuration, for volunteers seeking to help you. We strongly" +echo -e "encourage you to share this URL also when connecting with others in the IIAB" +echo -e "global community, learning from other initiatives in your region and beyond!\n" + +#echo -e "(3) If you're installing IIAB over Wi-Fi (instead of Ethernet) remember to run" +#echo -e "'iiab-hotspot-on' at the VERY END, when you're ready to ACTIVATE YOUR IIAB's" +#echo -e "INTERNAL WI-FI HOTSPOT. CAUTION: this permanently kills your IIAB's Internet" +#echo -e "(over Wi-Fi anyway) until you later run 'iiab-hotspot-off'. CAVEAT: these" +#echo -e "two commands only work with Raspberry Pi as of 2019-09-30.\n" + +if [ $INTERACTIVE == 1 ]; then + echo -ne "HIT [Enter] TO REBOOT, CONFIRMING YOU'VE" '"photographed" THE ABOVE PARAGRAPHS: ' + read ans < /dev/tty + # Sets hostname, improves RTC + memory mgmt, starts BitTorrents if needed, etc! + reboot +fi From 10dead927bb563094ae2402db49b15f7f0459986 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Tue, 1 Sep 2020 22:20:29 +0100 Subject: [PATCH 31/43] install iiab-upgrade --- iiab | 1 + 1 file changed, 1 insertion(+) diff --git a/iiab b/iiab index 0f331869..3a762070 100755 --- a/iiab +++ b/iiab @@ -202,6 +202,7 @@ if [ -d iiab-factory ]; then echo -e "REPO EXISTS? Consider 'cd /opt/iiab/iiab-factory; git pull'" else git clone https://github.com/iiab/iiab-factory --depth 1 + cp -f iiab-factory/iiab-upgrade /usr/sbin/iiab-upgrade fi # I. Install Ansible + 2 IIAB repos From 9b48d918b09eed5e4a71b3d2d22e6cfa5880d1e7 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Tue, 1 Sep 2020 22:54:23 +0100 Subject: [PATCH 32/43] self-install from git repo --- iiab-upgrade | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/iiab-upgrade b/iiab-upgrade index 35f163f0..ebf0af32 100755 --- a/iiab-upgrade +++ b/iiab-upgrade @@ -86,13 +86,12 @@ function update_self() { fi NEW_VERSION=$(grep RELEASE /opt/iiab/iiab-factory/$SCRIPT | awk -F = '{print $2}' | head -n 1) + cp $SCRIPT /usr/sbin/$SCRIPT + echo "Latest $SCRIPT now installed" if [ $NEW_VERSION -gt $RELEASE ]; then - cp /opt/iiab/iiab-factory/$SCRIPT /usr/sbin/$SCRIPT - echo "Latest $SCRIPT now installed" + echo " *** Relaunching $SCRIPT after update" cat > "$SELFUPDATE_SCRIPT" << EOF #!/bin/bash - echo " *** Relaunching $SCRIPT after update" -# exec env /bin/bash /usr/sbin/$SCRIPT exec /usr/sbin/$SCRIPT EOF exec /bin/bash $SELFUPDATE_SCRIPT From c6f569de3ec09b5585125fddd85a209c38b43fea Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Wed, 2 Sep 2020 01:23:10 +0100 Subject: [PATCH 33/43] upgrade_roles https://github.com/iiab/iiab-factory/pull/110/files --- iiab-upgrade | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/iiab-upgrade b/iiab-upgrade index ebf0af32..a81f5f1b 100755 --- a/iiab-upgrade +++ b/iiab-upgrade @@ -23,7 +23,7 @@ if [ "$1" = "--upgrade" ]; then shift 1 rm $FLAGS/iiab*complete || true UPDATE=1 - REINSTALL="--reinstall" +# REINSTALL="--reinstall" fi if [ "$1" = "--reinstall" ]; then @@ -31,11 +31,6 @@ if [ "$1" = "--reinstall" ]; then REINSTALL="--reinstall" fi -# cleanup -#if [ -f $SELFUPDATE_SCRIPT ]; then -# rm $SELFUPDATE_SCRIPT -#fi - # Subroutines for upgrade logic check_branch(){ git -C $BASEDIR/iiab branch | grep \* | grep release-7 | wc -l @@ -304,7 +299,16 @@ echo -e "│ child script ./iiab-install -- both avoid repeating any of the 9 echo -e "│ │" echo -e "└──────────────────────────────────────────────────────────────────────────────┘" cd $BASEDIR/iiab/ -./iiab-install $REINSTALL +if [ $UPDATE == 1 ]; then + if [ -f upgrade_roles ]; then + for force in $(cat upgrade_roles); do + sed -i -e '/^$force/d' $CONFDIR/iiab_state.yml + done + fi + ./iiab-configure +else + ./iiab-install $REINSTALL +fi echo -e "Install Admin Console... (also runs iiab-get-kiwix-cat to d/l Kiwix catalog, and installs Dynamic Menuing for /library/www/html/home/index.html)\n" if [ ! -f $FLAGDIR/iiab-admin-console-complete ] || [ $UPDATE == 1 ]; then @@ -399,9 +403,14 @@ echo -e "global community, learning from other initiatives in your region and be #echo -e "(over Wi-Fi anyway) until you later run 'iiab-hotspot-off'. CAVEAT: these" #echo -e "two commands only work with Raspberry Pi as of 2019-09-30.\n" +# cleanup +if [ -f $SELFUPDATE_SCRIPT ]; then + rm $SELFUPDATE_SCRIPT +fi if [ $INTERACTIVE == 1 ]; then echo -ne "HIT [Enter] TO REBOOT, CONFIRMING YOU'VE" '"photographed" THE ABOVE PARAGRAPHS: ' read ans < /dev/tty # Sets hostname, improves RTC + memory mgmt, starts BitTorrents if needed, etc! reboot fi +exit 0 From 66a1a595cfe5e419de7f5f0690c80b60ef874d71 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Wed, 2 Sep 2020 04:59:35 +0100 Subject: [PATCH 34/43] iiab_revision --- iiab-upgrade | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/iiab-upgrade b/iiab-upgrade index a81f5f1b..1a5decb0 100755 --- a/iiab-upgrade +++ b/iiab-upgrade @@ -6,6 +6,7 @@ SCRIPT=iiab-upgrade RELEASE=1 BASEDIR=/opt/iiab CONFDIR=/etc/iiab +IIABENV=$CONFDIR/iiab.env FLAGDIR=$CONFDIR/install-flags APT_PATH=/usr/bin/apt # Avoids problematic /usr/local/bin/apt on Linux Mint REINSTALL="" @@ -60,6 +61,7 @@ function update_master(){ echo -e "\nUpdating iiab" git checkout master git pull + NEWREV=$(grep iiab_revision vars/default_vars.yml | awk '{print $2}') fi cd $BASEDIR if [ -d iiab-admin-console ]; then @@ -112,6 +114,7 @@ if [ `check_branch` -gt 0 ]; then echo "remaning on release-7.X branch updating" cd $BASEDIR/iiab git pull + NEWREV=$(grep iiab_revision vars/default_vars.yml | awk '{print $2}') fi fi @@ -300,9 +303,14 @@ echo -e "│ echo -e "└──────────────────────────────────────────────────────────────────────────────┘" cd $BASEDIR/iiab/ if [ $UPDATE == 1 ]; then + source $IIABENV + OLDREV=$IIAB_REVISION if [ -f upgrade_roles ]; then - for force in $(cat upgrade_roles); do - sed -i -e '/^$force/d' $CONFDIR/iiab_state.yml + for REV in $(cat upgrade_roles | awk '{print $1}'); do + if [ $REV -gt $OLDREV ]; then + force=$(grep $REV upgrade_roles | awk '{print $2}') + sed -i -e '/^$force/d' $CONFDIR/iiab_state.yml + fi done fi ./iiab-configure From 4a6f1c70c24a805dfcbaa8c721aae2bd9e5a655a Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Wed, 2 Sep 2020 05:09:01 +0100 Subject: [PATCH 35/43] fall though to iiab-install on first pass --- iiab-upgrade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iiab-upgrade b/iiab-upgrade index 1a5decb0..0494e1b4 100755 --- a/iiab-upgrade +++ b/iiab-upgrade @@ -302,7 +302,7 @@ echo -e "│ child script ./iiab-install -- both avoid repeating any of the 9 echo -e "│ │" echo -e "└──────────────────────────────────────────────────────────────────────────────┘" cd $BASEDIR/iiab/ -if [ $UPDATE == 1 ]; then +if [ -f $IIABENV ] && [ $UPDATE == 1 ]; then source $IIABENV OLDREV=$IIAB_REVISION if [ -f upgrade_roles ]; then From 45b8af1744adc4bc65689794fce2c7a28005f4bb Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Wed, 2 Sep 2020 05:38:10 +0100 Subject: [PATCH 36/43] skipping re-exec --- iiab-upgrade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iiab-upgrade b/iiab-upgrade index 0494e1b4..fb44b7c6 100755 --- a/iiab-upgrade +++ b/iiab-upgrade @@ -93,7 +93,7 @@ function update_self() { EOF exec /bin/bash $SELFUPDATE_SCRIPT else - echo " Latest $SCRIPT is already installed" + echo "Latest $SCRIPT is already running skipping re-exec" fi } From 135a480ba61cc6106e0683e24825c2ee1850aab7 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Thu, 3 Sep 2020 07:55:22 +0100 Subject: [PATCH 37/43] grouping - move kernel test to the end --- iiab-upgrade | 68 +++++++++++++++++++++++++++------------------------- 1 file changed, 36 insertions(+), 32 deletions(-) diff --git a/iiab-upgrade b/iiab-upgrade index fb44b7c6..2cac8cae 100755 --- a/iiab-upgrade +++ b/iiab-upgrade @@ -97,6 +97,21 @@ EOF 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" +version_gt() { [ "$(printf '%s\n' "$@" | sort -V | head -1)" != "$1" ]; } + +# A. Subroutine for B. and D. Returns true (0) if username ($1) exists with password ($2) +check_user_pwd() { + # $meth (hashing method) is typically '6' which implies 5000 rounds + # of SHA-512 per /etc/login.defs -> /etc/pam.d/common-password + meth=$(grep "^$1:" /etc/shadow | cut -d: -f2 | cut -d$ -f2) + salt=$(grep "^$1:" /etc/shadow | cut -d: -f2 | cut -d$ -f3) + hash=$(grep "^$1:" /etc/shadow | cut -d: -f2 | cut -d$ -f4) + [ $(python3 -c "import crypt; print(crypt.crypt('$2', '\$$meth\$$salt'))") == "\$$meth\$$salt\$$hash" ] +} + # start exec here update_self @@ -118,16 +133,6 @@ if [ `check_branch` -gt 0 ]; then fi fi -# A. Subroutine for B. and D. Returns true (0) if username ($1) exists with password ($2) -check_user_pwd() { - # $meth (hashing method) is typically '6' which implies 5000 rounds - # of SHA-512 per /etc/login.defs -> /etc/pam.d/common-password - meth=$(grep "^$1:" /etc/shadow | cut -d: -f2 | cut -d$ -f2) - salt=$(grep "^$1:" /etc/shadow | cut -d: -f2 | cut -d$ -f3) - hash=$(grep "^$1:" /etc/shadow | cut -d: -f2 | cut -d$ -f4) - [ $(python3 -c "import crypt; print(crypt.crypt('$2', '\$$meth\$$salt'))") == "\$$meth\$$salt\$$hash" ] -} - # B. Ask for password change if pi/raspberry default remains if check_user_pwd "pi" "raspberry"; then echo -e "\n\nRaspberry Pi's are COMPROMISED often if the default password is not changed!\n" @@ -257,25 +262,6 @@ if [ $INTERACTIVE == 1 ]; then read -t 5 ans < /dev/tty 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" -version_gt() { [ "$(printf '%s\n' "$@" | sort -V | head -1)" != "$1" ]; } - -# Verify that Raspbian is running a recent enough kernel. As Raspbian -# kernel 1333 has wifi issues https://github.com/iiab/iiab/issues/2497. -CURR_KERN=`uname -v | awk '{print $1}' | sed -e s'/#//'` -echo "Found Kernel ""$CURR_KERN" -if [ -f /etc/rpi-issue ] && version_gt $MIN_RPI_KERN $CURR_KERN; then - echo -e "\033[31;5mWARNING: Kernel ""$MIN_RPI_KERN"" or higher required with Raspbian.\033[0m" -# echo -e "\033[31;5mPLEASE RUN 'apt update' then 'apt install raspberrypi-kernel' then reboot.\033[0m" - echo -e "\033[31;5mTHEN IF NEC run 'rpi-update' to install a more recent kernel post-install, then reboot.\033[0m" - echo -e "'enter' to continue" - if [ $INTERACTIVE == 1 ]; then - read -t 10 ans < /dev/tty - fi -fi - ######################### INTERACTIVE STUFF IS ABOVE ######################### @@ -411,14 +397,32 @@ echo -e "global community, learning from other initiatives in your region and be #echo -e "(over Wi-Fi anyway) until you later run 'iiab-hotspot-off'. CAVEAT: these" #echo -e "two commands only work with Raspberry Pi as of 2019-09-30.\n" +# Verify that Raspbian is running a recent enough kernel. As Raspbian +# kernel 1333 has wifi issues https://github.com/iiab/iiab/issues/2497. +CURR_KERN=`uname -v | awk '{print $1}' | sed -e s'/#//'` +echo "Found Kernel ""$CURR_KERN" +if [ -f /etc/rpi-issue ] && version_gt $MIN_RPI_KERN $CURR_KERN; then + echo -e "\033[31;5mWARNING: Kernel ""$MIN_RPI_KERN"" or higher required with Raspbian.\033[0m" +# echo -e "\033[31;5mPLEASE RUN 'apt update' then 'apt install raspberrypi-kernel' then reboot.\033[0m" + echo -e "\033[31;5mTHEN IF NEC run 'rpi-update' to install a more recent kernel \033[0m" + echo -e "\033[31;5mPlease check with developers before running this command" +# if [ $INTERACTIVE == 1 ]; then +# echo -e "'enter' to continue" +# read -t 10 ans < /dev/tty +# fi +fi + # cleanup if [ -f $SELFUPDATE_SCRIPT ]; then rm $SELFUPDATE_SCRIPT fi if [ $INTERACTIVE == 1 ]; then - echo -ne "HIT [Enter] TO REBOOT, CONFIRMING YOU'VE" '"photographed" THE ABOVE PARAGRAPHS: ' + echo -ne "HIT [Y] [Enter] TO REBOOT, [Enter] to exit, CONFIRMING YOU'VE" '"photographed" THE ABOVE PARAGRAPHS: ' + ans=n read ans < /dev/tty - # Sets hostname, improves RTC + memory mgmt, starts BitTorrents if needed, etc! - reboot + if [ "$ans" == "y" ] || [ "$ans" == "Y" ]; then + reboot + fi fi +echo -e "Remember to reboot" exit 0 From c9a7a29fc0856d9a17d294334f0995167f44fd0c Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Thu, 3 Sep 2020 23:08:57 +0100 Subject: [PATCH 38/43] whiptail for check_branch dialog --- iiab-upgrade | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/iiab-upgrade b/iiab-upgrade index 2cac8cae..b1aa0efc 100755 --- a/iiab-upgrade +++ b/iiab-upgrade @@ -116,14 +116,8 @@ check_user_pwd() { update_self if [ `check_branch` -gt 0 ]; then - echo -e "\nFound release-7.X branch would you like (re)install using the latest master?" - echo -e "[Y/n]\n n default 5 second timeout" - ans="n" -# if [ $INTERACTIVE == 1 ]; then -# read -t 5 ans < /dev/tty -# fi - read -t 5 ans < /dev/tty - if [ "$ans" == "y" ] || [ "$ans" == "Y" ]; then + if whiptail --yesno "\nFound release-7.X branch would you like (re)install using the latest master?" 20 60 2 3>&1 1>&2 2>&3; then + echo "matched yes for master" UPDATE=1 else echo "remaning on release-7.X branch updating" From 0ed069f0f2887262ca3495321880186f5b4cae9e Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Fri, 4 Sep 2020 01:37:09 +0100 Subject: [PATCH 39/43] 7.2-install.txt --- 7.2-install.txt | 100 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 7.2-install.txt diff --git a/7.2-install.txt b/7.2-install.txt new file mode 100644 index 00000000..d6dc814d --- /dev/null +++ b/7.2-install.txt @@ -0,0 +1,100 @@ +#!/bin/bash +# Copied from: https://github.com/iiab/iiab-factory/blob/master/install.txt + +# To install Internet-in-a-Box (IIAB) 7.2 / pre-release onto Raspberry Pi OS, +# Ubuntu 20.04 or Debian 10, run this 1-line installer: +# +# curl d.iiab.io/install.txt | sudo bash + +# 1. WARNING: NOOBS IS *NOT* SUPPORTED, as its partitioning is very different. +# On a Raspberry Pi, WE RECOMMEND YOU INSTALL THE LATEST RASPBERRY PI OS: +# https://www.raspberrypi.org/documentation/installation/installing-images/README.md +# To attempt IIAB 7.2 on another Linux see the full/manual instructions: +# https://github.com/iiab/iiab/wiki/IIAB-Installation#do-everything-from-scratch + +# 2. An Ethernet cable is HIGHLY RECOMMENDED during installation, as this is +# more reliable than Wi-Fi (and faster!) + +# 3. Run 'sudo raspi-config' on RPi, to set LOCALISATION OPTIONS + +# 4. OPTIONAL: if you have slow/pricey Internet, pre-position KA Lite's +# mandatory 0.9 GB English Pack (en.zip) within /tmp -- you can grab a copy +# from http://pantry.learningequality.org/downloads/ka-lite/0.17/content/contentpacks/en.zip + +# 5. WHEN YOU RUN 1-LINE INSTALLER 'curl d.iiab.io/install.txt | sudo bash' +# YOU THEN NEED TO TYPE IN YOUR PASSWORD IF ON UBUNTU/DEBIAN/ETC (for sudo) +# ^^^ ^^^^ ^^^^ ^^ ^^^^ ^^ ^^^^ ^^^^^^^^ + +# 6. Follow on-screen instructions (TYPE 'sudo iiab' TO RESUME IF EVER NECESS!) + +# 7. About 1-2 hours later, it will announce that INTERNET-IN-A-BOX (IIAB) +# SOFTWARE INSTALL IS COMPLETE, prompting you to reboot...TO ADD CONTENT! + +# Thanks For Building Your Own Library To Serve One & All +# +# DRAFT IIAB 7.2 Release Notes: +# https://github.com/iiab/iiab/wiki/IIAB-7.2-Release-Notes +# +# Write to bugs @ iiab.io if you find issues, Thank You! Special Thanks to the +# countries+communities+volunteers who worked non-stop to bring about IIAB 7.2! +# +# IIAB Development Team +# http://FAQ.IIAB.IO + +# Copied from: https://github.com/jvonau/iiab-factory/blob/jv-pi-gen/install.txt +set -e # Exit on error (avoids snowballing) +export DEBIAN_FRONTEND=noninteractive # Bypass (most!) interactive questions +BASE=/opt/iiab +BRANCH=release-7.2 +ADMBRANCH=master +echo -e "\n\nDOWNLOAD (CLONE) IIAB'S 3 KEY REPOS INTO $BASE ...\n" +/usr/bin/apt -y install git nano whiptail +mkdir -p $BASE +cd $BASE +echo +if [ -d iiab-factory ]; then + echo -e "REPO iiab-factory EXISTS? -- updating master branch" + cd iiab-factory + git checkout master + git pull + git branch -D $BRANCH &> /dev/null || true + git checkout -b $BRANCH + cp $BASE/iiab-factory/iiab /usr/sbin/iiab +else + echo -e "Cloning iiab-factory" + git clone https://github.com/iiab/iiab-factory --depth 1 + cd iiab-factory + git checkout -b $BRANCH + cp $BASE/iiab-factory/iiab /usr/sbin/iiab +fi +cd $BASE +echo +if [ -d iiab ]; then + echo -e "REPO iiab EXISTS? Consider 'sudo iiab --upgrade'" #FIXME +else + cd iiab + git clone https://github.com/iiab/iiab --depth 10 --branch master + git checkout -b $BRANCH # this goes +# post branching below +# git clone https://github.com/iiab/iiab --depth 10 --branch $BRANCH +# git checkout -b master +# git config branch.master.remote origin +# git config branch.master.merge refs/heads/master +# git checkout $BRANCH +fi +cd $BASE +echo +if [ -d iiab-admin-console ]; then + echo -e "REPO iiab-admin-console EXISTS? Consider 'sudo iiab --upgrade'" #FIXME +else + git clone https://github.com/iiab/iiab-admin-console --depth 1 --branch ADMBRANCH + git checkout -b $BRANCH # this goes +# post branching below +# git checkout -b master +# git config branch.master.remote origin +# git config branch.master.merge refs/heads/master +# git checkout $BRANCH +fi + +# Run install script! +/usr/sbin/iiab From afccf2cf1c73794feffec863f233826a281b8a52 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Fri, 4 Sep 2020 03:42:50 +0100 Subject: [PATCH 40/43] update_self format --- iiab-upgrade | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/iiab-upgrade b/iiab-upgrade index b1aa0efc..21476450 100755 --- a/iiab-upgrade +++ b/iiab-upgrade @@ -80,20 +80,19 @@ function update_self() { cd iiab-factory git checkout master git pull - fi - - NEW_VERSION=$(grep RELEASE /opt/iiab/iiab-factory/$SCRIPT | awk -F = '{print $2}' | head -n 1) - cp $SCRIPT /usr/sbin/$SCRIPT - echo "Latest $SCRIPT now installed" - if [ $NEW_VERSION -gt $RELEASE ]; then - echo " *** Relaunching $SCRIPT after update" - cat > "$SELFUPDATE_SCRIPT" << EOF - #!/bin/bash - exec /usr/sbin/$SCRIPT + NEW_VERSION=$(grep RELEASE $SCRIPT | awk -F = '{print $2}' | head -n 1) + cp $SCRIPT /usr/sbin/$SCRIPT + echo "Latest $SCRIPT now installed" + if [ $NEW_VERSION -gt $RELEASE ]; then + echo " *** Relaunching $SCRIPT after update" + cat > "$SELFUPDATE_SCRIPT" << EOF +#!/bin/bash +exec /usr/sbin/$SCRIPT EOF - exec /bin/bash $SELFUPDATE_SCRIPT - else - echo "Latest $SCRIPT is already running skipping re-exec" + exec /bin/bash $SELFUPDATE_SCRIPT + else + echo "Latest $SCRIPT is already running skipping re-exec" + fi fi } From 09c49fd4b510cca255f58d67b83158b1d3750f37 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Fri, 4 Sep 2020 02:11:28 +0100 Subject: [PATCH 41/43] whiptail for passwords --- iiab-upgrade | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/iiab-upgrade b/iiab-upgrade index 21476450..c2c92a7b 100755 --- a/iiab-upgrade +++ b/iiab-upgrade @@ -128,10 +128,16 @@ fi # B. Ask for password change if pi/raspberry default remains if check_user_pwd "pi" "raspberry"; then - echo -e "\n\nRaspberry Pi's are COMPROMISED often if the default password is not changed!\n" - echo -n "What password do you want for GNU/Linux user 'pi' ? " - read -t 5 ans < /dev/tty # Whines but doesn't change password if [Enter] - echo pi:"$ans" | chpasswd || true # Overrides 'set -e' + if [ $INTERACTIVE == 1 ]; then + whiptail --msgbox "\ +Raspberry Pi's are COMPROMISED often if the default password is not changed! +What password do you want for GNU/Linux user 'pi' ? +press [Enter] 3 times for no change \ +" 20 60 1 + passwd raspberry && + whiptail --msgbox "done" 20 60 1 + #chpasswd || true # Overrides 'set -e' + fi fi # C. Create user 'iiab-admin' as nec, with default password @@ -142,14 +148,16 @@ fi # D. Ask for password change if iiab-admin/g0adm1n default remains if check_user_pwd "iiab-admin" "g0adm1n"; then - echo -e "\n\nUser 'iiab-admin' retains default password 'g0adm1n' per http://FAQ.IIAB.IO\n" - - echo -e "This is for login to Internet-in-a-Box's Admin Console (http://box.lan/admin)\n" if [ $INTERACTIVE == 1 ]; then - echo -n "What password do you want for GNU/Linux user 'iiab-admin' ? " - echo -n "press [Enter] for no change" - read -t 15 ans < /dev/tty # Whines but doesn't change password if [Enter] - echo iiab-admin:"$ans" | chpasswd || true # Overrides 'set -e' + whiptail --msgbox "\ +User 'iiab-admin' retains default password 'g0adm1n' per http://FAQ.IIAB.IO +This is for login to Internet-in-a-Box's Admin Console (http://box.lan/admin) +What password do you want for GNU/Linux user 'iiab-admin' ? +press [Enter] 3 times for no change / +" 20 60 1 + passwd iiab-admin && + whiptail --msgbox "done" 20 60 1 + #chpasswd || true # Overrides 'set -e' fi fi From 7d32e6cab1249819db053f2fe7ce0b160316fa02 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Fri, 4 Sep 2020 06:49:28 +0100 Subject: [PATCH 42/43] ansible --- iiab-upgrade | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/iiab-upgrade b/iiab-upgrade index c2c92a7b..8bed2b40 100755 --- a/iiab-upgrade +++ b/iiab-upgrade @@ -233,6 +233,16 @@ echo -e " ██ echo -e " ██ RUN 'sudo iiab' IF THIS INSTALL SCRIPT EVER FAILS, TO TRY TO CONTINUE! ██" echo -e " ██ ██" echo -e " ██████████████████████████████████████████████████████████████████████████████" +echo -e "\n" +# catch updates when apt runs +# add logic to force updates later +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 skipping install!" +else + echo -e "Install Ansible..." + $BASEDIR/iiab/scripts/ansible +fi echo -e "\n\n'apt update' is checking for OS updates...\n" #echo -e "2019-07-11 TEMP WORKAROUND FOR RASPBIAN BUSTER'S testing->stable apt GLITCH...\nDetails @ https://github.com/iiab/iiab/issues/1856\n" #apt -y update || true # Overrides 'set -e' @@ -274,10 +284,7 @@ if [ -e /dev/mmcblk0p2 ]; then fi # I. Install Ansible + 2 IIAB repos -echo -e "\n\nINSTALL ANSIBLE + CORE IIAB SOFTWARE + ADMIN CONSOLE / CONTENT PACK MENUS...\n" - -echo -e "Install Ansible..." -$BASEDIR/iiab/scripts/ansible +#echo -e "\n\nINSTALL ANSIBLE + CORE IIAB SOFTWARE + ADMIN CONSOLE / CONTENT PACK MENUS...\n" echo -e "\n┌──────────────────────────────────────────────────────────────────────────────┐" echo -e "│ │" From e735e1c7836c2f7fa62a9f0c86d7973d84ed941e Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Fri, 4 Sep 2020 07:37:09 +0100 Subject: [PATCH 43/43] sync iiab to iiab-upgrade --- iiab | 185 +++++++++++++++++++++++++++++---------------------- iiab-upgrade | 3 +- 2 files changed, 109 insertions(+), 79 deletions(-) diff --git a/iiab b/iiab index 6e41967c..7c1f3d99 100755 --- a/iiab +++ b/iiab @@ -47,14 +47,14 @@ SCRIPT=iiab RELEASE=1 BASEDIR=/opt/iiab CONFDIR=/etc/iiab +IIABENV=$CONFDIR/iiab.env FLAGDIR=$CONFDIR/install-flags APT_PATH=/usr/bin/apt # Avoids problematic /usr/local/bin/apt on Linux Mint +INTERACTIVE=1 REINSTALL="" -INTERACTIVE=0 UPDATE=0 MIN_RPI_KERN=1336 SELFUPDATE_SCRIPT="/tmp/.updateScript.sh" - # scrape the command line if [ "$1" = "--non-interactive" ]; then shift 1 @@ -65,7 +65,7 @@ if [ "$1" = "--upgrade" ]; then shift 1 rm $FLAGS/iiab*complete || true UPDATE=1 - REINSTALL="--reinstall" +# REINSTALL="--reinstall" fi if [ "$1" = "--reinstall" ]; then @@ -73,11 +73,6 @@ if [ "$1" = "--reinstall" ]; then REINSTALL="--reinstall" fi -# cleanup -#if [ -f $SELFUPDATE_SCRIPT ]; then -# rm $SELFUPDATE_SCRIPT -#fi - # Subroutines for upgrade logic check_branch(){ git -C $BASEDIR/iiab branch | grep \* | grep release-7 | wc -l @@ -107,6 +102,7 @@ function update_master(){ echo -e "\nUpdating iiab" git checkout master git pull + NEWREV=$(grep iiab_revision vars/default_vars.yml | awk '{print $2}') fi cd $BASEDIR if [ -d iiab-admin-console ]; then @@ -117,26 +113,7 @@ function update_master(){ fi } -if [ `check_branch` -gt 0 ]; then - echo -e "\nFound release-7.X branch would you like (re)install using the latest master?" - echo -e "[Y/n]\n n default 5 second timeout" - ans="n" -# if [ $INTERACTIVE == 1 ]; then -# read -t 5 ans < /dev/tty -# fi - read -t 5 ans < /dev/tty - if [ "$ans" == "y" ] || [ "$ans" == "Y" ]; then - UPDATE=1 - else - echo "remaning on release-7.X branch updating" - cd $BASEDIR/iiab - git pull - fi -fi - function update_self() { - cat > "$SELFUPDATE_SCRIPT" << EOF - #!/bin/bash echo " *** Performing self-update" cd $BASEDIR if [ -d iiab-factory ]; then @@ -144,22 +121,27 @@ function update_self() { cd iiab-factory git checkout master git pull - fi - VERSION=$RELEASE - NEW_VERSION=`grep RELEASE /opt/iiab/iiab-factory/$SCRIPT | awk -F = '{print $2}' | head -n 1` - - if [ $NEW_VERSION -gt $VERSION ]; then - cp /opt/iiab/iiab-factory/$SCRIPT /usr/sbin/$SCRIPT + NEW_VERSION=$(grep RELEASE $SCRIPT | awk -F = '{print $2}' | head -n 1) + cp $SCRIPT /usr/sbin/$SCRIPT echo "Latest $SCRIPT now installed" - else - echo "Latest $SCRIPT is already installed" - fi - exec env /bin/bash /usr/sbin/$SCRIPT + if [ $NEW_VERSION -gt $RELEASE ]; then + echo " *** Relaunching $SCRIPT after update" + cat > "$SELFUPDATE_SCRIPT" << EOF +#!/bin/bash +exec /usr/sbin/$SCRIPT EOF - echo " *** Relaunching $SCRIPT after update" - exec /bin/bash $SELFUPDATE_SCRIPT + exec /bin/bash $SELFUPDATE_SCRIPT + else + echo "Latest $SCRIPT is already running skipping re-exec" + fi + 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" +version_gt() { [ "$(printf '%s\n' "$@" | sort -V | head -1)" != "$1" ]; } + # A. Subroutine for B. and D. Returns true (0) if username ($1) exists with password ($2) check_user_pwd() { # $meth (hashing method) is typically '6' which implies 5000 rounds @@ -170,12 +152,33 @@ check_user_pwd() { [ $(python3 -c "import crypt; print(crypt.crypt('$2', '\$$meth\$$salt'))") == "\$$meth\$$salt\$$hash" ] } +# start exec here +update_self + +if [ `check_branch` -gt 0 ]; then + if whiptail --yesno "\nFound release-7.X branch would you like (re)install using the latest master?" 20 60 2 3>&1 1>&2 2>&3; then + echo "matched yes for master" + UPDATE=1 + else + echo "remaning on release-7.X branch updating" + cd $BASEDIR/iiab + git pull + NEWREV=$(grep iiab_revision vars/default_vars.yml | awk '{print $2}') + fi +fi + # B. Ask for password change if pi/raspberry default remains if check_user_pwd "pi" "raspberry"; then - echo -e "\n\nRaspberry Pi's are COMPROMISED often if the default password is not changed!\n" - echo -n "What password do you want for GNU/Linux user 'pi' ? " - read -t 5 ans < /dev/tty # Whines but doesn't change password if [Enter] - echo pi:"$ans" | chpasswd || true # Overrides 'set -e' + if [ $INTERACTIVE == 1 ]; then + whiptail --msgbox "\ +Raspberry Pi's are COMPROMISED often if the default password is not changed! +What password do you want for GNU/Linux user 'pi' ? +press [Enter] 3 times for no change \ +" 20 60 1 + passwd raspberry && + whiptail --msgbox "done" 20 60 1 + #chpasswd || true # Overrides 'set -e' + fi fi # C. Create user 'iiab-admin' as nec, with default password @@ -186,14 +189,16 @@ fi # D. Ask for password change if iiab-admin/g0adm1n default remains if check_user_pwd "iiab-admin" "g0adm1n"; then - echo -e "\n\nUser 'iiab-admin' retains default password 'g0adm1n' per http://FAQ.IIAB.IO\n" - - echo -e "This is for login to Internet-in-a-Box's Admin Console (http://box.lan/admin)\n" if [ $INTERACTIVE == 1 ]; then - echo -n "What password do you want for GNU/Linux user 'iiab-admin' ? " - echo -n "press [Enter] for no change" - read -t 15 ans < /dev/tty # Whines but doesn't change password if [Enter] - echo iiab-admin:"$ans" | chpasswd || true # Overrides 'set -e' + whiptail --msgbox "\ +User 'iiab-admin' retains default password 'g0adm1n' per http://FAQ.IIAB.IO +This is for login to Internet-in-a-Box's Admin Console (http://box.lan/admin) +What password do you want for GNU/Linux user 'iiab-admin' ? +press [Enter] 3 times for no change / +" 20 60 1 + passwd iiab-admin && + whiptail --msgbox "done" 20 60 1 + #chpasswd || true # Overrides 'set -e' fi fi @@ -258,7 +263,6 @@ else fi if [ $UPDATE == 1 ]; then - update_self use_master update_master fi @@ -270,6 +274,16 @@ echo -e " ██ echo -e " ██ RUN 'sudo iiab' IF THIS INSTALL SCRIPT EVER FAILS, TO TRY TO CONTINUE! ██" echo -e " ██ ██" echo -e " ██████████████████████████████████████████████████████████████████████████████" +echo -e "\n" +# catch updates when apt runs +# add logic to force updates later +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 skipping install!" +else + echo -e "Install Ansible..." + $BASEDIR/iiab/scripts/ansible +fi echo -e "\n\n'apt update' is checking for OS updates...\n" #echo -e "2019-07-11 TEMP WORKAROUND FOR RASPBIAN BUSTER'S testing->stable apt GLITCH...\nDetails @ https://github.com/iiab/iiab/issues/1856\n" #apt -y update || true # Overrides 'set -e' @@ -300,25 +314,6 @@ if [ $INTERACTIVE == 1 ]; then read -t 5 ans < /dev/tty 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" -version_gt() { [ "$(printf '%s\n' "$@" | sort -V | head -1)" != "$1" ]; } - -# Verify that Raspbian is running a recent enough kernel. As Raspbian -# kernel 1333 has wifi issues https://github.com/iiab/iiab/issues/2497. -CURR_KERN=`uname -v | awk '{print $1}' | sed -e s'/#//'` -echo "Found Kernel ""$CURR_KERN" -if [ -f /etc/rpi-issue ] && version_gt $MIN_RPI_KERN $CURR_KERN; then - echo -e "\033[31;5mWARNING: Kernel ""$MIN_RPI_KERN"" or higher required with Raspbian.\033[0m" -# echo -e "\033[31;5mPLEASE RUN 'apt update' then 'apt install raspberrypi-kernel' then reboot.\033[0m" - echo -e "\033[31;5mTHEN IF NEC run 'rpi-update' to install a more recent kernel post-install, then reboot.\033[0m" - echo -e "'enter' to continue" - if [ $INTERACTIVE == 1 ]; then - read -t 10 ans < /dev/tty - fi -fi - ######################### INTERACTIVE STUFF IS ABOVE ######################### @@ -330,10 +325,7 @@ if [ -e /dev/mmcblk0p2 ]; then fi # I. Install Ansible + 2 IIAB repos -echo -e "\n\nINSTALL ANSIBLE + CORE IIAB SOFTWARE + ADMIN CONSOLE / CONTENT PACK MENUS...\n" - -echo -e "Install Ansible..." -$BASEDIR/iiab/scripts/ansible +#echo -e "\n\nINSTALL ANSIBLE + CORE IIAB SOFTWARE + ADMIN CONSOLE / CONTENT PACK MENUS...\n" echo -e "\n┌──────────────────────────────────────────────────────────────────────────────┐" echo -e "│ │" @@ -345,7 +337,21 @@ echo -e "│ child script ./iiab-install -- both avoid repeating any of the 9 echo -e "│ │" echo -e "└──────────────────────────────────────────────────────────────────────────────┘" cd $BASEDIR/iiab/ -./iiab-install $REINSTALL +if [ -f $IIABENV ] && [ $UPDATE == 1 ]; then + source $IIABENV + OLDREV=$IIAB_REVISION + if [ -f upgrade_roles ]; then + for REV in $(cat upgrade_roles | awk '{print $1}'); do + if [ $REV -gt $OLDREV ]; then + force=$(grep $REV upgrade_roles | awk '{print $2}') + sed -i -e '/^$force/d' $CONFDIR/iiab_state.yml + fi + done + fi + ./iiab-configure +else + ./iiab-install $REINSTALL +fi echo -e "Install Admin Console... (also runs iiab-get-kiwix-cat to d/l Kiwix catalog, and installs Dynamic Menuing for /library/www/html/home/index.html)\n" if [ ! -f $FLAGDIR/iiab-admin-console-complete ] || [ $UPDATE == 1 ]; then @@ -440,9 +446,32 @@ echo -e "global community, learning from other initiatives in your region and be #echo -e "(over Wi-Fi anyway) until you later run 'iiab-hotspot-off'. CAVEAT: these" #echo -e "two commands only work with Raspberry Pi as of 2019-09-30.\n" +# Verify that Raspbian is running a recent enough kernel. As Raspbian +# kernel 1333 has wifi issues https://github.com/iiab/iiab/issues/2497. +CURR_KERN=`uname -v | awk '{print $1}' | sed -e s'/#//'` +echo "Found Kernel ""$CURR_KERN" +if [ -f /etc/rpi-issue ] && version_gt $MIN_RPI_KERN $CURR_KERN; then + echo -e "\033[31;5mWARNING: Kernel ""$MIN_RPI_KERN"" or higher required with Raspbian.\033[0m" +# echo -e "\033[31;5mPLEASE RUN 'apt update' then 'apt install raspberrypi-kernel' then reboot.\033[0m" + echo -e "\033[31;5mTHEN IF NEC run 'rpi-update' to install a more recent kernel \033[0m" + echo -e "\033[31;5mPlease check with developers before running this command" +# if [ $INTERACTIVE == 1 ]; then +# echo -e "'enter' to continue" +# read -t 10 ans < /dev/tty +# fi +fi + +# cleanup +if [ -f $SELFUPDATE_SCRIPT ]; then + rm $SELFUPDATE_SCRIPT +fi if [ $INTERACTIVE == 1 ]; then - echo -ne "HIT [Enter] TO REBOOT, CONFIRMING YOU'VE" '"photographed" THE ABOVE PARAGRAPHS: ' + echo -ne "HIT [Y] [Enter] TO REBOOT, [Enter] to exit, CONFIRMING YOU'VE" '"photographed" THE ABOVE PARAGRAPHS: ' + ans=n read ans < /dev/tty - # Sets hostname, improves RTC + memory mgmt, starts BitTorrents if needed, etc! - reboot + if [ "$ans" == "y" ] || [ "$ans" == "Y" ]; then + reboot + fi fi +echo -e "Remember to reboot" +exit 0 diff --git a/iiab-upgrade b/iiab-upgrade index 8bed2b40..24fa448d 100755 --- a/iiab-upgrade +++ b/iiab-upgrade @@ -1,4 +1,5 @@ #!/bin/bash +# Copied from: https://github.com/jvonau/iiab-factory/blob/iiab-update/iiab-update # jvonau set -e # Exit on error (avoids snowballing) export DEBIAN_FRONTEND=noninteractive # Bypass (most!) interactive questions @@ -9,8 +10,8 @@ CONFDIR=/etc/iiab IIABENV=$CONFDIR/iiab.env FLAGDIR=$CONFDIR/install-flags APT_PATH=/usr/bin/apt # Avoids problematic /usr/local/bin/apt on Linux Mint -REINSTALL="" INTERACTIVE=0 +REINSTALL="" UPDATE=0 MIN_RPI_KERN=1336 SELFUPDATE_SCRIPT="/tmp/.updateScript.sh"