Merge pull request #1457 from RaspAP/feat/update-install

Improves installer with --update switch & GitHub user/token auth
This commit is contained in:
Bill Zimmerman 2023-11-17 12:11:56 +01:00 committed by GitHub
commit 366e0447ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 175 additions and 142 deletions

View file

@ -57,35 +57,34 @@ function _install_raspap() {
_configure_networking _configure_networking
_prompt_install_adblock _prompt_install_adblock
_prompt_install_openvpn _prompt_install_openvpn
_install_mobile_clients _install_extra_features
_prompt_install_wireguard _prompt_install_wireguard
_prompt_install_vpn_providers _prompt_install_vpn_providers
_patch_system_files _patch_system_files
_install_complete _install_complete
} }
# search for optional installation files names install_feature_*.sh # Performs a minimal update of an existing installation to the latest release version.
function _install_mobile_clients() { # The user is not prompted to install new RaspAP components.
if [ "$insiders" == 1 ]; then # The -y, --yes and -p, --path switches may be used for an unattended update.
_install_log "Installing support for mobile data clients" function _update_raspap() {
for feature in $(ls $webroot_dir/installers/install_feature_*.sh) ; do _display_welcome
source $feature _config_installation
f=$(basename $feature) _update_system_packages
func="_${f%.*}" _install_dependencies
if declare -f -F $func > /dev/null; then _check_for_old_configs
echo "Installing $func" _download_latest_files
$func || _install_status 1 "Unable to install feature ($func)" _change_file_ownership
else _patch_system_files
_install_status 1 "Install file $f is missing install function $func" _install_complete
fi
done
fi
} }
# Prompts user to set installation options # Prompts user to set installation options
function _config_installation() { function _config_installation() {
if [ "$upgrade" == 1 ]; then if [ "$upgrade" == 1 ]; then
opt=(Upgrade Upgrading upgrade) opt=(Upgrade Upgrading upgrade)
elif [ "$update" == 1 ]; then
opt=(Update Updating update)
else else
opt=(Install Installing installation) opt=(Install Installing installation)
fi fi
@ -94,6 +93,10 @@ function _config_installation() {
echo "Detected OS: ${DESC} ${LONG_BIT}-bit" echo "Detected OS: ${DESC} ${LONG_BIT}-bit"
echo "Using GitHub repository: ${repo} ${branch} branch" echo "Using GitHub repository: ${repo} ${branch} branch"
echo "Configuration directory: ${raspap_dir}" echo "Configuration directory: ${raspap_dir}"
if [ -n "$path" ]; then
echo "Setting install path to ${path}"
webroot_dir=$path
fi
echo -n "lighttpd root: ${webroot_dir}? [Y/n]: " echo -n "lighttpd root: ${webroot_dir}? [Y/n]: "
if [ "$assume_yes" == 0 ]; then if [ "$assume_yes" == 0 ]; then
read answer < /dev/tty read answer < /dev/tty
@ -104,8 +107,8 @@ function _config_installation() {
echo -e echo -e
fi fi
echo "${opt[1]} lighttpd directory: ${webroot_dir}" echo "${opt[1]} lighttpd directory: ${webroot_dir}"
if [ "$upgrade" == 1 ]; then if [ "$upgrade" == 1 ] || [ "$update" == 1 ]; then
echo "This will upgrade your existing install to version ${RASPAP_RELEASE}" echo "This will ${opt[2]} your existing install to version ${RASPAP_RELEASE}"
echo "Your configuration will NOT be changed" echo "Your configuration will NOT be changed"
fi fi
echo -n "Complete ${opt[2]} with these values? [Y/n]: " echo -n "Complete ${opt[2]} with these values? [Y/n]: "
@ -255,13 +258,6 @@ function _enable_php_lighttpd() {
# Verifies existence and permissions of RaspAP directory # Verifies existence and permissions of RaspAP directory
function _create_raspap_directories() { function _create_raspap_directories() {
if [ "$upgrade" == 1 ]; then
if [ -f $raspap_dir/raspap.auth ]; then
_install_log "Moving existing raspap.auth file to /tmp"
sudo mv $raspap_dir/raspap.auth /tmp || _install_status 1 "Unable to backup raspap.auth to /tmp"
fi
fi
_install_log "Creating RaspAP directories" _install_log "Creating RaspAP directories"
if [ -d "$raspap_dir" ]; then if [ -d "$raspap_dir" ]; then
sudo mv $raspap_dir "$raspap_dir.`date +%F-%R`" || _install_status 1 "Unable to move old '$raspap_dir' out of the way" sudo mv $raspap_dir "$raspap_dir.`date +%F-%R`" || _install_status 1 "Unable to move old '$raspap_dir' out of the way"
@ -274,9 +270,6 @@ function _create_raspap_directories() {
# Create a directory to store networking configs # Create a directory to store networking configs
echo "Creating $raspap_dir/networking" echo "Creating $raspap_dir/networking"
sudo mkdir -p "$raspap_dir/networking" sudo mkdir -p "$raspap_dir/networking"
# Copy existing dhcpcd.conf to use as base config
echo "Adding /etc/dhcpcd.conf as base configuration"
cat /etc/dhcpcd.conf | sudo tee -a /etc/raspap/networking/defaults > /dev/null
echo "Changing file ownership of $raspap_dir" echo "Changing file ownership of $raspap_dir"
sudo chown -R $raspap_user:$raspap_user "$raspap_dir" || _install_status 1 "Unable to change file ownership for '$raspap_dir'" sudo chown -R $raspap_user:$raspap_user "$raspap_dir" || _install_status 1 "Unable to change file ownership for '$raspap_dir'"
} }
@ -552,29 +545,35 @@ function _create_openvpn_scripts() {
# Fetches latest files from github to webroot # Fetches latest files from github to webroot
function _download_latest_files() { function _download_latest_files() {
if [ ! -d "$webroot_dir" ]; then if [ -d "$webroot_dir" ] && [ "$update" == 0 ]; then
sudo mkdir -p $webroot_dir || _install_status 1 "Unable to create new webroot directory"
fi
if [ -d "$webroot_dir" ]; then
sudo mv $webroot_dir "$webroot_dir.`date +%F-%R`" || _install_status 1 "Unable to remove old webroot directory" sudo mv $webroot_dir "$webroot_dir.`date +%F-%R`" || _install_status 1 "Unable to remove old webroot directory"
elif [ "$upgrade" == 1 ] || [ "$update" == 1 ]; then
sudo rm -rf "$webroot_dir"
fi fi
_install_log "Cloning latest files from github" _install_log "Cloning latest files from GitHub"
if [ "$repo" == "RaspAP/raspap-insiders" ]; then if [ "$repo" == "RaspAP/raspap-insiders" ]; then
_install_status 3 if [ -n "$username" ] && [ -n "$acctoken" ]; then
echo "Insiders please read this: https://docs.raspap.com/insiders/#authentication" insiders_source_url="https://${username}:${acctoken}@github.com/$repo"
git clone --branch $branch --depth 1 -c advice.detachedHead=false $insiders_source_url /tmp/raspap-webgui || clone=false
else
_install_status 3
echo "Insiders please read this: https://docs.raspap.com/insiders/#authentication"
fi
fi
if [ -z "$insiders_source_url" ]; then
git clone --branch $branch --depth 1 -c advice.detachedHead=false $git_source_url /tmp/raspap-webgui || clone=false
fi fi
git clone --branch $branch --depth 1 -c advice.detachedHead=false $git_source_url /tmp/raspap-webgui || clone=false
if [ "$clone" = false ]; then if [ "$clone" = false ]; then
_install_status 1 "Unable to download files from github" _install_status 1 "Unable to download files from github"
echo "The installer cannot continue." >&2 echo "The installer cannot continue." >&2
exit 1 exit 1
fi fi
sudo mv /tmp/raspap-webgui $webroot_dir || _install_status 1 "Unable to move raspap-webgui to web root" _install_log "Installing application to $webroot_dir"
sudo mv /tmp/raspap-webgui $webroot_dir || _install_status 1 "Unable to move raspap-webgui to $webroot_dir"
if [ "$upgrade" == 1 ]; then if [ "$update" == 1 ]; then
_install_log "Applying existing configuration to ${webroot_dir}/includes" _install_log "Applying existing configuration to ${webroot_dir}/includes"
sudo mv /tmp/config.php $webroot_dir/includes || _install_status 1 "Unable to move config.php to ${webroot_dir}/includes" sudo mv /tmp/config.php $webroot_dir/includes || _install_status 1 "Unable to move config.php to ${webroot_dir}/includes"
@ -582,6 +581,11 @@ function _download_latest_files() {
_install_log "Applying existing authentication file to ${raspap_dir}" _install_log "Applying existing authentication file to ${raspap_dir}"
sudo mv /tmp/raspap.auth $raspap_dir || _install_status 1 "Unable to restore authentification credentials file to ${raspap_dir}" sudo mv /tmp/raspap.auth $raspap_dir || _install_status 1 "Unable to restore authentification credentials file to ${raspap_dir}"
fi fi
else
echo "Copying primary RaspAP config to includes/config.php"
if [ ! -f "$webroot_dir/includes/config.php" ]; then
sudo cp "$webroot_dir/config/config.php" "$webroot_dir/includes/config.php"
fi
fi fi
_install_status 0 _install_status 0
@ -599,11 +603,15 @@ function _change_file_ownership() {
# Check for existing configuration files # Check for existing configuration files
function _check_for_old_configs() { function _check_for_old_configs() {
if [ "$upgrade" == 1 ]; then if [ "$update" == 1 ]; then
_install_log "Moving existing configuration to /tmp" _install_log "Moving existing configuration to /tmp"
sudo mv $webroot_dir/includes/config.php /tmp || _install_status 1 "Unable to move config.php to /tmp" sudo mv $webroot_dir/includes/config.php /tmp || _install_status 1 "Unable to move config.php to /tmp"
if [ -f $raspap_dir/raspap.auth ]; then
_install_log "Moving existing raspap.auth file to /tmp"
sudo mv $raspap_dir/raspap.auth /tmp || _install_status 1 "Unable to backup raspap.auth to /tmp"
fi
else else
_install_log "Backing up existing configs to ${raspap_dir}/backups" _install_log "Checking for existing configs"
if [ -f /etc/network/interfaces ]; then if [ -f /etc/network/interfaces ]; then
sudo cp /etc/network/interfaces "$raspap_dir/backups/interfaces.`date +%F-%R`" sudo cp /etc/network/interfaces "$raspap_dir/backups/interfaces.`date +%F-%R`"
sudo ln -sf "$raspap_dir/backups/interfaces.`date +%F-%R`" "$raspap_dir/backups/interfaces" sudo ln -sf "$raspap_dir/backups/interfaces.`date +%F-%R`" "$raspap_dir/backups/interfaces"
@ -645,17 +653,26 @@ function _default_configuration() {
if [ "$upgrade" == 0 ]; then if [ "$upgrade" == 0 ]; then
_install_log "Applying default configuration to installed services" _install_log "Applying default configuration to installed services"
echo "Checking for existence of /etc/dnsmasq.d"
[ -d /etc/dnsmasq.d ] || sudo mkdir /etc/dnsmasq.d
echo "Copying config/hostapd.conf to /etc/hostapd/hostapd.conf"
sudo cp $webroot_dir/config/hostapd.conf /etc/hostapd/hostapd.conf || _install_status 1 "Unable to move hostapd configuration file" sudo cp $webroot_dir/config/hostapd.conf /etc/hostapd/hostapd.conf || _install_status 1 "Unable to move hostapd configuration file"
echo "Copying config/090_raspap.conf to $raspap_default"
sudo cp $webroot_dir/config/090_raspap.conf $raspap_default || _install_status 1 "Unable to move dnsmasq default configuration file" sudo cp $webroot_dir/config/090_raspap.conf $raspap_default || _install_status 1 "Unable to move dnsmasq default configuration file"
echo "Copying config/090_wlan0.conf to $raspap_wlan0"
sudo cp $webroot_dir/config/090_wlan0.conf $raspap_wlan0 || _install_status 1 "Unable to move dnsmasq wlan0 configuration file" sudo cp $webroot_dir/config/090_wlan0.conf $raspap_wlan0 || _install_status 1 "Unable to move dnsmasq wlan0 configuration file"
echo "Copying config/dhcpcd.conf to /etc/dhcpcd.conf"
sudo cp $webroot_dir/config/dhcpcd.conf /etc/dhcpcd.conf || _install_status 1 "Unable to move dhcpcd configuration file" sudo cp $webroot_dir/config/dhcpcd.conf /etc/dhcpcd.conf || _install_status 1 "Unable to move dhcpcd configuration file"
echo "Copying config/defaults.json to $raspap_network"
sudo cp $webroot_dir/config/defaults.json $raspap_network || _install_status 1 "Unable to move defaults.json settings" sudo cp $webroot_dir/config/defaults.json $raspap_network || _install_status 1 "Unable to move defaults.json settings"
echo "Changing file ownership of ${raspap_network}defaults.json" echo "Changing file ownership of ${raspap_network}defaults.json"
sudo chown $raspap_user:$raspap_user "$raspap_network"/defaults.json || _install_status 1 "Unable to change file ownership for defaults.json" sudo chown $raspap_user:$raspap_user "$raspap_network"defaults.json || _install_status 1 "Unable to change file ownership for defaults.json"
echo "Checking for existence of /etc/dnsmasq.d"
[ -d /etc/dnsmasq.d ] || sudo mkdir /etc/dnsmasq.d
# Copy OS-specific bridge default config # Copy OS-specific bridge default config
if [ ${OS,,} = "ubuntu" ] && [[ ${RELEASE} =~ ^(22.04|20.04|19.10|18.04) ]]; then if [ ${OS,,} = "ubuntu" ] && [[ ${RELEASE} =~ ^(22.04|20.04|19.10|18.04) ]]; then
@ -667,11 +684,6 @@ function _default_configuration() {
sudo cp $webroot_dir/config/raspap-br0-member-eth0.network /etc/systemd/network/raspap-br0-member-eth0.network || _install_status 1 "Unable to move br0 member file" sudo cp $webroot_dir/config/raspap-br0-member-eth0.network /etc/systemd/network/raspap-br0-member-eth0.network || _install_status 1 "Unable to move br0 member file"
fi fi
echo "Copying primary RaspAP config to includes/config.php"
if [ ! -f "$webroot_dir/includes/config.php" ]; then
sudo cp "$webroot_dir/config/config.php" "$webroot_dir/includes/config.php"
fi
if [ ${OS,,} = "raspbian" ] && [[ ${RELEASE} =~ ^(12) ]]; then if [ ${OS,,} = "raspbian" ] && [[ ${RELEASE} =~ ^(12) ]]; then
echo "Moving dhcpcd systemd unit control file to /lib/systemd/system/" echo "Moving dhcpcd systemd unit control file to /lib/systemd/system/"
sudo mv $webroot_dir/installers/dhcpcd.service /lib/systemd/system/ || _install_status 1 "Unable to move dhcpcd.service file" sudo mv $webroot_dir/installers/dhcpcd.service /lib/systemd/system/ || _install_status 1 "Unable to move dhcpcd.service file"
@ -679,7 +691,23 @@ function _default_configuration() {
sudo systemctl enable dhcpcd.service || _install_status 1 "Failed to enable raspap.service" sudo systemctl enable dhcpcd.service || _install_status 1 "Failed to enable raspap.service"
fi fi
# Set correct DAEMON_CONF path for hostapd (Ubuntu20 + Armbian22)
if [ ${OS,,} = "ubuntu" ] && [[ ${RELEASE} =~ ^(22.04|20.04|19.10|18.04) ]]; then
conf="/etc/default/hostapd"
key="DAEMON_CONF"
value="/etc/hostapd/hostapd.conf"
echo "Setting default ${key} path to ${value}"
sudo sed -i -E "/^#?$key/ { s/^#//; s%=.*%=\"$value\"%; }" "$conf" || _install_status 1 "Unable to set value in ${conf}"
fi
_install_log "Unmasking and enabling hostapd service"
sudo systemctl unmask hostapd.service
sudo systemctl enable hostapd.service
_install_status 0 _install_status 0
else
_install_log "Copying defaults.json to $raspap_network"
sudo cp $webroot_dir/config/defaults.json $raspap_network || _install_status 1 "Unable to move defaults.json settings"
fi fi
} }
@ -745,10 +773,11 @@ function _patch_system_files() {
sudo cp "$webroot_dir/installers/raspap.sudoers" $raspap_sudoers || _install_status 1 "Unable to apply raspap.sudoers to $raspap_sudoers" sudo cp "$webroot_dir/installers/raspap.sudoers" $raspap_sudoers || _install_status 1 "Unable to apply raspap.sudoers to $raspap_sudoers"
sudo chmod 0440 $raspap_sudoers || _install_status 1 "Unable to change file permissions for $raspap_sudoers" sudo chmod 0440 $raspap_sudoers || _install_status 1 "Unable to change file permissions for $raspap_sudoers"
_install_log "Creating RaspAP debug log control script" if [ ! -d "$raspap_dir/system" ]; then
sudo mkdir $raspap_dir/system || _install_status 1 "Unable to create directory '$raspap_dir/system'" sudo mkdir $raspap_dir/system || _install_status 1 "Unable to create directory '$raspap_dir/system'"
fi
# Copy debug shell script _install_log "Creating RaspAP debug log control script"
sudo cp "$webroot_dir/installers/"debuglog.sh "$raspap_dir/system" || _install_status 1 "Unable to move debug logging script" sudo cp "$webroot_dir/installers/"debuglog.sh "$raspap_dir/system" || _install_status 1 "Unable to move debug logging script"
# Set ownership and permissions # Set ownership and permissions
@ -761,19 +790,6 @@ function _patch_system_files() {
sudo ln -s /usr/share/dhcpcd/hooks/10-wpa_supplicant /etc/dhcp/dhclient-enter-hooks.d/ sudo ln -s /usr/share/dhcpcd/hooks/10-wpa_supplicant /etc/dhcp/dhclient-enter-hooks.d/
fi fi
# Unmask and enable hostapd.service
_install_log "Unmasking and enabling hostapd service"
sudo systemctl unmask hostapd.service
sudo systemctl enable hostapd.service
# Set correct DAEMON_CONF path for hostapd (Ubuntu20 + Armbian22)
if [ ${OS,,} = "ubuntu" ] && [[ ${RELEASE} =~ ^(22.04|20.04|19.10|18.04) ]]; then
conf="/etc/default/hostapd"
key="DAEMON_CONF"
value="/etc/hostapd/hostapd.conf"
echo "Setting default ${key} path to ${value}"
sudo sed -i -E "/^#?$key/ { s/^#//; s%=.*%=\"$value\"%; }" "$conf" || _install_status 1 "Unable to set value in ${conf}"
fi
_install_status 0 _install_status 0
} }
@ -832,6 +848,23 @@ function _optimize_php() {
fi fi
} }
# search for optional installation files names install_feature_*.sh
function _install_extra_features() {
if [ "$insiders" == 1 ]; then
_install_log "Installing additional features (Insiders)"
for feature in $(ls $webroot_dir/installers/install_feature_*.sh) ; do
source $feature
f=$(basename $feature)
func="_${f%.*}"
if declare -f -F $func > /dev/null; then
$func || _install_status 1 "Unable to install feature ($func)"
else
_install_status 1 "Install file $f is missing install function $func"
fi
done
fi
}
function _install_complete() { function _install_complete() {
_install_log "Installation completed" _install_log "Installation completed"
if [ "$repo" == "RaspAP/raspap-insiders" ]; then if [ "$repo" == "RaspAP/raspap-insiders" ]; then

View file

@ -1,31 +1,22 @@
#!/bin/bash #!/bin/bash
# #
# RaspAP Quick Installer # RaspAP Quick Installer - Installs and updates RaspAP
# Author: @billz <billzimmerman@gmail.com> # Author: @billz <billzimmerman@gmail.com>
# Author URI: https://github.com/billz/ # Author URI: https://github.com/billz
# Project URI: https://github.com/RaspAP/
# License: GNU General Public License v3.0 # License: GNU General Public License v3.0
# License URI: https://github.com/raspap/raspap-webgui/blob/master/LICENSE # License URI: https://github.com/RaspAP/raspap-webgui/blob/master/LICENSE
# #
# Usage: raspbian.sh [options] # Usage: raspbian.sh [options]
# #
# Installs an instance of RaspAP. # See below for options and usage examples.
# #
# OPTIONS: # GNU GENERAL PUBLIC LICENSE
# -y, --yes, --assume-yes Assume "yes" as answer to all prompts and run non-interactively # This program is free software: you may copy, redistribute and/or modify
# -c, --cert, --certficate Installs mkcert and generates an SSL certificate for lighttpd # it under the terms of the GNU General Public License as published by
# -o, --openvpn <flag> Used with -y, --yes, sets OpenVPN install option (0=no install) # the Free Software Foundation, under version 3 of the License. You are not
# -a, --adblock <flag> Used with -y, --yes, sets Adblock install option (0=no install) # obligated to bundle the LICENSE file with your RaspAP projects as long as
# -w, --wireguard <flag> Used with -y, --yes, sets WireGuard install option (0=no install) # you leave these references intact in the header comments of your source files.
# -c, --cert, --certificate Installs an SSL certificate with mkcert and configures lighttpd for HTTPS
# -r, --repo, --repository <name> Overrides the default GitHub repo (RaspAP/raspap-webgui)
# -b, --branch <name> Overrides the default git branch (master)
# -t, --token <accesstoken> Specify a GitHub token to access a private repository
# -u, --upgrade Upgrades an existing installation to the latest release version
# -i, --insiders Installs from the Insiders Edition (RaspAP/raspap-insiders)
# -m, --minwrite Configures a microSD card for minimum write operation
# -v, --version Outputs release info and exits
# -n, --uninstall Loads and executes the uninstaller
# -h, --help Outputs usage notes and exits
# #
# NOTE # NOTE
# Depending on options passed to the installer, ONE of the following # Depending on options passed to the installer, ONE of the following
@ -38,9 +29,51 @@
# https://raw.githubusercontent.com/raspap/raspap-webgui/master/installers/minwrite.sh # https://raw.githubusercontent.com/raspap/raspap-webgui/master/installers/minwrite.sh
# - or - # - or -
# https://raw.githubusercontent.com/raspap/raspap-webgui/master/installers/uninstall.sh # https://raw.githubusercontent.com/raspap/raspap-webgui/master/installers/uninstall.sh
#
# You are not obligated to bundle the LICENSE file with your RaspAP projects as long function _usage() {
# as you leave these references intact in the header comments of your source files. cat << EOF
Usage: raspbian.sh [options]
Installs an instance of RaspAP or a helper component.
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)
-w, --wireguard <flag> Used with -y, --yes, sets WireGuard install option (0=no install)
-r, --repo, --repository <name> Overrides the default GitHub repo (RaspAP/raspap-webgui)
-b, --branch <name> Overrides the default git branch (latest release)
-t, --token <accesstoken> Specify a GitHub token to access a private repository
-n, --name <username> Specify a GitHub username to access a private repository
-u, --upgrade Upgrades an existing installation to the latest release version
-d, --update Updates an existing installation to the latest release version
-p, --path Used with -d, --update, sets the existing install path
-i, --insiders Installs from the Insiders Edition (RaspAP/raspap-insiders)
-m, --minwrite Configures a microSD card for minimum write operation
-v, --version Outputs release info and exits
-n, --uninstall Loads and executes the uninstaller
-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 --wireguard 1 --adblock 0
Invoke remotely, uprgrade an existing install to the Insiders Edition:
curl -sL https://install.raspap.com | bash -s -- --upgrade --insiders --name <name> --token <token>
Invoke remotely, perform an unattended update to the latest release version:
curl -sL https://install.raspap.com | bash -s -- --yes --update --path /var/www/html
EOF
exit
}
set -eo pipefail set -eo pipefail
@ -58,12 +91,14 @@ function _parse_params() {
# default option values # default option values
assume_yes=0 assume_yes=0
upgrade=0 upgrade=0
update=0
ovpn_option=1 ovpn_option=1
adblock_option=1 adblock_option=1
wg_option=1 wg_option=1
insiders=0 insiders=0
minwrite=0 minwrite=0
acctoken="" acctoken=""
path=""
while :; do while :; do
case "${1-}" in case "${1-}" in
@ -111,6 +146,17 @@ function _parse_params() {
acctoken="$2" acctoken="$2"
shift shift
;; ;;
-n|--name)
username="$2"
shift
;;
-d|--update)
update=1
;;
-p|--path)
path="$2"
shift
;;
-v|--version) -v|--version)
_version _version
;; ;;
@ -145,46 +191,6 @@ function _log_output() {
exec 2>&1 exec 2>&1
} }
function _usage() {
cat << EOF
Usage: raspbian.sh options
Installs an instance of RaspAP or a helper component.
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)
-w, --wireguard <flag> Used with -y, --yes, sets WireGuard install option (0=no install)
-c, --cert, --certificate Installs an SSL certificate with mkcert and configures lighttpd for HTTPS
-r, --repo, --repository <name> Overrides the default GitHub repo (RaspAP/raspap-webgui)
-b, --branch <name> Overrides the default git branch (latest release)
-t, --token <accesstoken> Specify a GitHub token to access a private repository
-u, --upgrade Upgrades an existing installation to the latest release version
-i, --insiders Installs from the Insiders Edition (RaspAP/raspap-insiders)
-m, --minwrite Configures a microSD card for minimum write operation
-v, --version Outputs release info and exits
-n, --uninstall Loads and executes the uninstaller
-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
Invoke remotely, uprgrade an existing install to the Insiders Edition:
curl -sL https://install.raspap.com | bash -s -- --upgrade --insiders
EOF
exit
}
function _version() { function _version() {
_get_release _get_release
echo -e "RaspAP v${RASPAP_RELEASE} - Simple wireless AP setup & management for Debian-based devices" echo -e "RaspAP v${RASPAP_RELEASE} - Simple wireless AP setup & management for Debian-based devices"
@ -260,18 +266,7 @@ function _load_installer() {
if [ -z ${branch} ]; then if [ -z ${branch} ]; then
branch=$RASPAP_LATEST branch=$RASPAP_LATEST
fi fi
# add optional auth token header if defined with -t, --token option
header=()
if [[ ! -z "$acctoken" ]]; then
header=(--header "Authorization: token $acctoken")
fi
UPDATE_URL="https://raw.githubusercontent.com/$repo_common/$branch/" UPDATE_URL="https://raw.githubusercontent.com/$repo_common/$branch/"
header=()
if [[ ! -z "$acctoken" ]]; then
header=(--header "Authorization: token $acctoken")
fi
if [ "${install_cert:-}" = 1 ]; then if [ "${install_cert:-}" = 1 ]; then
source="mkcert" source="mkcert"
@ -296,8 +291,13 @@ function _load_installer() {
component="Install" component="Install"
wget "${header[@]}" -q ${UPDATE_URL}installers/${source}.sh -O /tmp/raspap_${source}.sh wget "${header[@]}" -q ${UPDATE_URL}installers/${source}.sh -O /tmp/raspap_${source}.sh
source /tmp/raspap_${source}.sh && rm -f /tmp/raspap_${source}.sh source /tmp/raspap_${source}.sh && rm -f /tmp/raspap_${source}.sh
_install_raspap || _install_status 1 "Unable to install RaspAP" if [ "$update" == 1 ]; then
_update_raspap || _install_status 1 "Unable to update RaspAP"
else
_install_raspap || _install_status 1 "Unable to install RaspAP"
fi
fi fi
} }
_main "$@" _main "$@"