Browse Source

rewrite to scripts after testing (improved error handling)

DerLinkman 3 months ago
parent
commit
73929db796

+ 0 - 108
_modules/ipv6_controller.sh

@@ -1,108 +0,0 @@
-#!/usr/bin/env bash
-# _modules/ipv6_controller.sh
-
-# 1) Check if the host supports IPv6
-get_ipv6_support() {
-  if grep -qs '^1' /proc/sys/net/ipv6/conf/all/disable_ipv6 2>/dev/null \
-    || ! ip -6 route show default &>/dev/null; then
-    ENABLE_IPV6_LINE="ENABLE_IPV6=false"
-    echo "IPv6 not detected on host – disabling IPv6 support."
-  else
-    ENABLE_IPV6_LINE="ENABLE_IPV6=true"
-    echo "IPv6 detected on host – leaving IPv6 support enabled."
-  fi
-}
-
-# 2) Ensure Docker daemon.json has the required IPv6 settings
-docker_daemon_edit(){
-  DOCKER_DAEMON_CONFIG="/etc/docker/daemon.json"
-  MISSING=()
-
-  # helper: check for a key/value in the JSON
-  _has_kv() { grep -Eq "\"$1\"\s*:\s*$2" "$DOCKER_DAEMON_CONFIG" 2>/dev/null; }
-
-  if [[ -f "$DOCKER_DAEMON_CONFIG" ]]; then
-    # Validate JSON syntax if jq is available
-    if command -v jq &>/dev/null; then
-      if ! jq empty "$DOCKER_DAEMON_CONFIG" &>/dev/null; then
-        echo "ERROR: Invalid JSON in $DOCKER_DAEMON_CONFIG – please correct it manually."
-        exit 1
-      fi
-    else
-      echo "WARNING: jq not found – JSON syntax not validated."
-    fi
-
-    # Check required settings
-    ! _has_kv ipv6 true       && MISSING+=("ipv6: true")
-    ! grep -Eq '"fixed-cidr-v6"\s*:\s*".+"' "$DOCKER_DAEMON_CONFIG" \
-                              && MISSING+=('fixed-cidr-v6: "fd00:dead:beef:c0::/80"')
-
-    # Determine Docker major version
-    DOCKER_MAJOR=$(docker version --format '{{.Server.Version}}' 2>/dev/null | cut -d. -f1)
-    if [[ -n "$DOCKER_MAJOR" && "$DOCKER_MAJOR" -lt 27 ]]; then
-      _has_kv ipv6 true && ! _has_kv ip6tables true \
-                              && MISSING+=("ip6tables: true")
-      ! _has_kv experimental true \
-                              && MISSING+=("experimental: true")
-    else
-      echo "Docker ≥27 detected – skipping ip6tables/experimental checks."
-    fi
-
-    # If anything is missing, offer to auto-fix
-    if ((${#MISSING[@]}>0)); then
-      echo "Your daemon.json is missing: ${MISSING[*]}"
-      read -p "Would you like to update $DOCKER_DAEMON_CONFIG now? [Y/n] " ans
-      ans=${ans:-Y}
-      if [[ $ans =~ ^[Yy]$ ]]; then
-        cp "$DOCKER_DAEMON_CONFIG" "${DOCKER_DAEMON_CONFIG}.bak"
-        if command -v jq &>/dev/null; then
-          TMP=$(mktemp)
-          JQ_FILTER='.ipv6 = true | .["fixed-cidr-v6"] = "fd00:dead:beef:c0::/80"'
-          [[ "$DOCKER_MAJOR" && "$DOCKER_MAJOR" -lt 27 ]] \
-            && JQ_FILTER+=' | .ip6tables = true | .experimental = true'
-          jq "$JQ_FILTER" "$DOCKER_DAEMON_CONFIG" >"$TMP" && mv "$TMP" "$DOCKER_DAEMON_CONFIG"
-          echo "daemon.json updated. Restarting Docker..."
-          (command -v systemctl &>/dev/null && systemctl restart docker) \
-            || service docker restart
-          echo "Docker restarted. Please rerun this script."
-          exit 1
-        else
-          echo "Please install jq or manually update daemon.json and restart Docker."
-          exit 1
-        fi
-      else
-        ENABLE_IPV6_LINE="ENABLE_IPV6=false"
-        echo "User declined update – disabling IPv6 support."
-      fi
-    fi
-  else
-    echo "WARNING: $DOCKER_DAEMON_CONFIG not found – skipping Docker config check."
-  fi
-}
-
-# 3) Wrapper to integrate into both generate_config.sh and update.sh
-configure_ipv6() {
-  get_ipv6_support
-
-  # Only edit Docker config if IPv6 is enabled on host
-  if [[ "$ENABLE_IPV6_LINE" == "ENABLE_IPV6=true" ]]; then
-    docker_daemon_edit
-  else
-    echo "Skipping Docker IPv6 configuration because host does not support IPv6."
-  fi
-
-  # Write ENABLE_IPV6 into mailcow.conf (generate_config.sh) or export in current shell (update.sh)
-  if [[ -n "$MAILCOW_CONF" && -f "$MAILCOW_CONF" ]]; then
-    # generate_config.sh: append or replace in mailcow.conf
-    if grep -q '^ENABLE_IPV6=' "$MAILCOW_CONF"; then
-      sed -i "s/^ENABLE_IPV6=.*/$ENABLE_IPV6_LINE/" "$MAILCOW_CONF"
-    else
-      echo "$ENABLE_IPV6_LINE" >> "$MAILCOW_CONF"
-    fi
-  else
-    # update.sh: export into the running environment
-    export "$ENABLE_IPV6_LINE"
-  fi
-
-  echo "IPv6 configuration complete: $ENABLE_IPV6_LINE"
-}

+ 0 - 59
_modules/migrate_options.sh

@@ -1,59 +0,0 @@
-#!/bin/bash
-
-migrate_solr_config_options() {
-
-  sed -i --follow-symlinks '$a\' mailcow.conf
-
-  if grep -q "SOLR_HEAP" mailcow.conf; then
-    echo "Removing SOLR_HEAP in mailcow.conf"
-    sed -i '/# Solr heap size in MB\b/d' mailcow.conf
-    sed -i '/# Solr is a prone to run\b/d' mailcow.conf
-    sed -i '/SOLR_HEAP\b/d' mailcow.conf
-  fi
-
-  if grep -q "SKIP_SOLR" mailcow.conf; then
-    echo "Removing SKIP_SOLR in mailcow.conf"
-    sed -i '/\bSkip Solr on low-memory\b/d' mailcow.conf
-    sed -i '/\bSolr is disabled by default\b/d' mailcow.conf
-    sed -i '/\bDisable Solr or\b/d' mailcow.conf
-    sed -i '/\bSKIP_SOLR\b/d' mailcow.conf
-  fi
-
-  if grep -q "SOLR_PORT" mailcow.conf; then
-    echo "Removing SOLR_PORT in mailcow.conf"
-    sed -i '/\bSOLR_PORT\b/d' mailcow.conf
-  fi
-
-  if grep -q "FLATCURVE_EXPERIMENTAL" mailcow.conf; then
-    echo "Removing FLATCURVE_EXPERIMENTAL in mailcow.conf"
-    sed -i '/\bFLATCURVE_EXPERIMENTAL\b/d' mailcow.conf
-  fi
-
-  solr_volume=$(docker volume ls -qf name=^${COMPOSE_PROJECT_NAME}_solr-vol-1)
-  if [[ -n $solr_volume ]]; then
-    echo -e "\e[34mSolr has been replaced within mailcow since 2025-01.\nThe volume $solr_volume is unused.\e[0m"
-    sleep 1
-    if [ ! "$FORCE" ]; then
-      read -r -p "Remove $solr_volume? [y/N] " response
-      if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]; then
-        echo -e "\e[33mRemoving $solr_volume...\e[0m"
-        docker volume rm $solr_volume || echo -e "\e[31mFailed to remove. Remove it manually!\e[0m"
-        echo -e "\e[32mSuccessfully removed $solr_volume!\e[0m"
-      else
-        echo -e "Not removing $solr_volume. Run \`docker volume rm $solr_volume\` manually if needed."
-      fi
-    else
-      echo -e "\e[33mForce removing $solr_volume...\e[0m"
-      docker volume rm $solr_volume || echo -e "\e[31mFailed to remove. Remove it manually!\e[0m"
-      echo -e "\e[32mSuccessfully removed $solr_volume!\e[0m"
-    fi
-  fi
-
-  # Delete old fts.conf before forced switch to flatcurve to ensure update is working properly
-  FTS_CONF_PATH="${SCRIPT_DIR}/data/conf/dovecot/conf.d/fts.conf"
-  if [[ -f "$FTS_CONF_PATH" ]]; then
-    if grep -q "Autogenerated by mailcow" "$FTS_CONF_PATH"; then
-      rm -rf $FTS_CONF_PATH
-    fi
-  fi
-}

+ 13 - 3
_modules/core.sh → _modules/scripts/core.sh

@@ -1,5 +1,15 @@
 #!/bin/bash
 
+# ANSI color for red errors
+RED='\e[31m'
+GREEN='\e[32m'
+YELLOW='\e[33m'
+BLUE='\e[34m'
+MAGENTA='\e[35m'
+LIGHT_RED='\e[91m'
+LIGHT_GREEN='\e[92m'
+NC='\e[0m'
+
 caller="${BASH_SOURCE[1]##*/}"
 
 get_installed_tools(){
@@ -7,10 +17,10 @@ get_installed_tools(){
         if [[ -z $(which ${bin}) ]]; then echo "Cannot find ${bin}, exiting..."; exit 1; fi
     done
 
-    if grep --help 2>&1 | head -n 1 | grep -q -i "busybox"; then echo "BusyBox grep detected, please install gnu grep, \"apk add --no-cache --upgrade grep\""; exit 1; fi
+    if grep --help 2>&1 | head -n 1 | grep -q -i "busybox"; then echo -e "${LIGHT_RED}BusyBox grep detected, please install gnu grep, \"apk add --no-cache --upgrade grep\"${NC}"; exit 1; fi
     # This will also cover sort
-    if cp --help 2>&1 | head -n 1 | grep -q -i "busybox"; then echo "BusyBox cp detected, please install coreutils, \"apk add --no-cache --upgrade coreutils\""; exit 1; fi
-    if sed --help 2>&1 | head -n 1 | grep -q -i "busybox"; then echo "BusyBox sed detected, please install gnu sed, \"apk add --no-cache --upgrade sed\""; exit 1; fi
+    if cp --help 2>&1 | head -n 1 | grep -q -i "busybox"; then echo -e "${LIGHT_RED}BusyBox cp detected, please install coreutils, \"apk add --no-cache --upgrade coreutils\"${NC}"; exit 1; fi
+    if sed --help 2>&1 | head -n 1 | grep -q -i "busybox"; then echo -e "${LIGHT_RED}BusyBox sed detected, please install gnu sed, \"apk add --no-cache --upgrade sed\"${NC}"; exit 1; fi
 }
 
 get_docker_version(){

+ 160 - 0
_modules/scripts/ipv6_controller.sh

@@ -0,0 +1,160 @@
+#!/usr/bin/env bash
+# _modules/scripts/ipv6_controller.sh
+
+# 1) Check if the host supports IPv6
+get_ipv6_support() {
+  if grep -qs '^1' /proc/sys/net/ipv6/conf/all/disable_ipv6 2>/dev/null \
+    || ! ip -6 route show default &>/dev/null; then
+    DETECTED_IPV6=false
+    echo -e "${YELLOW}IPv6 not detected on host – ${LIGHT_RED}disabling IPv6 support${YELLOW}.${NC}"
+  else
+    DETECTED_IPV6=true
+    echo -e "IPv6 detected on host – ${LIGHT_GREEN}leaving IPv6 support enabled${YELLOW}.${NC}"
+  fi
+}
+
+# 2) Ensure Docker daemon.json has (or create) the required IPv6 settings
+docker_daemon_edit(){
+  DOCKER_DAEMON_CONFIG="/etc/docker/daemon.json"
+  MISSING=()
+
+  _has_kv() { grep -Eq "\"$1\"\s*:\s*$2" "$DOCKER_DAEMON_CONFIG" 2>/dev/null; }
+
+  if [[ -f "$DOCKER_DAEMON_CONFIG" ]]; then
+    # Validate JSON if jq is present
+    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}"
+      exit 1
+    fi
+
+    # Gather missing keys
+    ! _has_kv ipv6 true       && MISSING+=("ipv6: true")
+    ! grep -Eq '"fixed-cidr-v6"\s*:\s*".+"' "$DOCKER_DAEMON_CONFIG" \
+                              && MISSING+=('fixed-cidr-v6: "fd00:dead:beef:c0::/80"')
+    if [[ -n "$docker_version" && "$docker_version" -lt 27 ]]; then
+      _has_kv ipv6 true && ! _has_kv ip6tables true && MISSING+=("ip6tables: true")
+      ! _has_kv experimental true                 && MISSING+=("experimental: true")
+    fi
+
+    # Fix if needed
+    if ((${#MISSING[@]}>0)); then
+      echo -e "${MAGENTA}Your daemon.json is missing: ${YELLOW}${MISSING[*]}${NC}"
+      if [[ -n "$FORCE" ]]; then
+        ans=Y
+      else
+        read -p "Would you like to update $DOCKER_DAEMON_CONFIG now? [Y/n] " ans
+        ans=${ans:-Y}
+      fi
+
+      if [[ $ans =~ ^[Yy]$ ]]; then
+        cp "$DOCKER_DAEMON_CONFIG" "${DOCKER_DAEMON_CONFIG}.bak"
+        if command -v jq &>/dev/null; then
+          TMP=$(mktemp)
+          JQ_FILTER='.ipv6 = true | .["fixed-cidr-v6"] = "fd00:dead:beef:c0::/80"'
+          [[ "$DOCKER_MAJOR" && "$DOCKER_MAJOR" -lt 27 ]] \
+            && JQ_FILTER+=' | .ip6tables = true | .experimental = true'
+          jq "$JQ_FILTER" "$DOCKER_DAEMON_CONFIG" >"$TMP" && mv "$TMP" "$DOCKER_DAEMON_CONFIG"
+          echo -e "${LIGHT_GREEN}daemon.json updated. Restarting Docker...${NC}"
+          (command -v systemctl &>/dev/null && systemctl restart docker) || service docker restart
+          echo -e "${YELLOW}Docker restarted.${NC}"
+        else
+          echo -e "${RED}Please install jq or manually update daemon.json and restart Docker.${NC}"
+          exit 1
+        fi
+      else
+        echo "User declined Docker update – please insert these changes manually:"
+        echo "${MISSING[*]}"
+        exit 1
+      fi
+    fi
+
+  else
+    # Create new daemon.json if missing
+    if [[ -n "$FORCE" ]]; then
+      ans=Y
+    else
+      read -p "$DOCKER_DAEMON_CONFIG not found. Create it with IPv6 settings? [Y/n] " ans
+      ans=${ans:-Y}
+    fi
+
+    if [[ $ans =~ ^[Yy]$ ]]; then
+      DOCKER_MAJOR=$(docker version --format '{{.Server.Version}}' 2>/dev/null | cut -d. -f1)
+      if [[ -n "$DOCKER_MAJOR" && "$DOCKER_MAJOR" -lt 27 ]]; then
+        cat > "$DOCKER_DAEMON_CONFIG" <<EOF
+{
+  "ipv6": true,
+  "fixed-cidr-v6": "fd00:dead:beef:c0::/80",
+  "ip6tables": true,
+  "experimental": true
+}
+EOF
+      else
+        cat > "$DOCKER_DAEMON_CONFIG" <<EOF
+{
+  "ipv6": true,
+  "fixed-cidr-v6": "fd00:dead:beef:c0::/80"
+}
+EOF
+      fi
+      echo "Created $DOCKER_DAEMON_CONFIG with IPv6 settings."
+      echo "Restarting Docker..."
+      (command -v systemctl &>/dev/null && systemctl restart docker) || service docker restart
+      echo "Docker restarted."
+    else
+      echo "User declined to create daemon.json – please manually merge the docker daemon with these configs:"
+      echo "${MISSING[*]}"
+      exit 1
+    fi
+  fi
+}
+
+# 3) Main wrapper for generate_config.sh and update.sh
+configure_ipv6() {
+  # detect manual override if mailcow.conf is present
+  if [[ -n "$MAILCOW_CONF" && -f "$MAILCOW_CONF" ]] && grep -q '^ENABLE_IPV6=' "$MAILCOW_CONF"; then
+    MANUAL_SETTING=$(grep '^ENABLE_IPV6=' "$MAILCOW_CONF" | cut -d= -f2)
+  elif [[ -z "$MAILCOW_CONF" ]] && [[ ! -z "${ENABLE_IPV6:-}" ]]; then
+    MANUAL_SETTING="$ENABLE_IPV6"
+  else
+    MANUAL_SETTING=""
+  fi
+
+  get_ipv6_support
+
+  # if user manually set it, check for mismatch
+  if [[ -n "$MANUAL_SETTING" ]]; then
+    if [[ "$MANUAL_SETTING" == "false" && "$DETECTED_IPV6" == "true" ]]; then
+      echo -e "${RED}ERROR: You have ENABLE_IPV6=false but your host and Docker support IPv6.${NC}"
+      echo -e "${RED}This can create an open relay. Please set ENABLE_IPV6=true in your mailcow.conf and re-run.${NC}"
+      exit 1
+    elif [[ "$MANUAL_SETTING" == "true" && "$DETECTED_IPV6" == "false" ]]; then
+      echo -e "${RED}ERROR: You have ENABLE_IPV6=true but your host does not support IPv6.${NC}"
+      echo -e "${RED}Please disable or fix your host/Docker IPv6 support, or set ENABLE_IPV6=false.${NC}"
+      exit 1
+    else
+      echo "Manual ENABLE_IPV6=$MANUAL_SETTING detected and matches system status—no changes applied."
+      return
+    fi
+  fi
+
+  # no manual override: proceed to set or export
+  if [[ "$DETECTED_IPV6" == "true" ]]; then
+    docker_daemon_edit
+  else
+    echo "Skipping Docker IPv6 configuration because host does not support IPv6."
+  fi
+
+  # now write into mailcow.conf or export
+  if [[ -n "$MAILCOW_CONF" && -f "$MAILCOW_CONF" ]]; then
+    LINE="ENABLE_IPV6=$DETECTED_IPV6"
+    if grep -q '^ENABLE_IPV6=' "$MAILCOW_CONF"; then
+      sed -i "s/^ENABLE_IPV6=.*/$LINE/" "$MAILCOW_CONF"
+    else
+      echo "$LINE" >> "$MAILCOW_CONF"
+    fi
+  else
+    export IPV6_BOOL="$DETECTED_IPV6"
+  fi
+
+  echo "IPv6 configuration complete: ENABLE_IPV6=$DETECTED_IPV6"
+}

+ 82 - 0
_modules/scripts/migrate_options.sh

@@ -0,0 +1,82 @@
+#!/bin/bash
+
+migrate_config_options() {
+
+  sed -i --follow-symlinks '$a\' mailcow.conf
+
+  KEYS=(
+    SOLR_HEAP
+    SKIP_SOLR
+    SOLR_PORT
+    FLATCURVE_EXPERIMENTAL
+    DISABLE_IPv6
+  )
+
+  for key in "${KEYS[@]}"; do
+    if grep -q "${key}" mailcow.conf; then
+      case "${key}" in
+        SOLR_HEAP)
+          echo "Removing ${key} in mailcow.conf"
+          sed -i '/# Solr heap size in MB\b/d' mailcow.conf
+          sed -i '/# Solr is a prone to run\b/d' mailcow.conf
+          sed -i '/SOLR_HEAP\b/d' mailcow.conf
+          ;;
+        SKIP_SOLR)
+          echo "Removing ${key} in mailcow.conf"
+          sed -i '/\bSkip Solr on low-memory\b/d' mailcow.conf
+          sed -i '/\bSolr is disabled by default\b/d' mailcow.conf
+          sed -i '/\bDisable Solr or\b/d' mailcow.conf
+          sed -i '/\bSKIP_SOLR\b/d' mailcow.conf
+          ;;
+        SOLR_PORT)
+          echo "Removing ${key} in mailcow.conf"
+          sed -i '/\bSOLR_PORT\b/d' mailcow.conf
+          ;;
+        FLATCURVE_EXPERIMENTAL)
+          echo "Removing ${key} in mailcow.conf"
+          sed -i '/\bFLATCURVE_EXPERIMENTAL\b/d' mailcow.conf
+          ;;
+        DISABLE_IPv6)
+          echo "Migrating ${key} to ENABLE_IPv6 in mailcow.conf"
+          local old=$(grep '^DISABLE_IPv6=' "mailcow.conf" | cut -d'=' -f2)
+          local new
+          if [[ "$old" == "y" ]]; then
+            new="false"
+          else
+            new="true"
+          fi
+          sed -i '/^DISABLE_IPv6=/d' "mailcow.conf"
+          echo "ENABLE_IPV6=$new" >> "mailcow.conf"
+          ;;
+      esac
+    fi
+  done
+
+  solr_volume=$(docker volume ls -qf name=^${COMPOSE_PROJECT_NAME}_solr-vol-1)
+  if [[ -n $solr_volume ]]; then
+    echo -e "\e[34mSolr has been replaced within mailcow since 2025-01.\nThe volume $solr_volume is unused.\e[0m"
+    sleep 1
+    if [ ! "$FORCE" ]; then
+      read -r -p "Remove $solr_volume? [y/N] " response
+      if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]; then
+        echo -e "\e[33mRemoving $solr_volume...\e[0m"
+        docker volume rm $solr_volume || echo -e "\e[31mFailed to remove. Remove it manually!\e[0m"
+        echo -e "\e[32mSuccessfully removed $solr_volume!\e[0m"
+      else
+        echo -e "Not removing $solr_volume. Run \`docker volume rm $solr_volume\` manually if needed."
+      fi
+    else
+      echo -e "\e[33mForce removing $solr_volume...\e[0m"
+      docker volume rm $solr_volume || echo -e "\e[31mFailed to remove. Remove it manually!\e[0m"
+      echo -e "\e[32mSuccessfully removed $solr_volume!\e[0m"
+    fi
+  fi
+
+  # Delete old fts.conf before forced switch to flatcurve to ensure update is working properly
+  FTS_CONF_PATH="${SCRIPT_DIR}/data/conf/dovecot/conf.d/fts.conf"
+  if [[ -f "$FTS_CONF_PATH" ]]; then
+    if grep -q "Autogenerated by mailcow" "$FTS_CONF_PATH"; then
+      rm -rf $FTS_CONF_PATH
+    fi
+  fi
+}

+ 3 - 2
_modules/new_options.sh → _modules/scripts/new_options.sh

@@ -277,9 +277,10 @@ adapt_new_options() {
         ENABLE_IPV6)
             echo '# IPv6 Controller Section' >> mailcow.conf
             echo '# This variable controls the usage of IPv6 within mailcow.' >> mailcow.conf
-            echo '# Defaults to true' >> mailcow.conf
+            echo '# Can either be true or false | Defaults to true' >> mailcow.conf
             echo '# WARNING: MAKE SURE TO PROPERLY CONFIGURE IPv6 ON YOUR HOST FIRST BEFORE ENABLING THIS AS FAULTY CONFIGURATIONS CAN LEAD TO OPEN RELAYS!' >> mailcow.conf
-            echo $ENABLE_IPV6_LINE >> mailcow.conf
+            echo '# A COMPLETE DOCKER STACK REBUILD (compose down && compose up -d) IS NEEDED TO APPLY THIS.' >> mailcow.conf
+            echo ENABLE_IPV6=${IPV6_BOOL} >> mailcow.conf
             ;;
     
         SKIP_CLAMD)

+ 1 - 1
docker-compose.yml

@@ -394,7 +394,7 @@ services:
         - php-fpm-mailcow
         - sogo-mailcow
         - rspamd-mailcow
-      image: ghcr.io/mailcow/nginx:1.03
+      image: ghcr.io/mailcow/nginx:1.04
       dns:
         - ${IPV4_NETWORK:-172.22.1}.254
       environment:

+ 6 - 6
generate_config.sh

@@ -1,8 +1,8 @@
 #!/usr/bin/env bash
 
 # Load mailcow Generic Scripts
-source _modules/core.sh
-source _modules/ipv6.sh
+source _modules/scripts/core.sh
+source _modules/scripts/ipv6_controller.sh
 
 set -o pipefail
 
@@ -140,8 +140,7 @@ if [ ! -z "${MAILCOW_BRANCH}" ]; then
   git_branch=${MAILCOW_BRANCH}
 fi
 
-get_ipv6_support
-docker_daemon_edit
+configure_ipv6
 
 [ ! -f ./data/conf/rspamd/override.d/worker-controller-password.inc ] && echo '# Placeholder' > ./data/conf/rspamd/override.d/worker-controller-password.inc
 
@@ -438,9 +437,10 @@ SPAMHAUS_DQS_KEY=
 
 # IPv6 Controller Section
 # This variable controls the usage of IPv6 within mailcow.
-# Defaults to true
+# Can either be true or false | Defaults to true
 # WARNING: MAKE SURE TO PROPERLY CONFIGURE IPv6 ON YOUR HOST FIRST BEFORE ENABLING THIS AS FAULTY CONFIGURATIONS CAN LEAD TO OPEN RELAYS!
-$ENABLE_IPV6_LINE
+# A COMPLETE DOCKER STACK REBUILD (compose down && compose up -d) IS NEEDED TO APPLY THIS.
+ENABLE_IPV6=${IPV6_BOOL}
 
 # Prevent netfilter from setting an iptables/nftables rule to isolate the mailcow docker network - y/n
 # CAUTION: Disabling this may expose container ports to other neighbors on the same subnet, even if the ports are bound to localhost

+ 30 - 10
update.sh

@@ -2,11 +2,11 @@
 
 ############## Begin Function Section ##############
 
-source _modules/core.sh
-source _modules/ipv6_controller.sh
+source _modules/scripts/core.sh
+source _modules/scripts/ipv6_controller.sh
 
-source _modules/new_options.sh
-source _modules/migrate_options.sh
+source _modules/scripts/new_options.sh
+source _modules/scripts/migrate_options.sh
 
 detect_major_update() {
   if [ ${BRANCH} == "master" ]; then
@@ -354,14 +354,34 @@ fi
 if [ ! "$DEV" ]; then
   echo -e "\e[32mChecking for newer update script...\e[0m"
   SHA1_1="$(sha1sum update.sh)"
-  git fetch origin #${BRANCH}
-  git checkout "origin/${BRANCH}" update.sh
-  SHA1_2=$(sha1sum update.sh)
+  git fetch origin
+  git checkout "origin/${BRANCH}" -- update.sh
+  SHA1_2="$(sha1sum update.sh)"
   if [[ "${SHA1_1}" != "${SHA1_2}" ]]; then
-    echo "update.sh changed, please run this script again, exiting."
     chmod +x update.sh
-    exit 2
+    EXIT_COUNT+=1
   fi
+
+  MODULE_DIR="$(dirname "$0")/_modules"
+  echo -e "\e[32mChecking for updates in _modules...\e[0m"
+  if [ ! -d "${MODULE_DIR}" ] || [ -z "$(ls -A "${MODULE_DIR}")" ]; then
+    echo -e "\e[33m_modules missing or empty — fetching from origin...\e[0m"
+    git checkout "origin/${BRANCH}" -- _modules
+  else
+    OLD_SUM="$(find "${MODULE_DIR}" -type f -exec sha1sum {} \; | sort | sha1sum)"
+    git fetch origin
+    git checkout "origin/${BRANCH}" -- _modules
+    NEW_SUM="$(find "${MODULE_DIR}" -type f -exec sha1sum {} \; | sort | sha1sum)"
+
+    if [[ "${OLD_SUM}" != "${NEW_SUM}" ]]; then
+      EXIT_COUNT+=1
+    fi
+  fi
+
+  if [ "${EXIT_COUNT}" -ge 1 ]; then
+    echo "Changes for the update Script, please run this script again, exiting!"
+    exit 2
+
 fi
 
 if [ ! "$FORCE" ]; then
@@ -413,7 +433,7 @@ done
 configure_ipv6
 
 [[ -f data/conf/nginx/ZZZ-ejabberd.conf ]] && rm data/conf/nginx/ZZZ-ejabberd.conf
-migrate_solr_config_options
+migrate_config_options
 adapt_new_options
 remove_obsolete_options