-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #158 from holta/add-PRs-during-1-line-install
1-line-installer: facilitate testing w/ instant install of CLI-specified PR's e.g. 'sudo iiab 361 2607'
- Loading branch information
Showing
2 changed files
with
145 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,15 +46,18 @@ | |
|
||
set -e # Exit on error (avoids snowballing) | ||
export DEBIAN_FRONTEND=noninteractive # Bypass (most!) interactive questions | ||
BASEDIR=/opt/iiab | ||
CONFDIR=/etc/iiab | ||
FLAGDIR=$CONFDIR/install-flags | ||
FLAGDIR=/etc/iiab/install-flags | ||
APTPATH=/usr/bin # Avoids problematic /usr/local/bin/apt on Linux Mint | ||
|
||
[ $(id -un) = root ] || { echo "Please run 'sudo iiab'" ; exit 1 ; } | ||
|
||
mkdir -p $FLAGDIR # Whih also creates /etc/iiab | ||
# Save CLI params (PR #s) for section I. so 'sudo iiab' continues after reboots | ||
[ $# != 0 ] && printf '%s\n' "$@" >> /etc/iiab/pr-queue | ||
|
||
# A. Subroutine for B. and D. Returns true (0) if username ($1) exists with password ($2) | ||
command -v grep &> /dev/null || $APTPATH/apt -y install grep # 3 MORE BELOW! | ||
command -v grep &> /dev/null || | ||
$APTPATH/apt -y install grep # AVOID UX CLUTTER+DELAYS: 4 MORE BELOW! | ||
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 | ||
|
@@ -65,7 +68,7 @@ check_user_pwd() { | |
} | ||
|
||
# B. Ask for password change if pi/raspberry default remains | ||
if check_user_pwd "pi" "raspberry" ; then | ||
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' ? " | ||
|
@@ -94,7 +97,7 @@ if ! grep -q '^iiab_admin_user_install:\s\+[fF]alse\b' /etc/iiab/local_vars.yml | |
fi | ||
|
||
# D. If 'iiab-admin' (or equivalent) use the default password, prompt for change | ||
if check_user_pwd "$IIAB_ADMIN_USER" "$IIAB_ADMIN_PUBLISHED_PWD" ; then | ||
if check_user_pwd "$IIAB_ADMIN_USER" "$IIAB_ADMIN_PUBLISHED_PWD"; then | ||
echo -e "\n\nUser '$IIAB_ADMIN_USER' retains default password '$IIAB_ADMIN_PUBLISHED_PWD' per http://FAQ.IIAB.IO\n" | ||
|
||
echo -e "This is for login to Internet-in-a-Box's Admin Console (http://box.lan/admin)" | ||
|
@@ -105,28 +108,29 @@ if check_user_pwd "$IIAB_ADMIN_USER" "$IIAB_ADMIN_PUBLISHED_PWD" ; then | |
echo "$IIAB_ADMIN_USER":"$ans" | chpasswd || true # Overrides 'set -e' | ||
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 | ||
|
||
# E. Position & customize $CONFDIR/local_vars.yml | ||
command -v wget &> /dev/null || $APTPATH/apt -y install wget # AS ABOVE (grep) | ||
command -v nano &> /dev/null || $APTPATH/apt -y install nano # AND BELOW (git) | ||
cd $CONFDIR | ||
if [ -f local_vars.yml ]; then | ||
# E. Position & customize /etc/iiab/local_vars.yml | ||
command -v wget &> /dev/null || | ||
$APTPATH/apt -y install wget # AS ABOVE (grep) | ||
command -v nano &> /dev/null || | ||
$APTPATH/apt -y install nano # BELOW (git, jq) | ||
local_vars_src_file=local_vars_big.yml # Testing default, for section I. (PR's can change local_vars.yml templates) | ||
if [ -f /etc/iiab/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\n EXISTING /etc/iiab/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\n" | ||
echo -e "\n\nInstalling Internet-in-a-Box requires /etc/iiab/local_vars.yml\n" | ||
|
||
echo -e "Do you want (1) 🚵 MIN-sized (2) 🚢🚣 MEDIUM-sized or (3) 🚂🚃🚃 BIG-sized?" | ||
echo -e "Or (m) for 🚑 MEDICAL? YOU NEED 2 GB RAM OR HIGHER, IF YOU CHOOSE (3)\n" | ||
|
@@ -142,23 +146,28 @@ else | |
echo | ||
case $local_vars_size in | ||
1) | ||
wget -O local_vars.yml https://github.com/iiab/iiab/raw/master/vars/local_vars_min.yml | ||
local_vars_src_file=local_vars_min.yml | ||
;; | ||
3) | ||
wget -O local_vars.yml https://github.com/iiab/iiab/raw/master/vars/local_vars_big.yml | ||
local_vars_src_file=local_vars_big.yml | ||
;; | ||
m) | ||
wget -O local_vars.yml https://github.com/iiab/iiab/raw/master/vars/local_vars_medical.yml | ||
local_vars_src_file=local_vars_medical.yml | ||
;; | ||
*) | ||
wget -O local_vars.yml https://github.com/iiab/iiab/raw/master/vars/local_vars_medium.yml | ||
local_vars_src_file=local_vars_medium.yml | ||
;; | ||
esac | ||
if [ -d /opt/iiab/iiab/vars ]; then | ||
cp /opt/iiab/iiab/vars/$local_vars_src_file /etc/iiab/local_vars.yml | ||
else | ||
wget -O /etc/iiab/local_vars.yml https://github.com/iiab/iiab/raw/master/vars/$local_vars_src_file | ||
fi | ||
|
||
echo -en "\nEdit $CONFDIR/local_vars.yml to customize your Internet-in-a-Box? [Y/n] " | ||
echo -en "\nEdit /etc/iiab/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 "\n1) PLEASE RUN: sudo nano /etc/iiab/local_vars.yml\n" | ||
|
||
echo -e "2) After you're done editing, RUN 'sudo iiab' TO CONTINUE!\n" | ||
exit 0 | ||
|
@@ -178,7 +187,7 @@ echo -e "\n\n'apt update' is checking for OS updates...\n" | |
#apt -y update || true # Overrides 'set -e' | ||
#echo -e "\nNOW THE REAL 'apt update' WILL RUN...\n" | ||
$APTPATH/apt -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 | ||
if (( $(wc -c < /tmp/apt.stderr) > 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 | ||
|
@@ -198,44 +207,137 @@ 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 | ||
|
||
######################### INTERACTIVE STUFF IS ABOVE ######################### | ||
####################### MAIN INTERACTIVE STUFF IS ABOVE ####################### | ||
|
||
# G. If RPi, lower reserve disk space from ~5% to 2% | ||
# G. If microSD, lower reserve disk space from ~5% to 2% | ||
#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 2%\n" | ||
tune2fs -m 2 /dev/mmcblk0p2 | ||
fi | ||
|
||
# H. Clone 3 IIAB repos | ||
echo -e "\n\nDOWNLOAD (CLONE) IIAB'S 3 KEY REPOS INTO $BASEDIR ...\n" | ||
$APTPATH/apt -y install git # grep, wget, nano ABOVE -- AVOID UX CLUTTER+DELAYS | ||
mkdir -p $BASEDIR | ||
cd $BASEDIR | ||
echo -e "\n\nDOWNLOAD (CLONE) IIAB'S 3 KEY REPOS INTO /opt/iiab ..." | ||
command -v git &> /dev/null || | ||
$APTPATH/apt -y install git # AVOID UX CLUTTER+DELAYS | ||
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 | ||
git clone https://github.com/iiab/iiab | ||
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 | ||
git clone https://github.com/iiab/iiab-admin-console | ||
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 | ||
git clone https://github.com/iiab/iiab-factory | ||
fi | ||
|
||
# I. Install optional PR's | ||
echo -e "\n\nINSTALL PR's FROM iiab/iiab OR iiab/iiab-admin-console -- USAGE EXAMPLES:\n" | ||
echo -e " sudo iiab 361 2604 2607" | ||
echo -e " curl d.iiab.io/install.txt | sudo bash -s 361 2604 2607" | ||
command -v jq &> /dev/null || | ||
$APTPATH/apt -y install jq # sed to avoid delays? | ||
if [ $# != 0 ]; then # Stub email for 'git pull' if one isn't already set | ||
git config --get user.email 1> /dev/null || | ||
git config --global user.email "[email protected]" | ||
echo -e "\nYour git email is set to: $(git config --get user.email)" | ||
echo -e 'Change this by running: sudo git config --global user.email "[email protected]"' | ||
fi | ||
|
||
cp /opt/iiab/iiab/vars/$local_vars_src_file /tmp | ||
# Similar to 'for pr in "$@"' but survives reboots: | ||
while [ -s /etc/iiab/pr-queue ] # Test that file exists and is non-empty | ||
do | ||
pr=$(head -1 /etc/iiab/pr-queue) # Try the next PR, from top of queue | ||
if ! [[ "$pr" =~ ^[1-9][0-9]*$ ]]; then | ||
echo -e "\n\e[1mInvalid PR number:\e[0m $pr\n" | ||
echo -n "Delete it from top of /etc/iiab/pr-queue and continue? [Y/n] " | ||
read ans < /dev/tty | ||
[ "$ans" = "n" ] || [ "$and" = "N" ] && | ||
exit 1 | ||
sed -i '1d' /etc/iiab/pr-queue # Delete 1st line | ||
continue | ||
fi | ||
|
||
if (( pr >= 1561 )); then # iiab/iiab's lowest PR as of October 2020 | ||
repo=iiab | ||
else | ||
repo=iiab-admin-console | ||
fi | ||
|
||
http_code=$(curl -sH "Accept: application/vnd.github.v3" https://api.github.com/repos/iiab/$repo/pulls/$pr -w "%{http_code}" -o /tmp/iiab-pr.json) | ||
if [ "$http_code" != 200 ] ; then | ||
echo -e "\n\e[41mCOULD NOT FIND PR #$pr (https://github.com/iiab/$repo/pull/$pr)\e[0m\n" | ||
echo -en "\e[41mHTTP ERROR: $http_code\e[0m\e[1m " | ||
[ "$http_code" = 403 ] && | ||
echo -en "(DID YOU REQUEST 60+ PR's IN ONE HOUR?)" | ||
[ "$http_code" = 404 ] && | ||
echo -en "(IS #$pr AN ISSUE, RATHER THAN A PR?)" | ||
echo -e "\n" | ||
|
||
cat /tmp/iiab-pr.json # GitHub sometimes includes an English explanation of the error, and URL, e.g. https://developer.github.com/v3/#rate-limiting | ||
echo | ||
curl -IsH "Accept: application/vnd.github.v3" https://api.github.com/repos/iiab/$repo/pulls/$pr # HTTP headers typically reveal a lot more! | ||
|
||
echo -n "Delete it from top of /etc/iiab/pr-queue and continue? [Y/n] " | ||
read ans < /dev/tty | ||
[ "$ans" = "n" ] || [ "$and" = "N" ] && | ||
exit 1 | ||
sed -i '1d' /etc/iiab/pr-queue # Delete 1st line | ||
continue | ||
fi | ||
|
||
account=$(jq -r '.head.label' /tmp/iiab-pr.json | cut -d: -f1) | ||
branch=$(jq -r '.head.label' /tmp/iiab-pr.json | cut -d: -f2) | ||
|
||
echo -e "\nPR #$pr: cd /opt/iiab/$repo" | ||
cd /opt/iiab/$repo | ||
#git checkout -b POTLUCK master || true # If test branch name/norm in future...for both repos? | ||
echo -e "git pull --no-edit https://github.com/$account/$repo $branch" # Or $repo.git | ||
git pull --no-edit https://github.com/$account/$repo $branch || { | ||
echo -e "\n\e[1mgit exit/error code:\e[0m $?\n" # if hides err code | ||
echo -n "Delete it from top of /etc/iiab/pr-queue and continue? [Y/n] " | ||
read ans < /dev/tty | ||
[ "$ans" = "n" ] || [ "$and" = "N" ] && | ||
exit 1 | ||
sed -i '1d' /etc/iiab/pr-queue # Delete 1st line | ||
continue | ||
} | ||
|
||
sed -i '1d' /etc/iiab/pr-queue # Delete 1st line | ||
echo "$pr $(date '+%F %T %Z')" >> /etc/iiab/pr-list-pulled # For iiab-diagnostics | ||
done | ||
|
||
if ! cmp -s /tmp/$local_vars_src_file /opt/iiab/iiab/vars/$local_vars_src_file; then | ||
mv /etc/iiab/local_vars.yml /etc/iiab/local_vars.yml.old | ||
cp /opt/iiab/iiab/vars/$local_vars_src_file /etc/iiab/local_vars.yml | ||
|
||
echo -e "\n\e[1mWARNING: /opt/iiab/iiab/vars/$local_vars_src_file HAS CHANGED!\n" | ||
echo -e "YOUR /etc/iiab/local_vars.yml WAS MOVED TO /etc/iiab/local_vars.yml.old\e[0m\n" | ||
echo -n "Edit the NEW /etc/iiab/local_vars.yml to customize 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 "2) After you're done editing, RUN 'sudo iiab' TO CONTINUE!\n" | ||
exit 0 | ||
fi | ||
fi | ||
|
||
# I. Install Ansible + 2 IIAB repos | ||
# J. Install Ansible + 2 IIAB repos | ||
echo -e "\n\nINSTALL ANSIBLE + CORE IIAB SOFTWARE + ADMIN CONSOLE / CONTENT PACK MENUS...\n" | ||
|
||
echo -e "Install Ansible..." | ||
cd $BASEDIR/iiab/scripts/ | ||
cd /opt/iiab/iiab/scripts/ | ||
./ansible | ||
|
||
echo -e "\n┌──────────────────────────────────────────────────────────────────────────────┐" | ||
|
@@ -247,8 +349,8 @@ 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 /opt/iiab/iiab/ | ||
./iiab-install # "$@" | ||
|
||
if [ -f $FLAGDIR/iiab-admin-console-complete ]; then | ||
echo -e "ADMIN CONSOLE INSTALLATION IS ALREADY COMPLETE -- per existence of:" | ||
|
@@ -260,7 +362,7 @@ else | |
echo -e "Install Admin Console... (also runs iiab-get-kiwix-cat to d/l Kiwix catalog," | ||
echo -e "and installs Dynamic Menuing for /library/www/html/home/index.html)\n" | ||
|
||
cd $BASEDIR/iiab-admin-console | ||
cd /opt/iiab/iiab-admin-console | ||
./install | ||
touch $FLAGDIR/iiab-admin-console-complete | ||
fi | ||
|
@@ -279,7 +381,7 @@ else | |
systemctl start iiab-cmdsrv || true # Overrides 'set -e' | ||
fi | ||
|
||
# J. KA Lite prep | ||
# K. KA Lite prep | ||
if [ -d /library/ka-lite ]; then | ||
echo -e "\n\nKA LITE REQUIRES 2 THINGS...\n" | ||
|
||
|
@@ -319,15 +421,15 @@ fi | |
# 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 | ||
# L. Start BitTorrent downloads, e.g. if /etc/iiab/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! | ||
# M. Educate Implementers prior to rebooting! | ||
echo -e "\n\n ┌───────────────────────────────────────────────────────────┐" | ||
echo -e " │ │" | ||
echo -e " │ INTERNET-IN-A-BOX (IIAB) SOFTWARE INSTALL IS COMPLETE │" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters