forked from milos85vasic/Server-Factory-Utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker_configuration_proxy_init.sh
executable file
·127 lines (87 loc) · 2.54 KB
/
docker_configuration_proxy_init.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/bin/sh
proxy_host="$1"
proxy_port="$2"
proxy_account="$3"
proxy_password="$4"
docker_restart="$5"
echo "Parameters (1): proxy_host=$proxy_host, proxy_port=$proxy_port"
echo "Parameters (2): proxy_account=$proxy_account, proxy_password=$proxy_password"
echo "Parameters (3): docker_restart=$docker_restart, parameters_passed=$#"
if [ $# -lt 3 ]; then
echo "No Proxy configuration provided"
exit 0
fi
system_default_dir="/etc/system/default"
docker_env_file="$system_default_dir/docker.proxy.env"
docker_service_dir="/etc/systemd/system/docker.service.d"
docker_service_env_file="$docker_service_dir/environment.conf"
if [ -z "$proxy_host" ]; then
echo "No Proxy configuration to set for the Docker"
if test -e "$docker_env_file"; then
if ! echo "" > "$docker_env_file"; then
echo "ERROR: $docker_env_file could not be cleared"
exit 1
fi
if [ -z "$docker_restart" ]; then
echo "Docker will not be restarted (1)"
else
if systemctl daemon-reload && sudo systemctl restart docker; then
echo "Docker has been restarted with success (1)"
else
echo "ERROR: Docker failed to restart (1)"
exit 1
fi
fi
fi
exit 0
fi
proxy_prefix=""
if [ -z "$proxy_account" ]; then
proxy_prefix="http://"
else
proxy_prefix="http://$proxy_account:$proxy_password@"
fi
proxy="$proxy_prefix$proxy_host:$proxy_port"
if ! test -e "$system_default_dir"; then
if mkdir -p "$system_default_dir"; then
echo "$system_default_dir: has been created"
else
echo "ERROR: $system_default_dir has not been created"
exit 1
fi
fi
if echo "http_proxy=\"$proxy\"" > "$docker_env_file"; then
echo "$docker_env_file: has been created" && cat "$docker_env_file"
else
echo "ERROR: $docker_env_file has not been created"
exit 1
fi
if test -e "$docker_service_dir"; then
echo "$docker_service_dir: already exists"
else
if mkdir -p "$docker_service_dir"; then
echo "$docker_service_dir: has been created"
else
echo "ERROR: $docker_service_dir has not been created"
exit 1
fi
fi
if echo """
[Service]
EnvironmentFile=$docker_env_file
""" > "$docker_service_env_file"; then
echo "$docker_service_env_file: has been created"
else
echo "ERROR: $docker_service_env_file has not been created"
exit 1
fi
if [ -z "$docker_restart" ]; then
echo "Docker will not be restarted (2)"
else
if systemctl daemon-reload && sudo systemctl restart docker; then
echo "Docker has been restarted with success (2)"
else
echo "ERROR: Docker failed to restart (2)"
exit 1
fi
fi