-
Notifications
You must be signed in to change notification settings - Fork 111
/
docker.sh
88 lines (73 loc) · 2.09 KB
/
docker.sh
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/bash
# plugin to set "docker" proxy settings for ProxyMan
# privileges has to be set by the process which starts this script
CONF_FILE=`readlink -f /etc/systemd/system/docker.service.d/http-proxy.conf`
reload_docker_service() {
echo "reloading docker"
systemctl daemon-reload
systemctl restart docker.service
echo "done"
}
list_proxy() {
# inefficient way as the file is read twice.. think of some better way
echo -e "${bold}docker proxy settings: ${normal}"
if [ ! -e "$CONF_FILE" ]; then
echo -e "${red}None${normal}"
return
else
lines="$(cat $CONF_FILE | grep proxy -i | wc -l)"
if [ "$lines" -gt 0 ]; then
cat $CONF_FILE | grep proxy -i | sed -e "s/Environment=//g" -e "s/\_/\ /g"
else
echo -e "${red}None${normal}"
fi
fi
}
unset_proxy() {
if [ ! -e "$CONF_FILE" ]; then
return
fi
for PROTOTYPE in "HTTP" "HTTPS" "FTP" "RSYNC" "NO"; do
sed -i "/${PROTOTYPE}_PROXY\=/d" "$CONF_FILE"
done
}
set_proxy() {
unset_proxy
mkdir -p /etc/systemd/system/docker.service.d
if [[ ! -e "$CONF_FILE" ]]; then
echo -n "" > $CONF_FILE
echo "[Service]" >> $CONF_FILE
fi
local stmt=""
if [ "$use_auth" = "y" ]; then
stmt="${username}:${password}@"
fi
if [ "$USE_HTTP_PROXY_FOR_HTTPS" = "true" ]; then
echo 'Environment="HTTP_PROXY=http://'${stmt}${http_host}:${http_port}'/" "HTTPS_PROXY=http://'${stmt}${https_host}:${https_port}'/" "NO_PROXY='${no_proxy}'"'\
>> $CONF_FILE
else
echo 'Environment="HTTP_PROXY=http://'${stmt}${http_host}:${http_port}'/" "HTTPS_PROXY=https://'${stmt}${https_host}:${https_port}'/" "NO_PROXY='${no_proxy}'"'\
>> $CONF_FILE
fi
return
}
which docker &> /dev/null
if [ "$?" != 0 ]; then
exit
fi
if [ "$#" = 0 ]; then
exit
fi
what_to_do=$1
case $what_to_do in
set) set_proxy
reload_docker_service
;;
unset) unset_proxy
reload_docker_service
;;
list) list_proxy
;;
*)
;;
esac