Skip to content

Commit 4db1569

Browse files
committed
Squashed commit of the following:
commit 94c1a6c Author: DerLinkman <[email protected]> Date: Wed Sep 10 16:20:58 2025 +0200 scripts: ipv6_controller improvement + fix modules handling (#6722) * Fix subscript handling for modules * ipv6: detect case when link local is present * v6-controller: removed fixed-cidr for docker 28+
1 parent 7ce3b0f commit 4db1569

File tree

4 files changed

+145
-42
lines changed

4 files changed

+145
-42
lines changed

_modules/scripts/ipv6_controller.sh

Lines changed: 109 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,65 @@
55

66
# 1) Check if the host supports IPv6
77
get_ipv6_support() {
8-
if grep -qs '^1' /proc/sys/net/ipv6/conf/all/disable_ipv6 2>/dev/null \
9-
|| ! ip -6 route show default &>/dev/null; then
8+
# ---- helper: probe external IPv6 connectivity without DNS ----
9+
_probe_ipv6_connectivity() {
10+
# Use literal, always-on IPv6 echo responders (no DNS required)
11+
local PROBE_IPS=("2001:4860:4860::8888" "2606:4700:4700::1111")
12+
local ip rc=1
13+
14+
for ip in "${PROBE_IPS[@]}"; do
15+
if command -v ping6 &>/dev/null; then
16+
ping6 -c1 -W2 "$ip" &>/dev/null || ping6 -c1 -w2 "$ip" &>/dev/null
17+
rc=$?
18+
elif command -v ping &>/dev/null; then
19+
ping -6 -c1 -W2 "$ip" &>/dev/null || ping -6 -c1 -w2 "$ip" &>/dev/null
20+
rc=$?
21+
else
22+
rc=1
23+
fi
24+
[[ $rc -eq 0 ]] && return 0
25+
done
26+
return 1
27+
}
28+
29+
if [[ ! -f /proc/net/if_inet6 ]] || grep -qs '^1' /proc/sys/net/ipv6/conf/all/disable_ipv6 2>/dev/null; then
1030
DETECTED_IPV6=false
11-
echo -e "${YELLOW}IPv6 not detected on host – ${LIGHT_RED}disabling IPv6 support${YELLOW}.${NC}"
12-
else
13-
DETECTED_IPV6=true
14-
echo -e "IPv6 detected on host – ${LIGHT_GREEN}leaving IPv6 support enabled${YELLOW}.${NC}"
31+
echo -e "${YELLOW}IPv6 not detected on host – ${LIGHT_RED}IPv6 is administratively disabled${YELLOW}.${NC}"
32+
return
33+
fi
34+
35+
if ip -6 route show default 2>/dev/null | grep -qE '^default'; then
36+
echo -e "${YELLOW}Default IPv6 route found – testing external IPv6 connectivity...${NC}"
37+
if _probe_ipv6_connectivity; then
38+
DETECTED_IPV6=true
39+
echo -e "IPv6 detected on host – ${LIGHT_GREEN}leaving IPv6 support enabled${YELLOW}.${NC}"
40+
else
41+
DETECTED_IPV6=false
42+
echo -e "${YELLOW}Default IPv6 route present but external IPv6 connectivity failed – ${LIGHT_RED}disabling IPv6 support${YELLOW}.${NC}"
43+
fi
44+
return
45+
fi
46+
47+
if ip -6 addr show scope global 2>/dev/null | grep -q 'inet6'; then
48+
DETECTED_IPV6=false
49+
echo -e "${YELLOW}Global IPv6 address present but no default route – ${LIGHT_RED}disabling IPv6 support${YELLOW}.${NC}"
50+
return
1551
fi
52+
53+
if ip -6 addr show scope link 2>/dev/null | grep -q 'inet6'; then
54+
echo -e "${YELLOW}Only link-local IPv6 addresses found – testing external IPv6 connectivity...${NC}"
55+
if _probe_ipv6_connectivity; then
56+
DETECTED_IPV6=true
57+
echo -e "External IPv6 connectivity available – ${LIGHT_GREEN}leaving IPv6 support enabled${YELLOW}.${NC}"
58+
else
59+
DETECTED_IPV6=false
60+
echo -e "${YELLOW}Only link-local IPv6 present and no external connectivity – ${LIGHT_RED}disabling IPv6 support${YELLOW}.${NC}"
61+
fi
62+
return
63+
fi
64+
65+
DETECTED_IPV6=false
66+
echo -e "${YELLOW}IPv6 not detected on host – ${LIGHT_RED}disabling IPv6 support${YELLOW}.${NC}"
1667
}
1768

1869
# 2) Ensure Docker daemon.json has (or create) the required IPv6 settings
@@ -21,7 +72,7 @@ docker_daemon_edit(){
2172
DOCKER_MAJOR=$(docker version --format '{{.Server.Version}}' 2>/dev/null | cut -d. -f1)
2273
MISSING=()
2374

24-
_has_kv() { grep -Eq "\"$1\"\s*:\s*$2" "$DOCKER_DAEMON_CONFIG" 2>/dev/null; }
75+
_has_kv() { grep -Eq "\"$1\"[[:space:]]*:[[:space:]]*$2" "$DOCKER_DAEMON_CONFIG" 2>/dev/null; }
2576

2677
if [[ -f "$DOCKER_DAEMON_CONFIG" ]]; then
2778

@@ -38,12 +89,18 @@ docker_daemon_edit(){
3889
fi
3990

4091
# Gather missing keys
41-
! _has_kv ipv6 true && MISSING+=("ipv6: true")
42-
! grep -Eq '"fixed-cidr-v6"\s*:\s*".+"' "$DOCKER_DAEMON_CONFIG" \
43-
&& MISSING+=('fixed-cidr-v6: "fd00:dead:beef:c0::/80"')
44-
if [[ -n "$DOCKER_MAJOR" && "$DOCKER_MAJOR" -le 27 ]]; then
92+
! _has_kv ipv6 true && MISSING+=("ipv6: true")
93+
94+
# For Docker < 28, keep requiring fixed-cidr-v6 (default bridge needs it on old engines)
95+
if [[ -n "$DOCKER_MAJOR" && "$DOCKER_MAJOR" -lt 28 ]]; then
96+
! grep -Eq '"fixed-cidr-v6"[[:space:]]*:[[:space:]]*".+"' "$DOCKER_DAEMON_CONFIG" \
97+
&& MISSING+=('fixed-cidr-v6: "fd00:dead:beef:c0::/80"')
98+
fi
99+
100+
# For Docker < 27, ip6tables needed and was tied to experimental in older releases
101+
if [[ -n "$DOCKER_MAJOR" && "$DOCKER_MAJOR" -lt 27 ]]; then
45102
_has_kv ipv6 true && ! _has_kv ip6tables true && MISSING+=("ip6tables: true")
46-
! _has_kv experimental true && MISSING+=("experimental: true")
103+
! _has_kv experimental true && MISSING+=("experimental: true")
47104
fi
48105

49106
# Fix if needed
@@ -60,9 +117,19 @@ docker_daemon_edit(){
60117
cp "$DOCKER_DAEMON_CONFIG" "${DOCKER_DAEMON_CONFIG}.bak"
61118
if command -v jq &>/dev/null; then
62119
TMP=$(mktemp)
63-
JQ_FILTER='.ipv6 = true | .["fixed-cidr-v6"] = "fd00:dead:beef:c0::/80"'
64-
[[ "$DOCKER_MAJOR" && "$DOCKER_MAJOR" -lt 27 ]] \
65-
&& JQ_FILTER+=' | .ip6tables = true | .experimental = true'
120+
# Base filter: ensure ipv6 = true
121+
JQ_FILTER='.ipv6 = true'
122+
123+
# Add fixed-cidr-v6 only for Docker < 28
124+
if [[ -n "$DOCKER_MAJOR" && "$DOCKER_MAJOR" -lt 28 ]]; then
125+
JQ_FILTER+=' | .["fixed-cidr-v6"] = (.["fixed-cidr-v6"] // "fd00:dead:beef:c0::/80")'
126+
fi
127+
128+
# Add ip6tables/experimental only for Docker < 27
129+
if [[ -n "$DOCKER_MAJOR" && "$DOCKER_MAJOR" -lt 27 ]]; then
130+
JQ_FILTER+=' | .ip6tables = true | .experimental = true'
131+
fi
132+
66133
jq "$JQ_FILTER" "$DOCKER_DAEMON_CONFIG" >"$TMP" && mv "$TMP" "$DOCKER_DAEMON_CONFIG"
67134
echo -e "${LIGHT_GREEN}daemon.json updated. Restarting Docker...${NC}"
68135
(command -v systemctl &>/dev/null && systemctl restart docker) || service docker restart
@@ -97,12 +164,19 @@ docker_daemon_edit(){
97164
"experimental": true
98165
}
99166
EOF
100-
else
167+
elif [[ -n "$DOCKER_MAJOR" && "$DOCKER_MAJOR" -lt 28 ]]; then
101168
cat > "$DOCKER_DAEMON_CONFIG" <<EOF
102169
{
103170
"ipv6": true,
104171
"fixed-cidr-v6": "fd00:dead:beef:c0::/80"
105172
}
173+
EOF
174+
else
175+
# Docker 28+: ipv6 works without fixed-cidr-v6
176+
cat > "$DOCKER_DAEMON_CONFIG" <<EOF
177+
{
178+
"ipv6": true
179+
}
106180
EOF
107181
fi
108182
echo -e "${GREEN}Created $DOCKER_DAEMON_CONFIG with IPv6 settings.${NC}"
@@ -122,7 +196,7 @@ configure_ipv6() {
122196
# detect manual override if mailcow.conf is present
123197
if [[ -n "$MAILCOW_CONF" && -f "$MAILCOW_CONF" ]] && grep -q '^ENABLE_IPV6=' "$MAILCOW_CONF"; then
124198
MANUAL_SETTING=$(grep '^ENABLE_IPV6=' "$MAILCOW_CONF" | cut -d= -f2)
125-
elif [[ -z "$MAILCOW_CONF" ]] && [[ ! -z "${ENABLE_IPV6:-}" ]]; then
199+
elif [[ -z "$MAILCOW_CONF" ]] && [[ -n "${ENABLE_IPV6:-}" ]]; then
126200
MANUAL_SETTING="$ENABLE_IPV6"
127201
else
128202
MANUAL_SETTING=""
@@ -131,38 +205,34 @@ configure_ipv6() {
131205
get_ipv6_support
132206

133207
# if user manually set it, check for mismatch
134-
if [[ -n "$MANUAL_SETTING" ]]; then
135-
if [[ "$MANUAL_SETTING" == "false" && "$DETECTED_IPV6" == "true" ]]; then
136-
echo -e "${RED}ERROR: You have ENABLE_IPV6=false but your host and Docker support IPv6.${NC}"
137-
echo -e "${RED}This can create an open relay. Please set ENABLE_IPV6=true in your mailcow.conf and re-run.${NC}"
138-
exit 1
139-
elif [[ "$MANUAL_SETTING" == "true" && "$DETECTED_IPV6" == "false" ]]; then
140-
echo -e "${RED}ERROR: You have ENABLE_IPV6=true but your host does not support IPv6.${NC}"
141-
echo -e "${RED}Please disable or fix your host/Docker IPv6 support, or set ENABLE_IPV6=false.${NC}"
142-
exit 1
208+
if [[ "$DETECTED_IPV6" != "true" ]]; then
209+
if [[ -n "$MAILCOW_CONF" && -f "$MAILCOW_CONF" ]]; then
210+
if grep -q '^ENABLE_IPV6=' "$MAILCOW_CONF"; then
211+
sed -i 's/^ENABLE_IPV6=.*/ENABLE_IPV6=false/' "$MAILCOW_CONF"
212+
else
213+
echo "ENABLE_IPV6=false" >> "$MAILCOW_CONF"
214+
fi
143215
else
144-
return
216+
export IPV6_BOOL=false
145217
fi
146-
fi
147-
148-
# no manual override: proceed to set or export
149-
if [[ "$DETECTED_IPV6" == "true" ]]; then
150-
docker_daemon_edit
151-
else
152218
echo "Skipping Docker IPv6 configuration because host does not support IPv6."
219+
echo "Make sure to check if your docker daemon.json does not include \"enable_ipv6\": true if you do not want IPv6."
220+
echo "IPv6 configuration complete: ENABLE_IPV6=false"
221+
sleep 2
222+
return
153223
fi
154224

155-
# now write into mailcow.conf or export
225+
docker_daemon_edit
226+
156227
if [[ -n "$MAILCOW_CONF" && -f "$MAILCOW_CONF" ]]; then
157-
LINE="ENABLE_IPV6=$DETECTED_IPV6"
158228
if grep -q '^ENABLE_IPV6=' "$MAILCOW_CONF"; then
159-
sed -i "s/^ENABLE_IPV6=.*/$LINE/" "$MAILCOW_CONF"
229+
sed -i 's/^ENABLE_IPV6=.*/ENABLE_IPV6=true/' "$MAILCOW_CONF"
160230
else
161-
echo "$LINE" >> "$MAILCOW_CONF"
231+
echo "ENABLE_IPV6=true" >> "$MAILCOW_CONF"
162232
fi
163233
else
164-
export IPV6_BOOL="$DETECTED_IPV6"
234+
export IPV6_BOOL=true
165235
fi
166236

167-
echo "IPv6 configuration complete: ENABLE_IPV6=$DETECTED_IPV6"
237+
echo "IPv6 configuration complete: ENABLE_IPV6=true"
168238
}

generate_config.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
#!/usr/bin/env bash
22

3+
# Ensure the script is run from the directory that contains a link of .env
4+
# Resolve the directory this script lives in for consistent behavior when invoked from elsewhere
5+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" >/dev/null 2>&1 && pwd)"
6+
7+
# Ensure script is executed in the mailcow installation directory by checking for a .env symlink that points to mailcow.conf
8+
if [ ! -L "${PWD}/.env" ]; then
9+
echo -e "\e[33mPlease run this script from the mailcow installation directory.\e[0m"
10+
echo -e " \e[36mcd /path/to/mailcow && ./generate_config.sh\e[0m"
11+
exit 1
12+
fi
13+
14+
# Verify the .env symlink points to a mailcow.conf file
15+
env_target="$(readlink -f "${PWD}/.env" 2>/dev/null || true)"
16+
if [ -z "$env_target" ] || [ "$(basename "$env_target")" != "mailcow.conf" ]; then
17+
echo -e "\e[31mThe found .env symlink does not point to a mailcow.conf file.\e[0m"
18+
echo -e "\e[33mPlease create a symbolic link .env -> mailcow.conf inside the mailcow directory and run this script there.\e[0m"
19+
echo -e "\e[33mNote: 'ln -s mailcow.conf .env' will create the symlink even if mailcow.conf does not yet exist.\e[0m"
20+
echo -e " \e[36mcd /path/to/mailcow && ln -s mailcow.conf .env && ./generate_config.sh\e[0m"
21+
exit 1
22+
fi
23+
324
# Load mailcow Generic Scripts
425
source _modules/scripts/core.sh
526
source _modules/scripts/ipv6_controller.sh

helper-scripts/_cold-standby.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ if ! ssh -o StrictHostKeyChecking=no \
293293
-i "${REMOTE_SSH_KEY}" \
294294
${REMOTE_SSH_HOST} \
295295
-p ${REMOTE_SSH_PORT} \
296-
${SCRIPT_DIR}/../update.sh -f --gc ; then
296+
"cd \"${SCRIPT_DIR}/../\" && ./update.sh -f --gc" ; then
297297
>&2 echo -e "\e[31m[ERR]\e[0m - Could not cleanup old images on remote"
298298
fi
299299

update.sh

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,20 @@
33
############## Begin Function Section ##############
44

55
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
6+
MAILCOW_CONF="${SCRIPT_DIR}/mailcow.conf"
7+
8+
# Ensure the script is run from the directory that contains mailcow.conf
9+
if [ ! -f "${PWD}/mailcow.conf" ]; then
10+
if [ -f "${SCRIPT_DIR}/mailcow.conf" ]; then
11+
echo -e "\e[33mPlease run this script directly from the mailcow installation directory:\e[0m"
12+
echo -e " \e[36mcd ${SCRIPT_DIR} && ./update.sh\e[0m"
13+
exit 1
14+
else
15+
echo -e "\e[31mmailcow.conf not found in current directory or script directory (\e[36m${SCRIPT_DIR}\e[31m).\e[0m"
16+
echo -e "\e[33mRun this script directly from your mailcow installation directory.\e[0m"
17+
exit 1
18+
fi
19+
fi
620
BRANCH="$(cd "${SCRIPT_DIR}" && git rev-parse --abbrev-ref HEAD)"
721

822
MODULE_DIR="${SCRIPT_DIR}/_modules"
@@ -27,8 +41,6 @@ if [ "$(id -u)" -ne "0" ]; then
2741
exit 1
2842
fi
2943

30-
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
31-
3244
# Run pre-update-hook
3345
if [ -f "${SCRIPT_DIR}/pre_update_hook.sh" ]; then
3446
bash "${SCRIPT_DIR}/pre_update_hook.sh"

0 commit comments

Comments
 (0)