#!/bin/bash
# Copied from: https://github.com/iiab/iiab-factory/blob/master/install.txt

# To install Internet-in-a-Box (IIAB) 7.2 onto Raspberry Pi OS, Ubuntu 20.04+,
# Linux Mint 20 or Debian 11+, 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/computers/getting-started.html
#    To attempt IIAB 7.2 on another Linux see the manual/legacy 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 WiFi (and faster!)  WARNING: IF YOU CONNECT YOUR IIAB'S
#    INTERNAL WIFI TO THE INTERNET OVER 5 GHz, YOU'LL PREVENT OLDER LAPTOPS/
#    PHONES/TABLETS (WHICH REQUIRE 2.4 GHz) FROM CONNECTING TO YOUR IIAB'S
#    INTERNAL HOTSPOT.  See: "wifi_up_down: True" in /etc/iiab/local_vars.yml

# 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. Within about 1-2 hours, 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
#
# 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 Dev Team
# http://FAQ.IIAB.IO

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 2> /dev/null || true    # Overrides 'set -e'
curl http://d.iiab.io/7.2/iiab > /usr/sbin/iiab
#curl https://raw.githubusercontent.com/iiab/iiab-factory/master/iiab > /usr/sbin/iiab
chmod 0744 /usr/sbin/iiab

# Run install script!
/usr/sbin/iiab "$@" # Pass on all CLI params (PR #s) for easy community
# testing.  Example: curl d.iiab.io/install.txt | sudo bash -s 361 2604 2607
# As explained in /usr/sbin/iiab Section "J. Install optional PR's"