#!/bin/sh

. /etc/sysconfig/heat-params

DOCKER_PROXY_CONF=/etc/systemd/system/docker.service.d/proxy.conf
BASH_RC=/etc/bashrc

mkdir -p /etc/systemd/system/docker.service.d

if [ -n "$HTTP_PROXY" ]; then
    cat <<EOF | sed "s/^ *//" > $DOCKER_PROXY_CONF
    [Service]
    Environment=HTTP_PROXY=$HTTP_PROXY
EOF

    systemctl daemon-reload
    systemctl --no-block restart docker.service

    if [ -f "$BASH_RC" ]; then
        echo "declare -x http_proxy=$HTTP_PROXY" >> $BASH_RC
    else
        echo "File $BASH_RC does not exist, not setting http_proxy"
    fi
fi

if [ -n "$HTTPS_PROXY" ]; then
    if [ -f "$BASH_RC" ]; then
        echo "declare -x https_proxy=$HTTPS_PROXY" >> $BASH_RC
    else
        echo "File $BASH_RC does not exist, not setting https_proxy"
    fi
fi

if [ -n "$NO_PROXY" ]; then
    if [ -f "$BASH_RC" ]; then
        echo "declare -x no_proxy=$NO_PROXY" >> $BASH_RC
    else
        echo "File $BASH_RC does not exist, not setting no_proxy"
    fi
fi

#!/bin/sh

. /etc/sysconfig/heat-params

DOCKER_PROXY_CONF=/etc/systemd/system/docker.service.d/proxy.conf

if [ -n "$HTTP_PROXY" ]; then
    cat <<EOF | sed "s/^ *//" > $DOCKER_PROXY_CONF
    [Service]
    Environment=HTTP_PROXY=$HTTP_PROXY
EOF

    systemctl daemon-reload
    systemctl --no-block restart docker.service

    if [ -f "/etc/bashrc" ]; then
        echo "declare -x http_proxy=$HTTP_PROXY" >> /etc/bashrc
    else
        echo "File /etc/bashrc does not exist, not setting http_proxy"
    fi
fi

if [ -n "$HTTPS_PROXY" ]; then
    if [ -f "/etc/bashrc" ]; then
        echo "declare -x https_proxy=$HTTPS_PROXY" >> /etc/bashrc
    else
        echo "File /etc/bashrc does not exist, not setting https_proxy"
    fi
fi

if [ -n "$NO_PROXY" ]; then
    if [ -f "/etc/bashrc" ]; then
        echo "declare -x no_proxy=$NO_PROXY" >> /etc/bashrc
    else
        echo "File /etc/bashrc does not exist, not setting no_proxy"
fi

--- 
+++ 
@@ -3,6 +3,9 @@
 . /etc/sysconfig/heat-params
 
 DOCKER_PROXY_CONF=/etc/systemd/system/docker.service.d/proxy.conf
+BASH_RC=/etc/bashrc
+
+mkdir -p /etc/systemd/system/docker.service.d
 
 if [ -n "$HTTP_PROXY" ]; then
     cat <<EOF | sed "s/^ *//" > $DOCKER_PROXY_CONF
@@ -13,24 +16,25 @@
     systemctl daemon-reload
     systemctl --no-block restart docker.service
 
-    if [ -f "/etc/bashrc" ]; then
-        echo "declare -x http_proxy=$HTTP_PROXY" >> /etc/bashrc
+    if [ -f "$BASH_RC" ]; then
+        echo "declare -x http_proxy=$HTTP_PROXY" >> $BASH_RC
     else
-        echo "File /etc/bashrc does not exist, not setting http_proxy"
+        echo "File $BASH_RC does not exist, not setting http_proxy"
     fi
 fi
 
 if [ -n "$HTTPS_PROXY" ]; then
-    if [ -f "/etc/bashrc" ]; then
-        echo "declare -x https_proxy=$HTTPS_PROXY" >> /etc/bashrc
+    if [ -f "$BASH_RC" ]; then
+        echo "declare -x https_proxy=$HTTPS_PROXY" >> $BASH_RC
     else
-        echo "File /etc/bashrc does not exist, not setting https_proxy"
+        echo "File $BASH_RC does not exist, not setting https_proxy"
     fi
 fi
 
 if [ -n "$NO_PROXY" ]; then
-    if [ -f "/etc/bashrc" ]; then
-        echo "declare -x no_proxy=$NO_PROXY" >> /etc/bashrc
+    if [ -f "$BASH_RC" ]; then
+        echo "declare -x no_proxy=$NO_PROXY" >> $BASH_RC
     else
-        echo "File /etc/bashrc does not exist, not setting no_proxy"
+        echo "File $BASH_RC does not exist, not setting no_proxy"
+    fi
 fi
Fix docker proxy config file not correctly seting on k8s master

In I19c92dc9b4fe195037b5ad4ca49b529cf6be4cfb , we added proxy for k8s cluster,
but it is not working on k8s master since master doesn't have
/etc/systemd/system/docker.service.d/ which is diffenect from minion.

Beside, this patch also improves hardcode filename in add_proxy.sh.

Closes-Bug: #1508279
Change-Id: I03cd504276e9ca99625b93452f832de406cd1fb7
Co-authored-by: Madhuri Kumari <374fd32ebb2ce2b27f97edb5e8fba1c3200f4b7d@intel.com>
