Skip to content

Commit

Permalink
introduce flags & softcoding
Browse files Browse the repository at this point in the history
  • Loading branch information
jvonau committed Oct 4, 2019
1 parent 5b958ae commit 60f6dec
Showing 1 changed file with 49 additions and 29 deletions.
78 changes: 49 additions & 29 deletions iiab
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@

set -e # Exit on error (avoids snowballing)
export DEBIAN_FRONTEND=noninteractive # Bypass (most!) interactive questions
BASE=/opt/iiab
CONFIGDIR=/etc/iiab
FLAGS=$CONFIGDIR/flags

# A. Subroutine for B. and D. Returns true (0) if username ($1) exists with password ($2)
check_user_pwd() {
Expand Down Expand Up @@ -82,20 +85,20 @@ if check_user_pwd "iiab-admin" "g0adm1n"; then
echo iiab-admin:"$ans" | chpasswd || true # Overrides 'set -e'
fi

# E. Position & customize /etc/iiab/local_vars.yml
mkdir -p /etc/iiab
cd /etc/iiab/
# E. Position & customize $CONFIGDIR/local_vars.yml
mkdir -p $FLAGS
cd $CONFIGDIR
if [ -f local_vars.yml ]; then

# FUTURE: Test if their local_vars.yml is sufficiently version-compatible !

echo -e "\n\n EXISTING /etc/iiab/local_vars.yml is being used to install Internet-in-a-Box\n"
echo -e "\n\n EXISTING $CONFIGDIR/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 /etc/iiab/local_vars.yml"
echo -e "\n\nInstalling Internet-in-a-Box requires $CONFIGDIR/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"
Expand All @@ -108,7 +111,6 @@ else
echo -n "Please type 1, 2 or 3 then press [ENTER]: "
read 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
Expand All @@ -121,23 +123,25 @@ else
;;
esac

echo -en "\nEdit /etc/iiab/local_vars.yml to customize your Internet-in-a-Box? [Y/n] "
echo -en "\nEdit $CONFIGDIR/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 /etc/iiab/local_vars.yml\n"
echo -e "\n1) PLEASE RUN: sudo nano $CONFIGDIR/local_vars.yml\n"

echo -e "2) After you're done editing, RUN 'sudo iiab' TO CONTINUE!\n"
exit 0
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 ██████████████████████████████████████████████████████████████████████████████"
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"
Expand Down Expand Up @@ -172,10 +176,10 @@ if [ -f /proc/device-tree/model ] && grep -qi raspberry /proc/device-tree/model;
fi

# H. Clone 3 IIAB repos
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
mkdir -p /opt/iiab
cd /opt/iiab/
mkdir -p $BASE
cd $BASE
echo
if [ -d iiab ]; then
echo -e "REPO EXISTS? Consider 'cd /opt/iiab/iiab; git pull'"
Expand All @@ -199,7 +203,7 @@ fi
echo -e "\n\nINSTALL ANSIBLE + CORE IIAB SOFTWARE + ADMIN CONSOLE / CONTENT PACK MENUS...\n"

echo -e "Install Ansible..."
cd /opt/iiab/iiab/scripts/
cd $BASE/iiab/scripts/
./ansible
echo -e "\n┌──────────────────────────────────────────────────────────────────────────────┐"
echo -e "│ │"
Expand All @@ -210,45 +214,61 @@ echo -e "│
echo -e "│ child script ./iiab-install -- both avoid repeating any of the 9 stages. │"
echo -e "│ │"
echo -e "└──────────────────────────────────────────────────────────────────────────────┘"
cd /opt/iiab/iiab/
cd $BASE/iiab/
./iiab-install $@
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"
cd /opt/iiab/iiab-admin-console/
./install

if [ ! -f $FLAGS/iiab-admin-console-complete ]; then
cd $BASE/iiab-admin-console
./install
touch $FLAGS/iiab-admin-console-complete
else
echo -e 'iiab-admin-console complete'
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'
kalite manage generate_zone || true # Overrides 'set -e' allowing repeat run
if [ ! -f $FLAGS/kalite-zone-complete ]; then
echo -e 'Now running kalite zone'
kalite manage generate_zone || true
touch $FLAGS/kalite-zone-complete
else
echo -e 'kalite zone already done'
fi

echo -e "\nInstall KA Lite's mandatory 0.9 GB English Pack... (en.zip)\n"
cd /tmp/ # Or /opt/iiab/downloads or /library/downloads if you prefer
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
if [ ! -f $FLAGS/kalite-en.zip-complete ]; then
echo -e 'Now retreiving kalite en.zip'
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. Removing\n" >&2
exit 1
else
echo -e "\nUsing existing /tmp/en.zip whose 929,916,955 byte size is correct!\n"
fi
else
echo -e "\nUsing existing /tmp/en.zip whose 929,916,955 byte size is correct!\n"
wget http://pantry.learningequality.org/downloads/ka-lite/0.17/content/contentpacks/en.zip
fi
else
wget http://pantry.learningequality.org/downloads/ka-lite/0.17/content/contentpacks/en.zip
echo -e 'Now installing kalite en.zip'
kalite manage retrievecontentpack local en en.zip
touch $FLAGS/kalite-en.zip-complete
fi
kalite manage retrievecontentpack local en en.zip
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 /etc/iiab/local_vars.yml requested any
# K. Start BitTorrent downloads, e.g. if $CONFIGDIR/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 $FLAGS/iiab-complete
# L. Educate Implementers prior to rebooting!
echo -e "\n\n ┌───────────────────────────────────────────────────────────┐"
echo -e " │ │"
Expand Down

0 comments on commit 60f6dec

Please sign in to comment.