1
0
mirror of https://github.com/mailcow/mailcow-dockerized.git synced 2025-12-19 12:51:29 +00:00

added error handling for blank daemon.json

This commit is contained in:
DerLinkman
2025-05-27 16:31:22 +02:00
parent 102226723e
commit 5ca10d1cde

View File

@@ -23,6 +23,13 @@ docker_daemon_edit(){
_has_kv() { grep -Eq "\"$1\"\s*:\s*$2" "$DOCKER_DAEMON_CONFIG" 2>/dev/null; } _has_kv() { grep -Eq "\"$1\"\s*:\s*$2" "$DOCKER_DAEMON_CONFIG" 2>/dev/null; }
if [[ -f "$DOCKER_DAEMON_CONFIG" ]]; then if [[ -f "$DOCKER_DAEMON_CONFIG" ]]; then
# reject empty or whitespace-only file immediately
if [[ ! -s "$DOCKER_DAEMON_CONFIG" ]] || ! grep -Eq '[{}]' "$DOCKER_DAEMON_CONFIG"; then
echo -e "${RED}ERROR: $DOCKER_DAEMON_CONFIG exists but is empty or contains no JSON braces please initialize it with valid JSON (e.g. {}).${NC}"
exit 1
fi
# Validate JSON if jq is present # Validate JSON if jq is present
if command -v jq &>/dev/null && ! jq empty "$DOCKER_DAEMON_CONFIG" &>/dev/null; then if command -v jq &>/dev/null && ! jq empty "$DOCKER_DAEMON_CONFIG" &>/dev/null; then
echo -e "${RED}ERROR: Invalid JSON in $DOCKER_DAEMON_CONFIG please correct manually.${NC}" echo -e "${RED}ERROR: Invalid JSON in $DOCKER_DAEMON_CONFIG please correct manually.${NC}"
@@ -64,7 +71,7 @@ docker_daemon_edit(){
exit 1 exit 1
fi fi
else else
echo "User declined Docker update please insert these changes manually:" echo -e "${YELLOW}User declined Docker update please insert these changes manually:${NC}"
echo "${MISSING[*]}" echo "${MISSING[*]}"
exit 1 exit 1
fi fi
@@ -98,7 +105,7 @@ EOF
} }
EOF EOF
fi fi
echo "Created $DOCKER_DAEMON_CONFIG with IPv6 settings." echo "${GREEN}Created $DOCKER_DAEMON_CONFIG with IPv6 settings.${NC}"
echo "Restarting Docker..." echo "Restarting Docker..."
(command -v systemctl &>/dev/null && systemctl restart docker) || service docker restart (command -v systemctl &>/dev/null && systemctl restart docker) || service docker restart
echo "Docker restarted." echo "Docker restarted."