From 4bdad68da5e658c16613c38f2d062ad7f1e86ead Mon Sep 17 00:00:00 2001 From: Patrick Skowronek Date: Thu, 5 Oct 2023 09:43:57 +0200 Subject: [PATCH] Added proxy user + pw detection --- bridgehead | 1 + lib/functions.sh | 11 +++++++++++ lib/monitoring.sh | 4 ++-- lib/prerequisites.sh | 2 +- lib/update-bridgehead.sh | 2 +- 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/bridgehead b/bridgehead index b937635..8db9735 100755 --- a/bridgehead +++ b/bridgehead @@ -65,6 +65,7 @@ loadVars() { fi detectCompose setHostname + setupProxy } case "$ACTION" in diff --git a/lib/functions.sh b/lib/functions.sh index 82a501d..0163b1c 100644 --- a/lib/functions.sh +++ b/lib/functions.sh @@ -9,6 +9,17 @@ detectCompose() { fi } +setupProxy() { + if [[ ! -z "$HTTP_PROXY_USERNAME" && ! -z "$HTTP_PROXY_PASSWORD" ]]; then + log "INFO" "Detected proxy user and password" + PROTO="$(echo $HTTP_PROXY_URL | grep :// | sed -e's,^\(.*://\).*,\1,g')" + URL="$(echo ${HTTP_PROXY_URL/$PROTO/})" + PROXY="$(echo $PROTO$HTTP_PROXY_USERNAME:$HTTP_PROXY_PASSWORD@$URL)" + else + PROXY=$HTTP_PROXY_URL + fi +} + exitIfNotRoot() { if [ "$EUID" -ne 0 ]; then log "ERROR" "Please run as root" diff --git a/lib/monitoring.sh b/lib/monitoring.sh index c3eb9fc..1b12272 100755 --- a/lib/monitoring.sh +++ b/lib/monitoring.sh @@ -47,8 +47,8 @@ function hc_send(){ if [ -n "$2" ]; then MSG="$2\n\nDocker stats:\n$UPTIME" - echo -e "$MSG" | https_proxy=$HTTPS_PROXY_URL curl --max-time 5 -A "$USER_AGENT" -s -o /dev/null -X POST --data-binary @- "$HCURL"/"$1" || log WARN "Monitoring failed: Unable to send data to $HCURL/$1" + echo -e "$MSG" | https_proxy=$PROXY curl --max-time 5 -A "$USER_AGENT" -s -o /dev/null -X POST --data-binary @- "$HCURL"/"$1" || log WARN "Monitoring failed: Unable to send data to $HCURL/$1" else - https_proxy=$HTTPS_PROXY_URL curl --max-time 5 -A "$USER_AGENT" -s -o /dev/null "$HCURL"/"$1" || log WARN "Monitoring failed: Unable to send data to $HCURL/$1" + https_proxy=$PROXY curl --max-time 5 -A "$USER_AGENT" -s -o /dev/null "$HCURL"/"$1" || log WARN "Monitoring failed: Unable to send data to $HCURL/$1" fi } diff --git a/lib/prerequisites.sh b/lib/prerequisites.sh index 2665b95..3140a2c 100755 --- a/lib/prerequisites.sh +++ b/lib/prerequisites.sh @@ -68,7 +68,7 @@ source /etc/bridgehead/${PROJECT}.conf source ${PROJECT}/vars set +e -SERVERTIME="$(https_proxy=$HTTPS_PROXY_URL curl -m 5 -s -I $BROKER_URL_FOR_PREREQ 2>&1 | grep -i -e '^Date: ' | sed -e 's/^Date: //i')" +SERVERTIME="$(https_proxy=$PROXY curl -m 5 -s -I $BROKER_URL_FOR_PREREQ 2>&1 | grep -i -e '^Date: ' | sed -e 's/^Date: //i')" RET=$? set -e if [ $RET -ne 0 ]; then diff --git a/lib/update-bridgehead.sh b/lib/update-bridgehead.sh index 9958eb5..37ac8cd 100755 --- a/lib/update-bridgehead.sh +++ b/lib/update-bridgehead.sh @@ -55,7 +55,7 @@ for DIR in /etc/bridgehead $(pwd); do OUT=$(retry 5 git -C $DIR fetch 2>&1 && retry 5 git -C $DIR pull 2>&1) else log "INFO" "Git is using proxy ${HTTP_PROXY_URL} from ${CONFFILE}" - OUT=$(retry 5 git -c http.proxy=$HTTP_PROXY_URL -c https.proxy=$HTTPS_PROXY_URL -C $DIR fetch 2>&1 && retry 5 git -c http.proxy=$HTTP_PROXY_URL -c https.proxy=$HTTPS_PROXY_URL -C $DIR pull 2>&1) + OUT=$(retry 5 git -c http.proxy=$PROXY -c https.proxy=$PROXY -C $DIR fetch 2>&1 && retry 5 git -c http.proxy=$PROXY -c https.proxy=$PROXY -C $DIR pull 2>&1) fi if [ $? -ne 0 ]; then report_error log "Unable to update git $DIR: $OUT"