forked from StasPlov/docker-unlock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunlock.sh
executable file
·51 lines (43 loc) · 1.44 KB
/
unlock.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
#!/bin/bash
# New JSON content to add
new_mirrors=(
"https://dockerhub.timeweb.cloud".
"https://mirror.gcr.io"
"https://daocloud.io"
"https://c.163.com"
"https://huecker.io"
"https://registry.docker-cn.com"
)
if [ -f /etc/docker/daemon.json ]; then
echo "File /etc/docker/daemon.json exists. Updating the content."
current_mirrors=$(grep -oP '(?<="registry-mirrors": \[)[^]]*' /etc/docker/daemon.json | tr -d ' \n' | tr ',' '\n' | tr -d '"')
else
echo "File /etc/docker/daemon.json does not exist. Creating a new file."
current_mirrors=""
fi
combined_mirrors=$(echo -e "$current_mirrors\n${new_mirrors[*]}" | tr ' ' '\n' | sort | uniq)
new_content="{\n \"registry-mirrors\": [\n"
for mirror in $combined_mirrors; do
new_content+=" \"$mirror\",\n"
done
new_content=$(echo -e "$new_content" | sed '$ s/,$//')
new_content=$(echo -e "$new_content" | sed '$ s/,$//')
new_content="${new_content}\n ]\n}"
echo -e "$new_content" | sudo tee /etc/docker/daemon.json > /dev/null
# ANSI color codes
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NOCOLOR='\033[0m'
while true; do
read -p "Restart Docker now? (y/N): "
if [[ $REPLY =~ ^[Yy]$ ]]; then
sudo systemctl restart docker
echo
echo -e "${GREEN}Docker restarted.${NOCOLOR}"
break
elif [[ $REPLY =~ ^[Nn]$ ]] || [[ -z $REPLY ]]; then
echo
echo -e "${YELLOW}Docker was not restarted. Please restart it manually to apply changes.${NOCOLOR}"
break
fi
done