Skip to content

Commit 728cc39

Browse files
committed
Fixed snappy download via proxy
1 parent d9bd2cb commit 728cc39

1 file changed

Lines changed: 50 additions & 15 deletions

File tree

scripts/snappy.sh

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,20 @@ function fixperms {
3636
chown -R www-data:www-data "$1/"
3737
}
3838

39-
# Handle http proxy if set
40-
if [ ! -z "$PROXY_HOST" -a ! -z "$PROXY_PORT" ] ; then
41-
# ok, by all means add proxy
39+
# Handle http proxy if set - comprehensive proxy support matching provision.sh
40+
function setup_proxy_environment {
41+
# Set both HTTP and HTTPS proxy environment variables
4242
export HTTP_PROXY="http://$PROXY_HOST:$PROXY_PORT"
43+
export HTTPS_PROXY="http://$PROXY_HOST:$PROXY_PORT"
44+
echo "===> Proxy configured: $PROXY_HOST:$PROXY_PORT"
4345

4446
# check for auth
4547
if [ ! -z "$PROXY_USER" -a ! -z "$PROXY_PASS" ] ; then
4648
export HTTP_PROXY="http://$PROXY_USER:$PROXY_PASS@$PROXY_HOST:$PROXY_PORT"
49+
export HTTPS_PROXY="http://$PROXY_USER:$PROXY_PASS@$PROXY_HOST:$PROXY_PORT"
50+
echo "===> Proxy authentication enabled for user: $PROXY_USER"
4751
fi
48-
fi
52+
}
4953

5054
# install php dependencies:
5155
apt-get install ${APT_OPTS} $SNAPPY_PKGS
@@ -69,27 +73,51 @@ R=0
6973
if [ -f "./$SNAPPY_FILE" -a "$DOMAIN" == "mailad.cu" ]; then
7074
cp "./$SNAPPY_FILE" "/tmp/$SNAPPY_FILE"
7175
else
72-
wget -q --no-clobber "$SNAPPY_URL" -O "/tmp/$SNAPPY_FILE"
76+
# Add proxy options to wget for package download if proxy is configured
77+
WGET_OPTS="--no-clobber"
78+
if [ "$PROXY_HOST" -a "$PROXY_PORT" ] ; then
79+
echo "===> Using proxy for SnappyMail package download: $PROXY_HOST:$PROXY_PORT" | tee -a $FILE
80+
WGET_OPTS="${WGET_OPTS} --proxy=on --http-proxy=\"$HTTP_PROXY\" --https-proxy=\"$HTTPS_PROXY\""
81+
fi
82+
83+
echo "===> Downloading SnappyMail package from: $SNAPPY_URL" | tee -a $FILE
84+
wget -q ${WGET_OPTS} "$SNAPPY_URL" -O "/tmp/$SNAPPY_FILE"
7385
R=$?
7486
fi
7587

7688
# check if download fails
7789
if [ $R -ne 0 -a $R -ne 1 ]; then
78-
echo "===> Error!" > $FILE
79-
echo " Download of the snappymail package failed" >> $FILE
80-
echo " URL is: $SNAPPY_URL" >> $FILE
81-
echo " This is a connectivity issue, if you use a proxy go to /etc/mailad/mailad.conf" >> $FILE
82-
echo " and configure the proxy there." >> $FILE
83-
echo "" >> $FILE
84-
echo " Webmail Installation aborted" >> $FILE
90+
echo "===> Error!" | tee -a $FILE
91+
echo " Download of the snappymail package failed" | tee -a $FILE
92+
echo " URL is: $SNAPPY_URL" | tee -a $FILE
93+
echo " Return code: $R" | tee -a $FILE
94+
95+
# Provide specific proxy-related error messages
96+
if [ ! -z "$PROXY_HOST" -a ! -z "$PROXY_PORT" ] ; then
97+
echo " Proxy configured: $PROXY_HOST:$PROXY_PORT" | tee -a $FILE
98+
if [ ! -z "$PROXY_USER" -a ! -z "$PROXY_PASS" ] ; then
99+
echo " Proxy authentication: enabled for user $PROXY_USER" | tee -a $FILE
100+
fi
101+
echo " This could be a proxy authentication or connectivity issue." | tee -a $FILE
102+
echo " Please verify:" | tee -a $FILE
103+
echo " - Proxy server is reachable" | tee -a $FILE
104+
echo " - Proxy credentials are correct (if required)" | tee -a $FILE
105+
echo " - Proxy allows access to github.com" | tee -a $FILE
106+
else
107+
echo " This is a connectivity issue, if you use a proxy go to /etc/mailad/mailad.conf" | tee -a $FILE
108+
echo " and configure the proxy there." | tee -a $FILE
109+
fi
110+
111+
echo "" | tee -a $FILE
112+
echo " Webmail Installation aborted" | tee -a $FILE
85113

86114
# dump msg $FILE
87115
cat $FILE
88116

89117
# add some instructions for the email
90-
echo "" >> $FILE
91-
echo " You can try later with the command: make webmail" >> $FILE
92-
echo "" >> $FILE
118+
echo "" | tee -a $FILE
119+
echo " You can try later with the command: make webmail" | tee -a $FILE
120+
echo "" | tee -a $FILE
93121

94122
# send the email as a reminder
95123
send_email "MailAD provision error." "$ADMINMAIL" "$FILE"
@@ -175,6 +203,13 @@ CONFIG="${CONFIGFOLDER}/application.ini"
175203
# small delay to allow the service to create the default config; options
176204
OPTS="--no-check-certificate"
177205
if [ "$WEBSERVER_HTTP_ENABLED" == "yes" ]; then OPTS="--no-hsts" ; fi
206+
207+
# Add proxy options to wget if proxy is configured
208+
if [ ! -z "$PROXY_HOST" -a ! -z "$PROXY_PORT" ] ; then
209+
OPTS="${OPTS} --proxy=on --http-proxy=$HTTP_PROXY --https-proxy=$HTTPS_PROXY"
210+
echo "===> Using proxy for SnappyMail admin setup: $PROXY_HOST:$PROXY_PORT"
211+
fi
212+
178213
while [ ! -f "$PASS" ] ; do
179214
# get it...
180215
wget -q ${OPTS} "$WEBPROTO://$HOSTNAME/?admin" -O /dev/null

0 commit comments

Comments
 (0)