From bc6ec3a9bf3cf9b4d967df0442f57eaa92ce4339 Mon Sep 17 00:00:00 2001 From: billz Date: Tue, 14 Nov 2023 08:49:21 +0000 Subject: [PATCH 1/9] Implement --update switch + GitHub user/token auth --- installers/common.sh | 42 +++++++++++++++++++++++++++++++++++++----- installers/raspbian.sh | 37 +++++++++++++++++++++++++------------ 2 files changed, 62 insertions(+), 17 deletions(-) diff --git a/installers/common.sh b/installers/common.sh index 0af9b920..14e65f07 100755 --- a/installers/common.sh +++ b/installers/common.sh @@ -64,6 +64,22 @@ function _install_raspap() { _install_complete } +# Performs a minimal update of an existing installation to the latest release version. +# NOTE: the user is not prompted to install new RaspAP components. +# The -y, --yes and -p, --path switches may be used for an unattended update. +function _update_raspap() { + _display_welcome + _config_installation + _update_system_packages + _install_dependencies + _create_raspap_directories + _check_for_old_configs + _download_latest_files + _change_file_ownership + _patch_system_files + _install_complete +} + # search for optional installation files names install_feature_*.sh function _install_mobile_clients() { if [ "$insiders" == 1 ]; then @@ -86,9 +102,15 @@ function _install_mobile_clients() { function _config_installation() { if [ "$upgrade" == 1 ]; then opt=(Upgrade Upgrading upgrade) + elif [ "$update" == 1 ]; then + opt=(Update Updating update) else opt=(Install Installing installation) fi + if [ -n "$path" ]; then + echo "Setting install path to ${path}" + webroot_dir=$path + fi _install_log "Configure ${opt[2]}" _get_linux_distro echo "Detected OS: ${DESC} ${LONG_BIT}-bit" @@ -107,6 +129,9 @@ function _config_installation() { if [ "$upgrade" == 1 ]; then echo "This will upgrade your existing install to version ${RASPAP_RELEASE}" echo "Your configuration will NOT be changed" + elif [ "$update" == 1 ]; then + echo "This will update your existing install to version ${RASPAP_RELEASE}" + echo "Your configuration will NOT be changed" fi echo -n "Complete ${opt[2]} with these values? [Y/n]: " if [ "$assume_yes" == 0 ]; then @@ -255,7 +280,7 @@ function _enable_php_lighttpd() { # Verifies existence and permissions of RaspAP directory function _create_raspap_directories() { - if [ "$upgrade" == 1 ]; then + if [ "$upgrade" == 1 ] || [ "$update" == 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" @@ -562,10 +587,17 @@ function _download_latest_files() { _install_log "Cloning latest files from github" if [ "$repo" == "RaspAP/raspap-insiders" ]; then - _install_status 3 - echo "Insiders please read this: https://docs.raspap.com/insiders/#authentication" + if [ -n "$username" ] && [ -n "$acctoken" ]; then + 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 - git clone --branch $branch --depth 1 -c advice.detachedHead=false $git_source_url /tmp/raspap-webgui || clone=false if [ "$clone" = false ]; then _install_status 1 "Unable to download files from github" echo "The installer cannot continue." >&2 @@ -599,7 +631,7 @@ function _change_file_ownership() { # Check for existing configuration files function _check_for_old_configs() { - if [ "$upgrade" == 1 ]; then + if [ "$upgrade" == 1 ] || ["$update" == 1 ]; then _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" else diff --git a/installers/raspbian.sh b/installers/raspbian.sh index 32b115af..c88987cd 100755 --- a/installers/raspbian.sh +++ b/installers/raspbian.sh @@ -20,7 +20,10 @@ # -r, --repo, --repository Overrides the default GitHub repo (RaspAP/raspap-webgui) # -b, --branch Overrides the default git branch (master) # -t, --token Specify a GitHub token to access a private repository +# -n, --name 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 @@ -58,12 +61,14 @@ function _parse_params() { # default option values assume_yes=0 upgrade=0 + update=0 ovpn_option=1 adblock_option=1 wg_option=1 insiders=0 minwrite=0 acctoken="" + path="" while :; do case "${1-}" in @@ -111,6 +116,17 @@ function _parse_params() { acctoken="$2" shift ;; + -n|--name) + username="$2" + shift + ;; + -d|--update) + update=1 + ;; + -p|--path) + path="$2" + shift + ;; -v|--version) _version ;; @@ -161,7 +177,10 @@ OPTIONS: -r, --repo, --repository Overrides the default GitHub repo (RaspAP/raspap-webgui) -b, --branch Overrides the default git branch (latest release) -t, --token Specify a GitHub token to access a private repository +-n, --name 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 @@ -260,18 +279,7 @@ function _load_installer() { if [ -z ${branch} ]; then branch=$RASPAP_LATEST 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/" - header=() - if [[ ! -z "$acctoken" ]]; then - header=(--header "Authorization: token $acctoken") - fi if [ "${install_cert:-}" = 1 ]; then source="mkcert" @@ -296,8 +304,13 @@ function _load_installer() { component="Install" wget "${header[@]}" -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" + 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 } _main "$@" + From 4c6ec03ea92769b91ea27024af8bad68b15bee6e Mon Sep 17 00:00:00 2001 From: billz Date: Wed, 15 Nov 2023 18:06:22 +0000 Subject: [PATCH 2/9] Fixup existing config + directory handling for update --- installers/common.sh | 52 +++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/installers/common.sh b/installers/common.sh index 14e65f07..2deabefd 100755 --- a/installers/common.sh +++ b/installers/common.sh @@ -65,14 +65,13 @@ function _install_raspap() { } # Performs a minimal update of an existing installation to the latest release version. -# NOTE: the user is not prompted to install new RaspAP components. +# The user is not prompted to install new RaspAP components. # The -y, --yes and -p, --path switches may be used for an unattended update. function _update_raspap() { _display_welcome _config_installation _update_system_packages _install_dependencies - _create_raspap_directories _check_for_old_configs _download_latest_files _change_file_ownership @@ -107,15 +106,15 @@ function _config_installation() { else opt=(Install Installing installation) fi - if [ -n "$path" ]; then - echo "Setting install path to ${path}" - webroot_dir=$path - fi _install_log "Configure ${opt[2]}" _get_linux_distro echo "Detected OS: ${DESC} ${LONG_BIT}-bit" echo "Using GitHub repository: ${repo} ${branch} branch" 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]: " if [ "$assume_yes" == 0 ]; then read answer < /dev/tty @@ -126,11 +125,8 @@ function _config_installation() { echo -e fi echo "${opt[1]} lighttpd directory: ${webroot_dir}" - if [ "$upgrade" == 1 ]; then - echo "This will upgrade your existing install to version ${RASPAP_RELEASE}" - echo "Your configuration will NOT be changed" - elif [ "$update" == 1 ]; then - echo "This will update your existing install to version ${RASPAP_RELEASE}" + if [ "$upgrade" == 1 ] || [ "$update" == 1 ]; then + echo "This will ${opt[2]} your existing install to version ${RASPAP_RELEASE}" echo "Your configuration will NOT be changed" fi echo -n "Complete ${opt[2]} with these values? [Y/n]: " @@ -280,13 +276,6 @@ function _enable_php_lighttpd() { # Verifies existence and permissions of RaspAP directory function _create_raspap_directories() { - if [ "$upgrade" == 1 ] || [ "$update" == 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" 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" @@ -580,12 +569,13 @@ function _download_latest_files() { if [ ! -d "$webroot_dir" ]; then sudo mkdir -p $webroot_dir || _install_status 1 "Unable to create new webroot directory" fi - - if [ -d "$webroot_dir" ]; then + if [ -d "$webroot_dir" ] && [ -z "$update" ]; then sudo mv $webroot_dir "$webroot_dir.`date +%F-%R`" || _install_status 1 "Unable to remove old webroot directory" + elif [ "$update" == 1 ]; then + sudo rm -rf "$webroot_dir" fi - _install_log "Cloning latest files from github" + _install_log "Cloning latest files from GitHub" if [ "$repo" == "RaspAP/raspap-insiders" ]; then if [ -n "$username" ] && [ -n "$acctoken" ]; then insiders_source_url="https://${username}:${acctoken}@github.com/$repo" @@ -604,9 +594,9 @@ function _download_latest_files() { exit 1 fi - sudo mv /tmp/raspap-webgui $webroot_dir || _install_status 1 "Unable to move raspap-webgui to web root" + sudo mv /tmp/raspap-webgui $webroot_dir || _install_status 1 "Unable to move raspap-webgui to $webroot_dir" - if [ "$upgrade" == 1 ]; then + if [ "$upgrade" == 1 ] || [ "$update" == 1 ]; then _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" @@ -631,9 +621,13 @@ function _change_file_ownership() { # Check for existing configuration files function _check_for_old_configs() { - if [ "$upgrade" == 1 ] || ["$update" == 1 ]; then + if [ "$upgrade" == 1 ] || [ "$update" == 1 ]; then _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" + 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 _install_log "Backing up existing configs to ${raspap_dir}/backups" if [ -f /etc/network/interfaces ]; then @@ -681,7 +675,6 @@ function _default_configuration() { 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_wlan0.conf $raspap_wlan0 || _install_status 1 "Unable to move dnsmasq wlan0 configuration file" sudo cp $webroot_dir/config/dhcpcd.conf /etc/dhcpcd.conf || _install_status 1 "Unable to move dhcpcd configuration file" - 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" sudo chown $raspap_user:$raspap_user "$raspap_network"/defaults.json || _install_status 1 "Unable to change file ownership for defaults.json" @@ -713,6 +706,9 @@ function _default_configuration() { _install_status 0 fi + _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" + } # Install and enable RaspAP daemon @@ -777,8 +773,10 @@ 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 chmod 0440 $raspap_sudoers || _install_status 1 "Unable to change file permissions for $raspap_sudoers" - _install_log "Creating RaspAP debug log control script" - sudo mkdir $raspap_dir/system || _install_status 1 "Unable to create directory '$raspap_dir/system'" + if [ ! -d "$raspap_dir" ]; then + _install_log "Creating RaspAP debug log control script" + sudo mkdir $raspap_dir/system || _install_status 1 "Unable to create directory '$raspap_dir/system'" + fi # Copy debug shell script sudo cp "$webroot_dir/installers/"debuglog.sh "$raspap_dir/system" || _install_status 1 "Unable to move debug logging script" From bfe62fb2c94f9005d7758c8adec1c1df6ad62522 Mon Sep 17 00:00:00 2001 From: billz Date: Wed, 15 Nov 2023 18:13:56 +0000 Subject: [PATCH 3/9] Replace comment block with usage() --- installers/raspbian.sh | 105 +++++++++++++++++------------------------ 1 file changed, 42 insertions(+), 63 deletions(-) diff --git a/installers/raspbian.sh b/installers/raspbian.sh index c88987cd..21008be0 100755 --- a/installers/raspbian.sh +++ b/installers/raspbian.sh @@ -10,26 +10,6 @@ # # Installs an instance of RaspAP. # -# 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 Used with -y, --yes, sets OpenVPN install option (0=no install) -# -a, --adblock Used with -y, --yes, sets Adblock install option (0=no install) -# -w, --wireguard 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 Overrides the default GitHub repo (RaspAP/raspap-webgui) -# -b, --branch Overrides the default git branch (master) -# -t, --token Specify a GitHub token to access a private repository -# -n, --name 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 -# # NOTE # Depending on options passed to the installer, ONE of the following # additional shell scripts will be downloaded and sourced: @@ -45,6 +25,48 @@ # 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. +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 Used with -y, --yes, sets OpenVPN install option (0=no install) +-a, --adblock Used with -y, --yes, sets Adblock install option (0=no install) +-w, --wireguard Used with -y, --yes, sets WireGuard install option (0=no install) +-r, --repo, --repository Overrides the default GitHub repo (RaspAP/raspap-webgui) +-b, --branch Overrides the default git branch (latest release) +-t, --token Specify a GitHub token to access a private repository +-n, --name 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 --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 +} + set -eo pipefail function _main() { @@ -161,49 +183,6 @@ function _log_output() { 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 Used with -y, --yes, sets OpenVPN install option (0=no install) --a, --adblock Used with -y, --yes, sets Adblock install option (0=no install) --w, --wireguard 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 Overrides the default GitHub repo (RaspAP/raspap-webgui) --b, --branch Overrides the default git branch (latest release) --t, --token Specify a GitHub token to access a private repository --n, --name 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 --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() { _get_release echo -e "RaspAP v${RASPAP_RELEASE} - Simple wireless AP setup & management for Debian-based devices" From 4c6455f1d961ab2535cf7765054fef00304fafb7 Mon Sep 17 00:00:00 2001 From: billz Date: Wed, 15 Nov 2023 19:27:14 +0000 Subject: [PATCH 4/9] Update file header, usage examples --- installers/raspbian.sh | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/installers/raspbian.sh b/installers/raspbian.sh index 21008be0..3b0a0da8 100755 --- a/installers/raspbian.sh +++ b/installers/raspbian.sh @@ -1,14 +1,21 @@ #!/bin/bash # -# RaspAP Quick Installer +# RaspAP Quick Installer - Installs and updates RaspAP # Author: @billz -# 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 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] # -# Installs an instance of RaspAP. +# See below for options and usage examples. +# +# This program is free software: you may copy, redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, unser version 3 of the License. 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. # # NOTE # Depending on options passed to the installer, ONE of the following @@ -21,13 +28,10 @@ # https://raw.githubusercontent.com/raspap/raspap-webgui/master/installers/minwrite.sh # - or - # 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 -# as you leave these references intact in the header comments of your source files. function _usage() { cat << EOF -Usage: raspbian.sh options +Usage: raspbian.sh [options] Installs an instance of RaspAP or a helper component. @@ -58,10 +62,13 @@ Examples: 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 + 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 + curl -sL https://install.raspap.com | bash -s -- --upgrade --insiders --name --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 From 387f52a2e4e64eb9bfc1d9b8fe52c1abec8150cc Mon Sep 17 00:00:00 2001 From: billz Date: Thu, 16 Nov 2023 10:05:18 +0000 Subject: [PATCH 5/9] Improve messages, fixup order of install steps --- installers/common.sh | 74 +++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 35 deletions(-) diff --git a/installers/common.sh b/installers/common.sh index 2deabefd..70415d3f 100755 --- a/installers/common.sh +++ b/installers/common.sh @@ -288,9 +288,6 @@ function _create_raspap_directories() { # Create a directory to store networking configs echo "Creating $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" sudo chown -R $raspap_user:$raspap_user "$raspap_dir" || _install_status 1 "Unable to change file ownership for '$raspap_dir'" } @@ -566,9 +563,6 @@ function _create_openvpn_scripts() { # Fetches latest files from github to webroot function _download_latest_files() { - if [ ! -d "$webroot_dir" ]; then - sudo mkdir -p $webroot_dir || _install_status 1 "Unable to create new webroot directory" - fi if [ -d "$webroot_dir" ] && [ -z "$update" ]; then sudo mv $webroot_dir "$webroot_dir.`date +%F-%R`" || _install_status 1 "Unable to remove old webroot directory" elif [ "$update" == 1 ]; then @@ -594,6 +588,7 @@ function _download_latest_files() { exit 1 fi + _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 ] || [ "$update" == 1 ]; then @@ -629,7 +624,7 @@ function _check_for_old_configs() { sudo mv $raspap_dir/raspap.auth /tmp || _install_status 1 "Unable to backup raspap.auth to /tmp" fi else - _install_log "Backing up existing configs to ${raspap_dir}/backups" + _install_log "Checking for existing configs" if [ -f /etc/network/interfaces ]; then 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" @@ -671,17 +666,27 @@ function _default_configuration() { if [ "$upgrade" == 0 ]; then _install_log "Applying default configuration to installed services" - 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/090_raspap.conf $raspap_default || _install_status 1 "Unable to move dnsmasq default configuration file" - 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/dhcpcd.conf /etc/dhcpcd.conf || _install_status 1 "Unable to move dhcpcd configuration file" - - 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" - echo "Checking for existence of /etc/dnsmasq.d" [ -d /etc/dnsmasq.d ] || sudo mkdir /etc/dnsmasq.d + echo "Copying $webroot_dir/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" + + echo "Copying $webroot_dir/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" + + echo "Copying $webroot_dir/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" + + echo "Copying $webroot_dir/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" + + echo "Copying $webroot_dir/defaults.json to $raspap_network" + 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" + sudo chown $raspap_user:$raspap_user "$raspap_network"defaults.json || _install_status 1 "Unable to change file ownership for defaults.json" + # Copy OS-specific bridge default config if [ ${OS,,} = "ubuntu" ] && [[ ${RELEASE} =~ ^(22.04|20.04|19.10|18.04) ]]; then echo "Copying bridged AP config to /etc/netplan" @@ -704,11 +709,24 @@ function _default_configuration() { sudo systemctl enable dhcpcd.service || _install_status 1 "Failed to enable raspap.service" fi - _install_status 0 - fi - _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" + # 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 + 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 } # Install and enable RaspAP daemon @@ -773,12 +791,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 chmod 0440 $raspap_sudoers || _install_status 1 "Unable to change file permissions for $raspap_sudoers" - if [ ! -d "$raspap_dir" ]; then - _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'" 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" # Set ownership and permissions @@ -791,19 +808,6 @@ function _patch_system_files() { sudo ln -s /usr/share/dhcpcd/hooks/10-wpa_supplicant /etc/dhcp/dhclient-enter-hooks.d/ 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 } From e6a90e728f2cba28b4ee5eedaf7f097951a099e5 Mon Sep 17 00:00:00 2001 From: billz Date: Thu, 16 Nov 2023 12:16:20 +0000 Subject: [PATCH 6/9] Modify conditions for update/upgrade --- installers/common.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/installers/common.sh b/installers/common.sh index 70415d3f..2a64afde 100755 --- a/installers/common.sh +++ b/installers/common.sh @@ -563,9 +563,9 @@ function _create_openvpn_scripts() { # Fetches latest files from github to webroot function _download_latest_files() { - if [ -d "$webroot_dir" ] && [ -z "$update" ]; then + if [ -d "$webroot_dir" ] && [ "$update" == 0 ]; then sudo mv $webroot_dir "$webroot_dir.`date +%F-%R`" || _install_status 1 "Unable to remove old webroot directory" - elif [ "$update" == 1 ]; then + elif [ "$upgrade" == 1 ] || [ "$update" == 1 ]; then sudo rm -rf "$webroot_dir" fi From 7782956917f1076ed8884ba9168f545f27516d1f Mon Sep 17 00:00:00 2001 From: billz Date: Thu, 16 Nov 2023 15:18:20 +0000 Subject: [PATCH 7/9] Rename _install_mobile_clients, clarify messages --- installers/common.sh | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/installers/common.sh b/installers/common.sh index 2a64afde..3ee07b36 100755 --- a/installers/common.sh +++ b/installers/common.sh @@ -57,7 +57,7 @@ function _install_raspap() { _configure_networking _prompt_install_adblock _prompt_install_openvpn - _install_mobile_clients + _install_extra_features _prompt_install_wireguard _prompt_install_vpn_providers _patch_system_files @@ -79,24 +79,6 @@ function _update_raspap() { _install_complete } -# search for optional installation files names install_feature_*.sh -function _install_mobile_clients() { - if [ "$insiders" == 1 ]; then - _install_log "Installing support for mobile data clients" - 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 - echo "Installing $func" - $func || _install_status 1 "Unable to install feature ($func)" - else - _install_status 1 "Install file $f is missing install function $func" - fi - done - fi -} - # Prompts user to set installation options function _config_installation() { if [ "$upgrade" == 1 ]; then @@ -866,6 +848,23 @@ function _optimize_php() { 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() { _install_log "Installation completed" if [ "$repo" == "RaspAP/raspap-insiders" ]; then From 7e8f63863d6a6b5d9b7c62d3f1a767e74d38d666 Mon Sep 17 00:00:00 2001 From: billz Date: Thu, 16 Nov 2023 17:07:36 +0000 Subject: [PATCH 8/9] Fix handling of config.php for different install types --- installers/common.sh | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/installers/common.sh b/installers/common.sh index 3ee07b36..32865812 100755 --- a/installers/common.sh +++ b/installers/common.sh @@ -573,7 +573,7 @@ function _download_latest_files() { _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 ] || [ "$update" == 1 ]; then + if [ "$update" == 1 ]; then _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" @@ -581,6 +581,11 @@ function _download_latest_files() { _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}" 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 _install_status 0 @@ -598,7 +603,7 @@ function _change_file_ownership() { # Check for existing configuration files function _check_for_old_configs() { - if [ "$upgrade" == 1 ] || [ "$update" == 1 ]; then + if [ "$update" == 1 ]; then _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" if [ -f $raspap_dir/raspap.auth ]; then @@ -651,19 +656,19 @@ function _default_configuration() { echo "Checking for existence of /etc/dnsmasq.d" [ -d /etc/dnsmasq.d ] || sudo mkdir /etc/dnsmasq.d - echo "Copying $webroot_dir/config/hostapd.conf to /etc/hostapd/hostapd.conf" + 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" - echo "Copying $webroot_dir/config/090_raspap.conf to $raspap_default" + 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" - echo "Copying $webroot_dir/config/090_wlan0.conf to $raspap_wlan0" + 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" - echo "Copying $webroot_dir/config/dhcpcd.conf to /etc/dhcpcd.conf" + 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" - echo "Copying $webroot_dir/defaults.json to $raspap_network" + 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" echo "Changing file ownership of ${raspap_network}defaults.json" @@ -679,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" 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 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" From dea57595141cd3c4d724ef972d29867f75af71d1 Mon Sep 17 00:00:00 2001 From: billz Date: Thu, 16 Nov 2023 17:32:04 +0000 Subject: [PATCH 9/9] Minor: tweak GPL verbiage --- installers/raspbian.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/installers/raspbian.sh b/installers/raspbian.sh index 3b0a0da8..deffde79 100755 --- a/installers/raspbian.sh +++ b/installers/raspbian.sh @@ -11,9 +11,10 @@ # # See below for options and usage examples. # -# This program is free software: you may copy, redistribute it and/or modify +# GNU GENERAL PUBLIC LICENSE +# This program is free software: you may copy, redistribute and/or modify # it under the terms of the GNU General Public License as published by -# the Free Software Foundation, unser version 3 of the License. You are not +# the Free Software Foundation, under version 3 of the License. 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. #