mirror of
https://github.com/RaspAP/raspap-webgui.git
synced 2024-11-22 15:40:22 +00:00
Tidy install loader, usage notes readability + examples
This commit is contained in:
parent
4e00b81940
commit
d7f5ee36e8
2 changed files with 124 additions and 106 deletions
|
@ -2,8 +2,10 @@
|
||||||
#
|
#
|
||||||
# RaspAP installation functions
|
# RaspAP installation functions
|
||||||
# Author: @billz <billzimmerman@gmail.com>
|
# Author: @billz <billzimmerman@gmail.com>
|
||||||
|
# Author URI: https://github.com/billz/
|
||||||
# License: GNU General Public License v3.0
|
# License: GNU General Public License v3.0
|
||||||
#
|
# License URI: https://github.com/billz/raspap-webgui/blob/master/LICENSE
|
||||||
|
|
||||||
# You are not obligated to bundle the LICENSE file with your RaspAP projects as long
|
# 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.
|
# as you leave these references intact in the header comments of your source files.
|
||||||
|
|
||||||
|
@ -27,6 +29,27 @@ webroot_dir="/var/www/html"
|
||||||
git_source_url="https://github.com/$repo" # $repo from install.raspap.com
|
git_source_url="https://github.com/$repo" # $repo from install.raspap.com
|
||||||
|
|
||||||
# NOTE: all the below functions are overloadable for system-specific installs
|
# NOTE: all the below functions are overloadable for system-specific installs
|
||||||
|
function _install_raspap() {
|
||||||
|
_display_welcome
|
||||||
|
_config_installation
|
||||||
|
_update_system_packages
|
||||||
|
_install_dependencies
|
||||||
|
_enable_php_lighttpd
|
||||||
|
_create_raspap_directories
|
||||||
|
_optimize_php
|
||||||
|
_check_for_old_configs
|
||||||
|
_download_latest_files
|
||||||
|
_change_file_ownership
|
||||||
|
_create_hostapd_scripts
|
||||||
|
_create_lighttpd_scripts
|
||||||
|
_move_config_file
|
||||||
|
_default_configuration
|
||||||
|
_configure_networking
|
||||||
|
_prompt_install_adblock
|
||||||
|
_prompt_install_openvpn
|
||||||
|
_patch_system_files
|
||||||
|
_install_complete
|
||||||
|
}
|
||||||
|
|
||||||
# Prompts user to set installation options
|
# Prompts user to set installation options
|
||||||
function _config_installation() {
|
function _config_installation() {
|
||||||
|
@ -550,24 +573,3 @@ function _install_complete() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function _install_raspap() {
|
|
||||||
_display_welcome
|
|
||||||
_config_installation
|
|
||||||
_update_system_packages
|
|
||||||
_install_dependencies
|
|
||||||
_enable_php_lighttpd
|
|
||||||
_create_raspap_directories
|
|
||||||
_optimize_php
|
|
||||||
_check_for_old_configs
|
|
||||||
_download_latest_files
|
|
||||||
_change_file_ownership
|
|
||||||
_create_hostapd_scripts
|
|
||||||
_create_lighttpd_scripts
|
|
||||||
_move_config_file
|
|
||||||
_default_configuration
|
|
||||||
_configure_networking
|
|
||||||
_prompt_install_adblock
|
|
||||||
_prompt_install_openvpn
|
|
||||||
_patch_system_files
|
|
||||||
_install_complete
|
|
||||||
}
|
|
||||||
|
|
|
@ -2,29 +2,24 @@
|
||||||
#
|
#
|
||||||
# RaspAP Quick Installer
|
# RaspAP Quick Installer
|
||||||
# Author: @billz <billzimmerman@gmail.com>
|
# Author: @billz <billzimmerman@gmail.com>
|
||||||
|
# Author URI: https://github.com/billz/
|
||||||
# License: GNU General Public License v3.0
|
# License: GNU General Public License v3.0
|
||||||
|
# License URI: https://github.com/billz/raspap-webgui/blob/master/LICENSE
|
||||||
|
#
|
||||||
|
# Usage: raspbian.sh options
|
||||||
#
|
#
|
||||||
# Installs an instance of RaspAP.
|
# Installs an instance of RaspAP.
|
||||||
#
|
#
|
||||||
# Available options:
|
# OPTIONS:
|
||||||
# -y, --yes, --assume-yes
|
# -y, --yes, --assume-yes Assume "yes" as answer to all prompts and run non-interactively
|
||||||
# Assume "yes" as answer to all prompts and run non-interactively
|
# -c, --cert, --certficate Installs mkcert and generates an SSL certificate for lighttpd
|
||||||
# -c, --cert, --certficate
|
# -o, --openvpn <flag> Used with -y, --yes, sets OpenVPN install option (0=no install)
|
||||||
# Installs mkcert and generates an SSL certificate for lighttpd
|
# -a, --adblock <flag> Used with -y, --yes, sets Adblock install option (0=no install)
|
||||||
# -o, --openvpn <flag>
|
# -r, --repo, --repository <name> Overrides the default GitHub repo (billz/raspap-webgui)
|
||||||
# Used with -y, --yes, sets OpenVPN install option (0=no install)
|
# -b, --branch <name> Overrides the default git branch (master)
|
||||||
# -a, --adblock <flag>
|
# -h, --help Outputs usage notes and exits
|
||||||
# Used with -y, --yes, sets Adblock install option (0=no install)
|
# -u, --upgrade Upgrades an existing installation to the latest release version
|
||||||
# -r, --repo, --repository <name>
|
# -v, --version Outputs release info and exits
|
||||||
# Overrides the default GitHub repo (billz/raspap-webgui)
|
|
||||||
# -b, --branch <name>
|
|
||||||
# Overrides the default git branch (master)
|
|
||||||
# -h, --help
|
|
||||||
# Outputs usage notes and exits
|
|
||||||
# -u, --upgrade
|
|
||||||
# Upgrades an existing installation to the latest release version
|
|
||||||
# -v, --version
|
|
||||||
# Outputs release info and exits
|
|
||||||
#
|
#
|
||||||
# Depending on options passed to the installer, ONE of the following
|
# Depending on options passed to the installer, ONE of the following
|
||||||
# additional shell scripts will be downloaded and sourced:
|
# additional shell scripts will be downloaded and sourced:
|
||||||
|
@ -36,54 +31,16 @@
|
||||||
# You are not obligated to bundle the LICENSE file with your RaspAP projects as long
|
# 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.
|
# as you leave these references intact in the header comments of your source files.
|
||||||
|
|
||||||
# Fetch latest release from GitHub API
|
set -eo pipefail
|
||||||
repo="billz/raspap-webgui" #override with -r, --repo option
|
|
||||||
readonly RASPAP_LATEST=$(curl -s "https://api.github.com/repos/$repo/releases/latest" | grep -Po '"tag_name": "\K.*?(?=")' )
|
|
||||||
branch="$RASPAP_LATEST" #override with -b, --branch option
|
|
||||||
|
|
||||||
function _setup_colors() {
|
function _main() {
|
||||||
ANSI_RED="\033[0;31m"
|
# set defaults
|
||||||
ANSI_GREEN="\033[0;32m"
|
repo="billz/raspap-webgui" # override with -r, --repo option
|
||||||
ANSI_YELLOW="\033[0;33m"
|
|
||||||
ANSI_RASPBERRY="\033[0;35m"
|
|
||||||
ANSI_ERROR="\033[1;37;41m"
|
|
||||||
ANSI_RESET="\033[m"
|
|
||||||
}
|
|
||||||
|
|
||||||
function _log_output() {
|
_parse_params "$@"
|
||||||
readonly LOGFILE_PATH="/tmp"
|
_setup_colors
|
||||||
exec > >(tee -i $LOGFILE_PATH/raspap_install.log)
|
_log_output
|
||||||
exec 2>&1
|
_load_installer
|
||||||
}
|
|
||||||
|
|
||||||
function _usage() {
|
|
||||||
cat << EOF
|
|
||||||
Usage: $(basename "$0") [OPTION]
|
|
||||||
|
|
||||||
Installs an instance of RaspAP.
|
|
||||||
|
|
||||||
Available 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)
|
|
||||||
-r, --repo, --repository <name>
|
|
||||||
Overrides the default GitHub repo (billz/raspap-webgui)
|
|
||||||
-b, --branch <name>
|
|
||||||
Overrides the default git branch (latest release)
|
|
||||||
-h, --help
|
|
||||||
Outputs usage notes and exits
|
|
||||||
-u, --upgrade
|
|
||||||
Upgrades an existing installation to the latest release version
|
|
||||||
-v, --version
|
|
||||||
Outputs release info and exits
|
|
||||||
|
|
||||||
EOF
|
|
||||||
exit
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function _parse_params() {
|
function _parse_params() {
|
||||||
|
@ -94,7 +51,7 @@ function _parse_params() {
|
||||||
adblock_option=1
|
adblock_option=1
|
||||||
|
|
||||||
while :; do
|
while :; do
|
||||||
case ${1} in
|
case "${1-}" in
|
||||||
-y|--yes|--assume-yes)
|
-y|--yes|--assume-yes)
|
||||||
assume_yes=1
|
assume_yes=1
|
||||||
apt_option="-y"
|
apt_option="-y"
|
||||||
|
@ -140,16 +97,57 @@ function _parse_params() {
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
function _version() {
|
function _setup_colors() {
|
||||||
echo -e "RaspAP v${RASPAP_LATEST} - Simple AP setup & WiFi management for Debian-based devices"
|
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)
|
||||||
|
-r, --repo, --repository <name> Overrides the default GitHub repo (billz/raspap-webgui)
|
||||||
|
-b, --branch <name> Overrides the default git branch (latest release)
|
||||||
|
-u, --upgrade Upgrades an existing installation to the latest release version
|
||||||
|
-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
|
||||||
|
|
||||||
|
EOF
|
||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
|
|
||||||
_parse_params "$@"
|
function _version() {
|
||||||
_setup_colors
|
_get_release
|
||||||
_log_output
|
echo -e "RaspAP v${RASPAP_LATEST} - Simple AP setup & WiFi management for Debian-based devices"
|
||||||
|
exit
|
||||||
UPDATE_URL="https://raw.githubusercontent.com/$repo/$branch/"
|
}
|
||||||
|
|
||||||
# Outputs a welcome message
|
# Outputs a welcome message
|
||||||
function _display_welcome() {
|
function _display_welcome() {
|
||||||
|
@ -166,6 +164,11 @@ function _display_welcome() {
|
||||||
echo -e "The Quick Installer will guide you through a few easy steps${ANSI_RESET}\n\n"
|
echo -e "The Quick Installer will guide you through a few easy steps${ANSI_RESET}\n\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Fetch latest release from GitHub API
|
||||||
|
function _get_release() {
|
||||||
|
readonly RASPAP_LATEST=$(curl -s "https://api.github.com/repos/$repo/releases/latest" | grep -Po '"tag_name": "\K.*?(?=")' )
|
||||||
|
}
|
||||||
|
|
||||||
# Outputs a RaspAP Install log line
|
# Outputs a RaspAP Install log line
|
||||||
function _install_log() {
|
function _install_log() {
|
||||||
echo -e "${ANSI_GREEN}RaspAP Install: $1${ANSI_RESET}"
|
echo -e "${ANSI_GREEN}RaspAP Install: $1${ANSI_RESET}"
|
||||||
|
@ -197,15 +200,28 @@ function _update_system_packages() {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Fetch required installer functions
|
# Fetch required installer functions
|
||||||
if [ "${install_cert:-}" = 1 ]; then
|
function _load_installer() {
|
||||||
source="mkcert"
|
# fetch latest release tag
|
||||||
wget -q ${UPDATE_URL}installers/${source}.sh -O /tmp/raspap_${source}.sh
|
_get_release
|
||||||
source /tmp/raspap_${source}.sh && rm -f /tmp/raspap_${source}.sh
|
|
||||||
_install_certificate || _install_status 1 "Unable to install certificate"
|
# assign default branch if not defined with -b, --branch option
|
||||||
else
|
if [ -z ${branch} ]; then
|
||||||
source="common"
|
branch=$RASPAP_LATEST
|
||||||
wget -q ${UPDATE_URL}installers/${source}.sh -O /tmp/raspap_${source}.sh
|
fi
|
||||||
source /tmp/raspap_${source}.sh && rm -f /tmp/raspap_${source}.sh
|
|
||||||
_install_raspap || _install_status 1 "Unable to install RaspAP"
|
UPDATE_URL="https://raw.githubusercontent.com/$repo/$branch/"
|
||||||
fi
|
if [ "${install_cert:-}" = 1 ]; then
|
||||||
|
source="mkcert"
|
||||||
|
wget -q ${UPDATE_URL}installers/${source}.sh -O /tmp/raspap_${source}.sh
|
||||||
|
source /tmp/raspap_${source}.sh && rm -f /tmp/raspap_${source}.sh
|
||||||
|
_install_certificate || _install_status 1 "Unable to install certificate"
|
||||||
|
else
|
||||||
|
source="common"
|
||||||
|
wget -q ${UPDATE_URL}installers/${source}.sh -O /tmp/raspap_${source}.sh
|
||||||
|
source /tmp/raspap_${source}.sh && rm -f /tmp/raspap_${source}.sh
|
||||||
|
_install_raspap || _install_status 1 "Unable to install RaspAP"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
_main "$@"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue