From e418a1877d1425cf5dbaeb34d468329e2725da51 Mon Sep 17 00:00:00 2001 From: Keith Schmitt <32067685+schmikei@users.noreply.github.com> Date: Mon, 3 Jan 2022 10:09:14 -0500 Subject: [PATCH] Add Proxy Support to Unix Install Script (#515) * attempt adding proxy support to installer script * add to help message * add windows proxy installation * Apply suggestions from code review Co-authored-by: Joseph Sirianni * pr feedback * don't try and add proxy support to windows Co-authored-by: Joseph Sirianni --- scripts/unix-install.sh | 67 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/scripts/unix-install.sh b/scripts/unix-install.sh index 37e629771..7285077cf 100755 --- a/scripts/unix-install.sh +++ b/scripts/unix-install.sh @@ -152,6 +152,17 @@ Usage: If not provided, this will default to Stanza\'s GitHub releases. Example: '-l http://my.domain.org/stanza' will download from there. + $(fg_yellow '-x, --proxy') + Defines the proxy server to be used for communication by the install script. + Example: $(fg_blue -x) $(fg_magenta http\(s\)://server-ip:port/). + + $(fg_yellow '-U, --proxy-user') + Defines the proxy user to be used for communication by the install script. + + $(fg_yellow '-P, --proxy-password') + Defines the proxy password to be used for communication by the install script. + + EOF ) info "$USAGE" @@ -228,6 +239,7 @@ setup_installation() set_download_urls set_install_dir set_agent_home + set_proxy # Service variables set_service_user @@ -451,8 +463,20 @@ install_package() stop_service succeeded + proxy_args="" + if [ -n "$proxy" ]; then + proxy_args="-x $proxy" + if [ -n "$proxy_user" ]; then + proxy_args="$proxy_args -U $proxy_user:$proxy_password" + fi + fi + + if [ -n "$proxy" ]; then + info "Downloading package using proxy..." + fi + info "Downloading binary..." - curl -L "$agent_download_url" -o "$agent_binary" --progress-bar --fail || error_exit "$LINENO" "Failed to download package" + eval curl -L "$proxy_args" "$agent_download_url" -o "$agent_binary" --progress-bar --fail || error_exit "$LINENO" "Failed to download package" succeeded info "Setting permissions..." @@ -535,6 +559,41 @@ pipeline: EOF } +set_proxy() +{ + if [ -n "$proxy" ]; then + info "Using proxy from arguments: $proxy" + if [ -n "$proxy_user" ]; then + while [ -z "$proxy_password" ] && [ ! "$accept_defaults" = "yes" ]; do + increase_indent + command printf "${indent}$(fg_blue "$proxy_user@$proxy")'s password: " + stty -echo + read -r proxy_password + stty echo + info + if [ -z "$proxy_password" ]; then + warn "The password must be provided!" + fi + decrease_indent + done + protocol="$(echo "$proxy" | cut -d'/' -f1)" + host="$(echo "$proxy" | cut -d'/' -f3)" + full_proxy="$protocol//$proxy_user:$proxy_password@$host" + fi + + elif [ -n "$http_proxy" ]; then + info "Using proxy from profile: $http_proxy" + proxy="$http_proxy" + elif [ -n "$https_proxy" ]; then + info "Using proxy from profile: $https_proxy" + proxy="$https_proxy" + fi + + if [ -z "$full_proxy" ]; then + full_proxy="$proxy" + fi +} + # This will install the service by detecting the init system # and configuring the launcher to run accordinngly install_service() @@ -1071,6 +1130,12 @@ main() service_user=$2 ; shift 2 ;; -l|--url) url=$2 ; shift 2 ;; + -x|--proxy) + proxy=$2 ; shift 2 ;; + -U|--proxy-user) + proxy_user=$2 ; shift 2 ;; + -P|--proxy-password) + proxy_password=$2 ; shift 2 ;; -h|--help) usage force_exit