Skip to content

Commit

Permalink
update: unlock add step
Browse files Browse the repository at this point in the history
  • Loading branch information
StasPlov committed May 30, 2024
1 parent 3180de9 commit 7d17190
Showing 1 changed file with 49 additions and 13 deletions.
62 changes: 49 additions & 13 deletions unlock.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,51 @@
#!/bin/bash

json_content='{
"registry-mirrors" : [
"https://mirror.gcr.io",
"https://daocloud.io",
"https://c.163.com",
"https://huecker.io",
"https://registry.docker-cn.com"
]
}'

echo "$json_content" | sudo tee /etc/docker/daemon.json > /dev/null

sudo systemctl restart docker
# 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

0 comments on commit 7d17190

Please sign in to comment.