2019-10-06 22:59:21 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# RaspAP Quick Installer
|
2020-03-23 09:31:18 +00:00
|
|
|
# Author: @billz <billzimmerman@gmail.com>
|
|
|
|
# License: GNU General Public License v3.0
|
2019-10-06 22:59:21 +00:00
|
|
|
#
|
2019-12-09 12:07:57 +00:00
|
|
|
# Usage:
|
|
|
|
#
|
2019-11-07 13:29:42 +00:00
|
|
|
# -y, --yes, --assume-yes
|
2019-12-01 09:45:06 +00:00
|
|
|
# Assume "yes" as answer to all prompts and run non-interactively
|
2019-11-07 20:12:41 +00:00
|
|
|
# c, --cert, --certficate
|
2019-12-01 09:45:06 +00:00
|
|
|
# Installs mkcert and generates an SSL certificate for lighttpd
|
2019-11-22 14:03:50 +00:00
|
|
|
# -o, --openvpn <flag>
|
2019-12-01 09:45:06 +00:00
|
|
|
# Used with -y, --yes, sets OpenVPN install option (0=no install)
|
2020-04-13 07:49:18 +00:00
|
|
|
# -a, --adblock <flag>
|
|
|
|
# Used with -y, --yes, sets Adblock install option (0=no install)
|
2019-12-01 09:45:06 +00:00
|
|
|
# -r, --repo, --repository <name>
|
|
|
|
# Overrides the default GitHub repo (billz/raspap-webgui)
|
2019-11-22 14:03:50 +00:00
|
|
|
# -b, --branch <name>
|
2019-12-01 09:45:06 +00:00
|
|
|
# Overrides the default git branch (master)
|
|
|
|
# -h, --help
|
|
|
|
# Outputs usage notes and exits
|
2020-06-24 22:36:19 +00:00
|
|
|
# -u, --upgrade
|
|
|
|
# Upgrades an existing installation to the latest release version
|
2019-12-01 09:45:06 +00:00
|
|
|
# -v, --version
|
|
|
|
# Outputs release info and exits
|
2020-01-15 17:47:09 +00:00
|
|
|
#
|
|
|
|
# Depending on options passed to the installer, ONE of the following
|
|
|
|
# additional shell scripts will be downloaded and sourced:
|
|
|
|
#
|
2020-03-05 21:47:46 +00:00
|
|
|
# https://raw.githubusercontent.com/billz/raspap-webgui/master/installers/common.sh
|
2020-01-15 17:47:09 +00:00
|
|
|
# - or -
|
2020-03-05 21:47:46 +00:00
|
|
|
# https://raw.githubusercontent.com/billz/raspap-webgui/master/installers/mkcert.sh
|
2020-03-23 09:31:18 +00: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-06 22:59:21 +00:00
|
|
|
|
2019-12-09 12:07:57 +00:00
|
|
|
# Set defaults
|
2019-11-11 08:51:45 +00:00
|
|
|
repo="billz/raspap-webgui"
|
|
|
|
branch="master"
|
2019-12-01 09:45:06 +00:00
|
|
|
assume_yes=0
|
2020-06-24 22:36:19 +00:00
|
|
|
upgrade=0
|
2019-12-01 09:45:06 +00:00
|
|
|
ovpn_option=1
|
2020-04-13 07:49:18 +00:00
|
|
|
adblock_option=1
|
2020-04-10 09:40:21 +00:00
|
|
|
|
|
|
|
# Define colors
|
|
|
|
readonly ANSI_RED="\033[0;31m"
|
|
|
|
readonly ANSI_GREEN="\033[0;32m"
|
|
|
|
readonly ANSI_YELLOW="\033[0;33m"
|
|
|
|
readonly ANSI_RASPBERRY="\033[0;35m"
|
|
|
|
readonly ANSI_ERROR="\033[1;37;41m"
|
|
|
|
readonly ANSI_RESET="\033[m"
|
|
|
|
|
|
|
|
# Fetch latest release from GitHub API
|
2020-03-23 09:31:18 +00:00
|
|
|
readonly RASPAP_LATEST=$(curl -s "https://api.github.com/repos/$repo/releases/latest" | grep -Po '"tag_name": "\K.*?(?=")' )
|
2019-12-09 12:07:57 +00:00
|
|
|
|
|
|
|
# Define usage notes
|
2019-11-11 19:18:20 +00:00
|
|
|
usage=$(cat << EOF
|
|
|
|
Usage: raspbian.sh [OPTION]\n
|
|
|
|
-y, --yes, --assume-yes\n\tAssumes "yes" as an answer to all prompts
|
2019-11-28 09:45:54 +00:00
|
|
|
-c, --cert, --certificate\n\tInstalls an SSL certificate for lighttpd
|
2019-11-22 14:03:50 +00:00
|
|
|
-o, --openvpn <flag>\n\tUsed with -y, --yes, sets OpenVPN install option (0=no install)
|
2020-04-13 07:49:18 +00:00
|
|
|
-a, --adblock <flag>\n\tUsed with -y, --yes, sets Adblock install option (0=no install)
|
2019-11-22 14:03:50 +00:00
|
|
|
-r, --repo, --repository <name>\n\tOverrides the default GitHub repo (billz/raspap-webgui)
|
2019-11-28 09:45:54 +00:00
|
|
|
-b, --branch <name>\n\tOverrides the default git branch (master)
|
2019-12-01 09:45:06 +00:00
|
|
|
-h, --help\n\tOutputs usage notes and exits
|
2020-06-24 22:36:19 +00:00
|
|
|
-u, --upgrade\n\tUpgrades an existing installation to the latest release version
|
2019-12-01 09:45:06 +00:00
|
|
|
-v, --version\n\tOutputs release info and exits\n
|
2019-11-11 19:18:20 +00:00
|
|
|
EOF
|
|
|
|
)
|
2019-11-07 08:44:13 +00:00
|
|
|
|
2019-12-09 12:07:57 +00:00
|
|
|
# Parse command-line options
|
2019-11-07 08:44:13 +00:00
|
|
|
while :; do
|
|
|
|
case $1 in
|
2019-11-07 13:29:42 +00:00
|
|
|
-y|--yes|--assume-yes)
|
|
|
|
assume_yes=1
|
|
|
|
apt_option="-y"
|
|
|
|
;;
|
2019-11-22 14:03:50 +00:00
|
|
|
-o|--openvpn)
|
|
|
|
ovpn_option="$2"
|
|
|
|
shift
|
|
|
|
;;
|
2020-03-31 21:54:46 +00:00
|
|
|
-a|--adblock)
|
2020-04-13 07:49:18 +00:00
|
|
|
adblock_option="$2"
|
|
|
|
shift
|
2020-03-31 21:54:46 +00:00
|
|
|
;;
|
2019-11-07 20:12:41 +00:00
|
|
|
-c|--cert|--certificate)
|
2019-11-07 13:29:42 +00:00
|
|
|
install_cert=1
|
|
|
|
;;
|
2019-11-11 08:51:45 +00:00
|
|
|
-r|--repo|--repository)
|
|
|
|
repo="$2"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-b|--branch)
|
|
|
|
branch="$2"
|
2019-11-22 14:03:50 +00:00
|
|
|
shift
|
2019-11-11 08:51:45 +00:00
|
|
|
;;
|
2019-11-11 19:24:01 +00:00
|
|
|
-h|--help)
|
|
|
|
printf "$usage"
|
|
|
|
exit 1
|
|
|
|
;;
|
2020-06-24 22:36:19 +00:00
|
|
|
-u|--upgrade)
|
|
|
|
upgrade=1
|
|
|
|
;;
|
2019-12-01 09:45:06 +00:00
|
|
|
-v|--version)
|
2020-04-10 09:40:21 +00:00
|
|
|
printf "RaspAP v${RASPAP_LATEST} - Simple AP setup & WiFi management for Debian-based devices\n"
|
2019-12-01 09:45:06 +00:00
|
|
|
exit 1
|
2020-04-10 09:40:21 +00:00
|
|
|
;;
|
2019-11-07 13:29:42 +00:00
|
|
|
-*|--*)
|
2019-11-11 08:51:45 +00:00
|
|
|
echo "Unknown option: $1"
|
2019-11-11 19:18:20 +00:00
|
|
|
printf "$usage"
|
2019-11-07 13:29:42 +00:00
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
*)
|
2019-11-07 08:44:13 +00:00
|
|
|
break
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
2019-09-30 17:58:12 +00:00
|
|
|
done
|
|
|
|
|
2019-11-11 08:51:45 +00:00
|
|
|
UPDATE_URL="https://raw.githubusercontent.com/$repo/$branch/"
|
|
|
|
|
2019-11-07 08:44:13 +00:00
|
|
|
# Outputs a welcome message
|
2020-03-23 09:31:18 +00:00
|
|
|
function _display_welcome() {
|
2020-04-10 09:40:21 +00:00
|
|
|
echo -e "${ANSI_RASPBERRY}\n"
|
2019-11-07 08:44:13 +00: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"
|
2020-03-20 11:06:36 +00:00
|
|
|
echo -e " dP version ${RASPAP_LATEST}"
|
2020-04-10 09:40:21 +00: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 08:44:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Outputs a RaspAP Install log line
|
2020-03-23 09:31:18 +00:00
|
|
|
function _install_log() {
|
2020-04-10 09:40:21 +00:00
|
|
|
echo -e "${ANSI_GREEN}RaspAP Install: $1${ANSI_RESET}"
|
2019-11-07 08:44:13 +00:00
|
|
|
}
|
|
|
|
|
2020-04-25 21:06:02 +00:00
|
|
|
# Outputs a RaspAP divider
|
|
|
|
function _install_divider() {
|
|
|
|
echo -e "\033[1;32m***************************************************************$*\033[m"
|
|
|
|
}
|
|
|
|
|
2020-04-10 09:40:21 +00: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 10:41:56 +00:00
|
|
|
}
|
|
|
|
|
2020-03-23 09:31:18 +00:00
|
|
|
function _update_system_packages() {
|
|
|
|
_install_log "Updating sources"
|
|
|
|
sudo apt-get update || _install_error "Unable to update package list"
|
2016-06-16 10:03:29 +00:00
|
|
|
}
|
|
|
|
|
2019-12-09 12:07:57 +00:00
|
|
|
# Fetch required installer functions
|
2019-11-07 08:44:13 +00:00
|
|
|
if [ "${install_cert:-}" = 1 ]; then
|
|
|
|
source="mkcert"
|
2019-11-07 20:12:41 +00:00
|
|
|
wget -q ${UPDATE_URL}installers/${source}.sh -O /tmp/raspap_${source}.sh
|
2019-11-07 13:48:30 +00:00
|
|
|
source /tmp/raspap_${source}.sh && rm -f /tmp/raspap_${source}.sh
|
2020-04-19 11:35:29 +00:00
|
|
|
_install_certificate || _install_status 1 "Unable to install certificate"
|
2019-11-07 08:44:13 +00:00
|
|
|
else
|
|
|
|
source="common"
|
2019-11-07 20:12:41 +00:00
|
|
|
wget -q ${UPDATE_URL}installers/${source}.sh -O /tmp/raspap_${source}.sh
|
2019-11-07 13:48:30 +00:00
|
|
|
source /tmp/raspap_${source}.sh && rm -f /tmp/raspap_${source}.sh
|
2020-04-19 11:35:29 +00:00
|
|
|
_install_raspap || _install_status 1 "Unable to install RaspAP"
|
2019-11-07 08:44:13 +00:00
|
|
|
fi
|
|
|
|
|