Skip to content

Commit

Permalink
Add Proxy Support to Unix Install Script (#515)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* pr feedback

* don't try and add proxy support to windows

Co-authored-by: Joseph Sirianni <[email protected]>
  • Loading branch information
schmikei and Joseph Sirianni authored Jan 3, 2022
1 parent cf1fa4b commit e418a18
Showing 1 changed file with 66 additions and 1 deletion.
67 changes: 66 additions & 1 deletion scripts/unix-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -228,6 +239,7 @@ setup_installation()
set_download_urls
set_install_dir
set_agent_home
set_proxy

# Service variables
set_service_user
Expand Down Expand Up @@ -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..."
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e418a18

Please sign in to comment.