From bc6ec3a9bf3cf9b4d967df0442f57eaa92ce4339 Mon Sep 17 00:00:00 2001 From: billz Date: Tue, 14 Nov 2023 08:49:21 +0000 Subject: [PATCH] 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 "$@" +