2012-11-09 11:04:13 +00:00
|
|
|
#!/bin/bash
|
2014-02-26 19:53:45 +00:00
|
|
|
# Save the HTTP/[S] and noproxy settings if available.
|
2012-11-09 11:04:13 +00:00
|
|
|
# XXX: Obviously not suitable for downloadable images.
|
|
|
|
|
2014-04-03 02:24:15 +00:00
|
|
|
set -eu
|
|
|
|
set -o pipefail
|
2012-11-09 11:04:13 +00:00
|
|
|
set -o xtrace
|
|
|
|
|
2014-04-03 22:49:18 +00:00
|
|
|
have_apt=
|
|
|
|
have_yum=
|
|
|
|
have_zypper=
|
|
|
|
http_proxy=${http_proxy:-""}
|
|
|
|
https_proxy=${https_proxy:-""}
|
|
|
|
|
2013-03-08 11:24:45 +00:00
|
|
|
if [ -d /etc/apt ] ; then
|
2014-05-02 17:02:38 +00:00
|
|
|
have_apt=1
|
2013-03-08 11:24:45 +00:00
|
|
|
fi
|
|
|
|
if [ -e /etc/yum.conf ] ; then
|
2014-05-02 17:02:38 +00:00
|
|
|
have_yum=1
|
2013-03-08 11:24:45 +00:00
|
|
|
fi
|
2013-12-09 20:13:20 +00:00
|
|
|
if [ -d /etc/zypp ] ; then
|
2014-05-02 17:02:38 +00:00
|
|
|
have_zypper=1
|
2013-12-09 20:13:20 +00:00
|
|
|
fi
|
2013-03-08 11:24:45 +00:00
|
|
|
|
2012-11-09 11:04:13 +00:00
|
|
|
if [ -n "$http_proxy" ]; then
|
2014-05-02 17:02:38 +00:00
|
|
|
if [ -d ~stack ]; then
|
|
|
|
echo export http_proxy=$http_proxy >> ~stack/.profile
|
|
|
|
fi
|
|
|
|
if [ -n "$have_apt" ] ; then
|
|
|
|
echo "Acquire::http::Proxy \"$http_proxy\";" > /etc/apt/apt.conf.d/02-use-http-proxy
|
|
|
|
fi
|
|
|
|
if [ -n "$have_yum" ] ; then
|
|
|
|
sed -i -e "s,\[main\],[main]\nproxy=$http_proxy," /etc/yum.conf
|
|
|
|
fi
|
|
|
|
if [ -n "$have_zypper" ] ; then
|
|
|
|
sed -i -e "s,^HTTP_PROXY=.*$,HTTP_PROXY=\"$http_proxy\"," /etc/sysconfig/proxy
|
|
|
|
fi
|
2012-12-07 22:52:35 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$https_proxy" ]; then
|
2014-05-02 17:02:38 +00:00
|
|
|
if [ -d ~stack ]; then
|
|
|
|
echo export https_proxy=$https_proxy >> ~stack/.profile
|
|
|
|
fi
|
|
|
|
if [ -n "$have_apt" ] ; then
|
|
|
|
echo "Acquire::https::Proxy \"$https_proxy\";" > /etc/apt/apt.conf.d/02-use-https-proxy
|
|
|
|
fi
|
|
|
|
if [ -n "$have_zypper" ] ; then
|
|
|
|
sed -i -e "s,^HTTPS_PROXY=.*$,HTTPS_PROXY=\"$https_proxy\"," /etc/sysconfig/proxy
|
|
|
|
fi
|
2012-12-07 22:52:35 +00:00
|
|
|
fi
|
|
|
|
|
2014-02-26 19:53:45 +00:00
|
|
|
no_proxy=${no_proxy:+"$no_proxy,192.0.2.1"}
|
|
|
|
no_proxy=${no_proxy:-"192.0.2.1"}
|
|
|
|
if [ -n "$no_proxy" ]; then
|
2014-05-02 17:02:38 +00:00
|
|
|
if [ -d ~stack ]; then
|
|
|
|
echo export no_proxy=$no_proxy >> ~stack/.profile
|
|
|
|
fi
|
|
|
|
if [ -n "$have_apt" ] ; then
|
|
|
|
for host in $(sed 's/,/ /g' <<<$no_proxy); do
|
|
|
|
echo "Acquire::http::Proxy::$host \"DIRECT\";" >> /etc/apt/apt.conf.d/02-no-proxy
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
if [ -n "$have_zypper" ] ; then
|
|
|
|
sed -i -e "s,^\(NO_PROXY=.*\)\"$,\1\, $no_proxy\"," /etc/sysconfig/proxy
|
|
|
|
fi
|
2014-02-26 19:53:45 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$http_proxy" -o -n "$https_proxy" -o -n "$no_proxy" ]; then
|
2014-05-02 17:02:38 +00:00
|
|
|
if [ -n "$have_zypper" ] ; then
|
|
|
|
sed -i -e "s,^PROXY_ENABLED=.*$,PROXY_ENABLED=\"yes\"," /etc/sysconfig/proxy
|
|
|
|
fi
|
2012-11-09 11:04:13 +00:00
|
|
|
fi
|