-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathproxy_enable.sh
More file actions
executable file
·70 lines (60 loc) · 3.66 KB
/
proxy_enable.sh
File metadata and controls
executable file
·70 lines (60 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash
# Filename: proxy_config.sh
# By: Dan Burkland
# Date: 2015-12-23
# Purpose: The purpose of this script is to add the appropriate proxy configuration lines
# to the 1) "/root/docker/harvest/{bashrc,Dockerfile}" files which will be used to
# build the NetApp Harvest docker container
# 2) "/etc/sysconfig/Docker" file which controls the Docker service on the host.
# The configuration file in list item #2 is only present in CentOS & Red Hat Enteprise Linux (RHEL)
# so its path my vary depending on the Docker host's Linux distribution. This script has been
# tested against CentOS/RHEL 6.7+/7.0+ and SUSE Linux 12.0+.
# Variables
HARVEST_BUILDDIR="/root/docker/harvest"
PROXY_SERVER_ADDRESS="$1"
if [ ! $1 ]; then
# If a Proxy server URL is not specified exit with error
echo "Usage: $0 PROXY_SERVER_ADDRESS"
echo ""
echo "Example: $0 10.0.0.200:3128"
exit 1
else
# Add appropriate configuraiton options to ${HARVEST_BUILDDIR}/bashrc
echo "Adding the appropriate proxy configuration lines to ${HARVEST_BUILDDIR}/bashrc..."
sed -i "s/#PROXY_PLACEHOLDER1/export http_proxy=http:\/\/${PROXY_SERVER_ADDRESS}\nexport HTTP_PROXY=http:\/\/${PROXY_SERVER_ADDRESS}\nexport https_proxy=https:\/\/${PROXY_SERVER_ADDRESS}\nexport HTTPS_PROXY=https:\/\/${PROXY_SERVER_ADDRESS}/g" ${HARVEST_BUILDDIR}/bashrc
sed -i "s/#PROXY_PLACEHOLDER1/export http_proxy=http:\/\/${PROXY_SERVER_ADDRESS}\nexport HTTP_PROXY=http:\/\/${PROXY_SERVER_ADDRESS}\nexport https_proxy=https:\/\/${PROXY_SERVER_ADDRESS}\nexport HTTPS_PROXY=https:\/\/${PROXY_SERVER_ADDRESS}/g" ${HARVEST_BUILDDIR}/netapp_harvest_automated_setup
# Add appropriate configuraiton options to ${HARVEST_BUILDDIR}/Dockerfile
echo "Adding the appropriate proxy configuration lines to ${HARVEST_BUILDDIR}/Dockerfile..."
sed -i "s/#PROXY_PLACEHOLDER1/ENV http_proxy http:\/\/${PROXY_SERVER_ADDRESS}\nENV HTTP_PROXY http:\/\/${PROXY_SERVER_ADDRESS}\nENV https_proxy https:\/\/${PROXY_SERVER_ADDRESS}\nENV HTTPS_PROXY https:\/\/${PROXY_SERVER_ADDRESS}/g" ${HARVEST_BUILDDIR}/Dockerfile
sed -i "s/#PROXY_PLACEHOLDER2/ENV http_proxy \"\"\nENV HTTP_PROXY \"\"\nENV https_proxy \"\"\nENV HTTPS_PROXY \"\"/g" ${HARVEST_BUILDDIR}/Dockerfile
if [ -f /etc/SuSE-release ]; then
# SUSE-based Distribution
DOCKERCONF="/etc/sysconfig/docker"
echo "Adding the appropriate proxy configuration lines to ${DOCKERCONF}..."
echo -e "HTTP_PROXY=http:\/\/${PROXY_SERVER_ADDRESS}\nHTTPS_PROXY=https:\/\/${PROXY_SERVER_ADDRESS}/g" >> ${DOCKERCONF}
echo "Restarting the Docker service to apply the recent configuration change..."
/bin/systemctl restart docker
elif [ -f /etc/debian_version ]; then
# Debian-based Distribution
DOCKERCONF="/etc/defaults/docker.io"
echo "Adding the appropriate proxy configuration lines to ${DOCKERCONF}..."
echo -e "http_proxy=http:\/\/${PROXY_SERVER_ADDRESS}\nHTTP_PROXY=http:\/\/${PROXY_SERVER_ADDRESS}\nhttps_proxy=https:\/\/${PROXY_SERVER_ADDRESS}\nHTTPS_PROXY=https:\/\/${PROXY_SERVER_ADDRESS}/g" >> ${DOCKERCONF}
echo "Restarting the Docker service to apply the recent configuration change..."
if [ -f /bin/systemctl ]; then
/bin/systemctl restart docker
else
service docker.io restart
fi
elif [ -f /etc/redhat-release ]; then
# RHEL-based Distribution
DOCKERCONF="/etc/sysconfig/docker"
echo "Adding the appropriate proxy configuration lines to ${DOCKERCONF}..."
echo -e "HTTP_PROXY=http:\/\/${PROXY_SERVER_ADDRESS}\nHTTPS_PROXY=https:\/\/${PROXY_SERVER_ADDRESS}/g" >> ${DOCKERCONF}
echo "Restarting the Docker service to apply the recent configuration change..."
if [ -f /usr/bin/systemctl ]; then
/usr/bin/systemctl restart docker
else
/etc/init.d/docker restart
fi
fi
fi