2019-10-07 00:59:21 +02:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# RaspAP Quick Installer
|
2020-03-23 10:31:18 +01:00
|
|
|
# Author: @billz <billzimmerman@gmail.com>
|
2020-12-16 11:01:11 +01:00
|
|
|
# Author URI: https://github.com/billz/
|
2020-03-23 10:31:18 +01:00
|
|
|
# License: GNU General Public License v3.0
|
2021-02-03 10:07:15 +01:00
|
|
|
# License URI: https://github.com/raspap/raspap-webgui/blob/master/LICENSE
|
2020-12-16 11:01:11 +01:00
|
|
|
#
|
|
|
|
# Usage: raspbian.sh options
|
2019-10-07 00:59:21 +02:00
|
|
|
#
|
2020-12-15 16:04:55 +01:00
|
|
|
# Installs an instance of RaspAP.
|
2019-12-09 13:07:57 +01:00
|
|
|
#
|
2020-12-16 11:01:11 +01:00
|
|
|
# OPTIONS:
|
|
|
|
# -y, --yes, --assume-yes Assume "yes" as answer to all prompts and run non-interactively
|
|
|
|
# -c, --cert, --certficate Installs mkcert and generates an SSL certificate for lighttpd
|
|
|
|
# -o, --openvpn <flag> Used with -y, --yes, sets OpenVPN install option (0=no install)
|
|
|
|
# -a, --adblock <flag> Used with -y, --yes, sets Adblock install option (0=no install)
|
2021-03-14 20:27:13 +01:00
|
|
|
# -r, --repo, --repository <name> Overrides the default GitHub repo (RaspAP/raspap-webgui)
|
2020-12-16 11:01:11 +01:00
|
|
|
# -b, --branch <name> Overrides the default git branch (master)
|
2021-03-14 20:27:13 +01:00
|
|
|
# -t, --token <accesstoken> Specify a GitHub token to access a private repository
|
2020-12-16 11:01:11 +01:00
|
|
|
# -u, --upgrade Upgrades an existing installation to the latest release version
|
2021-03-14 20:27:13 +01:00
|
|
|
# -i, --insiders Installs from the Insiders Edition (RaspAP/raspap-insiders)
|
2020-12-16 11:01:11 +01:00
|
|
|
# -v, --version Outputs release info and exits
|
2021-02-22 17:08:24 +01:00
|
|
|
# -h, --help Outputs usage notes and exits
|
2020-01-15 18:47:09 +01:00
|
|
|
#
|
|
|
|
# Depending on options passed to the installer, ONE of the following
|
|
|
|
# additional shell scripts will be downloaded and sourced:
|
|
|
|
#
|
2021-02-03 10:07:15 +01:00
|
|
|
# https://raw.githubusercontent.com/raspap/raspap-webgui/master/installers/common.sh
|
2020-01-15 18:47:09 +01:00
|
|
|
# - or -
|
2021-02-03 10:07:15 +01:00
|
|
|
# https://raw.githubusercontent.com/raspap/raspap-webgui/master/installers/mkcert.sh
|
2020-03-23 10:31:18 +01:00
|
|
|
#
|
|
|
|
# You are not obligated to bundle the LICENSE file with your RaspAP projects as long
|
|
|
|
# as you leave these references intact in the header comments of your source files.
|
2019-10-07 00:59:21 +02:00
|
|
|
|
2020-12-16 11:01:11 +01:00
|
|
|
set -eo pipefail
|
2020-12-15 16:04:55 +01:00
|
|
|
|
2020-12-16 11:01:11 +01:00
|
|
|
function _main() {
|
|
|
|
# set defaults
|
2021-03-09 10:51:15 +01:00
|
|
|
repo="RaspAP/raspap-webgui" # override with -r, --repo option
|
2020-12-16 11:01:11 +01:00
|
|
|
_parse_params "$@"
|
|
|
|
_setup_colors
|
|
|
|
_log_output
|
|
|
|
_load_installer
|
2020-12-15 16:04:55 +01:00
|
|
|
}
|
2019-11-07 09:44:13 +01:00
|
|
|
|
2020-12-15 16:04:55 +01:00
|
|
|
function _parse_params() {
|
2021-03-14 20:27:13 +01:00
|
|
|
# default option values
|
2020-12-15 16:04:55 +01:00
|
|
|
assume_yes=0
|
|
|
|
upgrade=0
|
|
|
|
ovpn_option=1
|
|
|
|
adblock_option=1
|
2021-03-09 10:51:15 +01:00
|
|
|
insiders=0
|
|
|
|
acctoken=""
|
2020-12-15 16:04:55 +01:00
|
|
|
|
|
|
|
while :; do
|
2020-12-16 11:01:11 +01:00
|
|
|
case "${1-}" in
|
2020-12-15 16:04:55 +01:00
|
|
|
-y|--yes|--assume-yes)
|
|
|
|
assume_yes=1
|
|
|
|
apt_option="-y"
|
|
|
|
;;
|
|
|
|
-o|--openvpn)
|
|
|
|
ovpn_option="$2"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-a|--adblock)
|
|
|
|
adblock_option="$2"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-c|--cert|--certificate)
|
|
|
|
install_cert=1
|
|
|
|
;;
|
|
|
|
-r|--repo|--repository)
|
|
|
|
repo="$2"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-b|--branch)
|
|
|
|
branch="$2"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-h|--help)
|
|
|
|
_usage
|
|
|
|
;;
|
|
|
|
-u|--upgrade)
|
|
|
|
upgrade=1
|
|
|
|
;;
|
2021-02-22 17:08:24 +01:00
|
|
|
-i|--insiders)
|
2021-03-09 10:51:15 +01:00
|
|
|
insiders=1
|
|
|
|
;;
|
|
|
|
-t|--token)
|
|
|
|
acctoken="$2"
|
2021-03-14 20:27:13 +01:00
|
|
|
shift
|
2021-02-22 17:08:24 +01:00
|
|
|
;;
|
2020-12-15 16:04:55 +01:00
|
|
|
-v|--version)
|
|
|
|
_version
|
|
|
|
;;
|
|
|
|
-*|--*)
|
|
|
|
echo "Unknown option: $1"
|
|
|
|
_usage
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
esac
|
2019-11-22 15:03:50 +01:00
|
|
|
shift
|
2020-12-15 16:04:55 +01:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2020-12-16 11:01:11 +01:00
|
|
|
function _setup_colors() {
|
|
|
|
ANSI_RED="\033[0;31m"
|
|
|
|
ANSI_GREEN="\033[0;32m"
|
|
|
|
ANSI_YELLOW="\033[0;33m"
|
|
|
|
ANSI_RASPBERRY="\033[0;35m"
|
|
|
|
ANSI_ERROR="\033[1;37;41m"
|
|
|
|
ANSI_RESET="\033[m"
|
|
|
|
}
|
|
|
|
|
|
|
|
function _log_output() {
|
|
|
|
readonly LOGFILE_PATH="/tmp"
|
|
|
|
exec > >(tee -i $LOGFILE_PATH/raspap_install.log)
|
|
|
|
exec 2>&1
|
|
|
|
}
|
|
|
|
|
|
|
|
function _usage() {
|
|
|
|
cat << EOF
|
|
|
|
Usage: raspbian.sh options
|
|
|
|
|
|
|
|
Installs an instance of RaspAP.
|
|
|
|
|
|
|
|
OPTIONS:
|
|
|
|
-y, --yes, --assume-yes Assumes "yes" as an answer to all prompts
|
|
|
|
-c, --cert, --certificate Installs an SSL certificate for lighttpd
|
|
|
|
-o, --openvpn <flag> Used with -y, --yes, sets OpenVPN install option (0=no install)
|
|
|
|
-a, --adblock <flag> Used with -y, --yes, sets Adblock install option (0=no install)
|
2021-03-14 20:27:13 +01:00
|
|
|
-r, --repo, --repository <name> Overrides the default GitHub repo (RaspAP/raspap-webgui)
|
2020-12-16 11:01:11 +01:00
|
|
|
-b, --branch <name> Overrides the default git branch (latest release)
|
2021-03-14 20:27:13 +01:00
|
|
|
-t, --token <accesstoken> Specify a GitHub token to access a private repository
|
2020-12-16 11:01:11 +01:00
|
|
|
-u, --upgrade Upgrades an existing installation to the latest release version
|
2021-03-14 20:27:13 +01:00
|
|
|
-i, --insiders Installs from the Insiders Edition (RaspAP/raspap-insiders)
|
2020-12-16 11:01:11 +01:00
|
|
|
-v, --version Outputs release info and exits
|
|
|
|
-h, --help Outputs usage notes and exits
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
Run locally specifying GitHub repo and branch:
|
|
|
|
raspbian.sh --repo foo/bar --branch my/branch
|
|
|
|
|
|
|
|
Run locally requesting release info:
|
|
|
|
raspbian.sh --version
|
|
|
|
|
|
|
|
Invoke installer remotely, run non-interactively with option flags:
|
|
|
|
curl -sL https://install.raspap.com | bash -s -- --yes --openvpn 1 --adblock 0
|
|
|
|
|
2021-02-22 17:08:24 +01:00
|
|
|
Invoke remotely, uprgrade an existing install to the Insiders Edition:
|
|
|
|
curl -sL https://install.raspap.com | bash -s -- --upgrade --insiders
|
|
|
|
|
2020-12-16 11:01:11 +01:00
|
|
|
EOF
|
|
|
|
exit
|
|
|
|
}
|
|
|
|
|
2020-12-15 16:04:55 +01:00
|
|
|
function _version() {
|
2020-12-16 11:01:11 +01:00
|
|
|
_get_release
|
2021-03-09 10:51:15 +01:00
|
|
|
echo -e "RaspAP v${RASPAP_RELEASE} - Simple wireless AP setup & management for Debian-based devices"
|
2020-12-15 16:04:55 +01:00
|
|
|
exit
|
|
|
|
}
|
|
|
|
|
2019-11-07 09:44:13 +01:00
|
|
|
# Outputs a welcome message
|
2020-03-23 10:31:18 +01:00
|
|
|
function _display_welcome() {
|
2020-04-10 11:40:21 +02:00
|
|
|
echo -e "${ANSI_RASPBERRY}\n"
|
2019-11-07 09:44:13 +01:00
|
|
|
echo -e " 888888ba .d888888 888888ba"
|
|
|
|
echo -e " 88 8b d8 88 88 8b"
|
|
|
|
echo -e "a88aaaa8P' .d8888b. .d8888b. 88d888b. 88aaaaa88a a88aaaa8P"
|
|
|
|
echo -e " 88 8b. 88 88 Y8ooooo. 88 88 88 88 88"
|
|
|
|
echo -e " 88 88 88. .88 88 88. .88 88 88 88"
|
|
|
|
echo -e " dP dP 88888P8 88888P 88Y888P 88 88 dP"
|
|
|
|
echo -e " 88"
|
2021-03-14 20:27:13 +01:00
|
|
|
echo -e " dP version ${RASPAP_RELEASE}"
|
2020-04-10 11:40:21 +02:00
|
|
|
echo -e "${ANSI_GREEN}"
|
|
|
|
echo -e "The Quick Installer will guide you through a few easy steps${ANSI_RESET}\n\n"
|
2019-11-07 09:44:13 +01:00
|
|
|
}
|
|
|
|
|
2021-03-09 11:58:15 +01:00
|
|
|
# Fetch latest release from GitHub or RaspAP Installer API
|
2020-12-16 11:01:11 +01:00
|
|
|
function _get_release() {
|
2021-03-09 10:51:15 +01:00
|
|
|
readonly RASPAP_LATEST=$(curl -s "https://api.github.com/repos/$repo/releases/latest" | grep -Po '"tag_name": "\K.*?(?=")' )
|
|
|
|
if [ "$insiders" == 1 ]; then
|
2021-03-14 20:27:13 +01:00
|
|
|
readonly RASPAP_INSIDERS_LATEST=$(curl -s "https://install.raspap.com/repos/RaspAP/raspap-insiders/releases/latest/" | grep -Po '"tag_name": "\K.*?(?=")' )
|
|
|
|
readonly RASPAP_RELEASE="${RASPAP_INSIDERS_LATEST} Insiders"
|
2021-02-22 17:08:24 +01:00
|
|
|
else
|
2021-03-14 20:27:13 +01:00
|
|
|
readonly RASPAP_RELEASE="${RASPAP_LATEST}"
|
2021-02-22 17:08:24 +01:00
|
|
|
fi
|
2020-12-16 11:01:11 +01:00
|
|
|
}
|
|
|
|
|
2019-11-07 09:44:13 +01:00
|
|
|
# Outputs a RaspAP Install log line
|
2020-03-23 10:31:18 +01:00
|
|
|
function _install_log() {
|
2020-04-10 11:40:21 +02:00
|
|
|
echo -e "${ANSI_GREEN}RaspAP Install: $1${ANSI_RESET}"
|
2019-11-07 09:44:13 +01:00
|
|
|
}
|
|
|
|
|
2020-04-25 23:06:02 +02:00
|
|
|
# Outputs a RaspAP divider
|
|
|
|
function _install_divider() {
|
|
|
|
echo -e "\033[1;32m***************************************************************$*\033[m"
|
|
|
|
}
|
|
|
|
|
2020-04-10 11:40:21 +02:00
|
|
|
# Outputs a RaspAP status indicator
|
|
|
|
function _install_status() {
|
|
|
|
case $1 in
|
|
|
|
0)
|
|
|
|
echo -e "[$ANSI_GREEN \U2713 ok $ANSI_RESET] $2"
|
|
|
|
;;
|
|
|
|
1)
|
|
|
|
echo -e "[$ANSI_RED \U2718 error $ANSI_RESET] $ANSI_ERROR $2 $ANSI_RESET"
|
|
|
|
;;
|
|
|
|
2)
|
|
|
|
echo -e "[$ANSI_YELLOW \U26A0 warning $ANSI_RESET] $2"
|
|
|
|
;;
|
|
|
|
esac
|
2019-11-07 11:41:56 +01:00
|
|
|
}
|
|
|
|
|
2020-03-23 10:31:18 +01:00
|
|
|
function _update_system_packages() {
|
|
|
|
_install_log "Updating sources"
|
2020-12-15 16:04:55 +01:00
|
|
|
sudo apt-get update || _install_status 1 "Unable to update package list"
|
2016-06-16 12:03:29 +02:00
|
|
|
}
|
|
|
|
|
2019-12-09 13:07:57 +01:00
|
|
|
# Fetch required installer functions
|
2020-12-16 11:01:11 +01:00
|
|
|
function _load_installer() {
|
|
|
|
# fetch latest release tag
|
|
|
|
_get_release
|
|
|
|
|
|
|
|
# assign default branch if not defined with -b, --branch option
|
|
|
|
if [ -z ${branch} ]; then
|
|
|
|
branch=$RASPAP_LATEST
|
|
|
|
fi
|
|
|
|
|
2021-03-14 20:27:13 +01:00
|
|
|
# add optional auth token header if defined with -t, --token option
|
2021-03-09 10:51:15 +01:00
|
|
|
header=()
|
|
|
|
if [[ ! -z "$acctoken" ]]; then
|
|
|
|
header=(--header "Authorization: token $acctoken")
|
|
|
|
fi
|
2021-03-14 20:27:13 +01:00
|
|
|
|
|
|
|
UPDATE_URL="https://raw.githubusercontent.com/$repo/$branch/"
|
2020-12-16 11:01:11 +01:00
|
|
|
if [ "${install_cert:-}" = 1 ]; then
|
|
|
|
source="mkcert"
|
2021-03-09 10:51:15 +01:00
|
|
|
wget "${header[@]}" -q ${UPDATE_URL}installers/${source}.sh -O /tmp/raspap_${source}.sh
|
2020-12-16 11:01:11 +01:00
|
|
|
source /tmp/raspap_${source}.sh && rm -f /tmp/raspap_${source}.sh
|
|
|
|
_install_certificate || _install_status 1 "Unable to install certificate"
|
|
|
|
else
|
|
|
|
source="common"
|
2021-03-14 20:27:13 +01:00
|
|
|
wget "${header[@]}" -q ${UPDATE_URL}installers/${source}.sh -O /tmp/raspap_${source}.sh
|
2020-12-16 11:01:11 +01:00
|
|
|
source /tmp/raspap_${source}.sh && rm -f /tmp/raspap_${source}.sh
|
|
|
|
_install_raspap || _install_status 1 "Unable to install RaspAP"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
_main "$@"
|
2019-11-07 09:44:13 +01:00
|
|
|
|