From e56e6918a7801f4ade53b874f1f425f2dd6347c2 Mon Sep 17 00:00:00 2001 From: librelad Date: Tue, 26 May 2026 16:11:13 +0100 Subject: [PATCH] refactor(network): drop dead 'migrate apps to new subnet' machinery MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The migrate/ helpers were either uncallable or no-ops: - migrateAppsToNewNetwork + updateComposeFileNetwork: never called from anywhere. The intended sed-on-compose subnet rewrite would also have fought the tag system / network_resources DB. - checkAppNetworkCompatibility: called from updateDockerNetworkConfig as a gate, but never explicitly returns, so it's effectively always-true and both branches do the same work. Pure noise. - getInstalledApps: only used by the above. - updateDockerNetworkConfig: collapses to a 2-line 'CFG := docker's reported subnet' adoption — inlined into check_docker_network.sh as adoptDockerSubnet(), which is what it actually does. The legitimate 'subnet changed, refresh apps' path is already covered by the idempotent per-app reinstall (dockerInstallApp ... reset_network=true → clears DB allocations → installer re-runs → ipUpdateComposeTags picks fresh IPs from the current CFG_NETWORK_SUBNET). Migration (infrastructure regen) vs restore (data) stays clean: reinstall regenerates compose+IPs, restore lays data on top. No new pathway needed. Files dropped: scripts/docker/network/migrate/migrate_apps_to_new_network.sh scripts/docker/network/migrate/migrate_check_app_network_compatibility.sh scripts/docker/network/migrate/migrate_get_installed_apps.sh scripts/docker/network/migrate/migrate_update_compose_file_network.sh scripts/docker/network/migrate/migrate_update_docker_network_config.sh Plus the now-empty migrate/ subdir; files_docker.sh regenerated to drop the references. Signed-off-by: librelad --- .../requirements/check_docker_network.sh | 25 +++++-- .../migrate/migrate_apps_to_new_network.sh | 68 ------------------- ...migrate_check_app_network_compatibility.sh | 42 ------------ .../migrate/migrate_get_installed_apps.sh | 14 ---- .../migrate_update_compose_file_network.sh | 27 -------- .../migrate_update_docker_network_config.sh | 23 ------- scripts/source/files/arrays/files_docker.sh | 5 -- 7 files changed, 20 insertions(+), 184 deletions(-) delete mode 100755 scripts/docker/network/migrate/migrate_apps_to_new_network.sh delete mode 100755 scripts/docker/network/migrate/migrate_check_app_network_compatibility.sh delete mode 100755 scripts/docker/network/migrate/migrate_get_installed_apps.sh delete mode 100755 scripts/docker/network/migrate/migrate_update_compose_file_network.sh delete mode 100755 scripts/docker/network/migrate/migrate_update_docker_network_config.sh diff --git a/scripts/checks/requirements/check_docker_network.sh b/scripts/checks/requirements/check_docker_network.sh index c4c2d13..f498208 100755 --- a/scripts/checks/requirements/check_docker_network.sh +++ b/scripts/checks/requirements/check_docker_network.sh @@ -1,16 +1,31 @@ #!/bin/bash +# CFG↔docker subnet adoption: if the docker network already exists with a +# different /24 than CFG, treat docker's value as the truth and update CFG. +# Apps' allocated IPs are still inside docker's subnet, so nothing else needs +# re-IPing. (A genuine user-initiated subnet change is a `libreportal app +# install --reset-network` per app — fresh compose + fresh IPs from +# the new subnet via the standard idempotent install path.) +adoptDockerSubnet() +{ + local current_subnet="$1" + [[ -z "$current_subnet" ]] && return 0 + updateConfigOption "CFG_NETWORK_SUBNET" "$current_subnet" + CFG_NETWORK_SUBNET="$current_subnet" + isSuccessful "Adopted docker's subnet into CFG: $current_subnet" +} + checkDockerNetworkRequirement() -{ +{ if [[ $CFG_REQUIREMENT_DOCKER_NETWORK == "true" ]]; then if [[ $CFG_DOCKER_INSTALL_TYPE == "rootless" ]]; then if dockerCommandRun "docker network inspect $CFG_NETWORK_NAME > /dev/null 2>&1"; then local current_subnet=$(dockerCommandRun "docker network inspect $CFG_NETWORK_NAME --format '{{range .IPAM.Config}}{{.Subnet}}{{end}}' 2>/dev/null") - + if [[ "$current_subnet" == "$CFG_NETWORK_SUBNET" ]]; then isSuccessful "Docker Network $CFG_NETWORK_NAME exists with matching subnet" else - updateDockerNetworkConfig "$current_subnet" + adoptDockerSubnet "$current_subnet" fi else isNotice "Docker Network $CFG_NETWORK_NAME not found." @@ -20,11 +35,11 @@ checkDockerNetworkRequirement() elif [[ $CFG_DOCKER_INSTALL_TYPE == "rooted" ]]; then if runFileOp docker network inspect $CFG_NETWORK_NAME > /dev/null 2>&1; then local current_subnet=$(runFileOp docker network inspect $CFG_NETWORK_NAME --format '{{range .IPAM.Config}}{{.Subnet}}{{end}}' 2>/dev/null) - + if [[ "$current_subnet" == "$CFG_NETWORK_SUBNET" ]]; then isSuccessful "Docker Network $CFG_NETWORK_NAME exists with matching subnet" else - updateDockerNetworkConfig "$current_subnet" + adoptDockerSubnet "$current_subnet" fi else isNotice "Docker Network $CFG_NETWORK_NAME not found." diff --git a/scripts/docker/network/migrate/migrate_apps_to_new_network.sh b/scripts/docker/network/migrate/migrate_apps_to_new_network.sh deleted file mode 100755 index 7073846..0000000 --- a/scripts/docker/network/migrate/migrate_apps_to_new_network.sh +++ /dev/null @@ -1,68 +0,0 @@ -#!/bin/bash - -migrateAppsToNewNetwork() -{ - local old_subnet="$1" - local new_subnet="$2" - - if [[ -z "$old_subnet" || -z "$new_subnet" ]]; then - isError "Both old and new subnets required for network migration" - fi - - isNotice "Starting network migration from $old_subnet to $new_subnet" - isNotice "This will update all installed applications to use the new network." - echo "" - - # Get list of installed apps - local installed_apps=$(getInstalledApps) - - if [[ -z "$installed_apps" ]]; then - isNotice "No installed applications found for migration" - fi - - local apps_updated=0 - local apps_failed=0 - - for app_name in $installed_apps; do - echo "" - isNotice "Processing $app_name..." - - # Get app's compose file path - local compose_file="$containers_dir/$app_name/compose.yml" - - if [[ ! -f "$compose_file" ]]; then - isNotice " No compose file found for $app_name, skipping" - continue - fi - - # Backup original compose file - cp "$compose_file" "$compose_file.backup.$(date +%s)" - - # Update network references in compose file - if updateComposeFileNetwork "$compose_file" "$old_subnet" "$new_subnet"; then - # Restart the app to apply changes - isNotice " Restarting $app_name to apply network changes..." - - if dockerCommandRun "cd $containers_dir/$app_name && docker compose down" && \ - dockerCommandRun "cd $containers_dir/$app_name && COMPOSE_PROGRESS=plain docker compose up --quiet-pull -d"; then - isSuccessful " $app_name successfully migrated to new network" - ((apps_updated++)) - else - isError "Failed to restart $app_name after network update" - # Restore backup - mv "$compose_file.backup.$(date +%s)" "$compose_file" - ((apps_failed++)) - fi - else - isError "Failed to update compose file for $app_name" - ((apps_failed++)) - fi - done - - echo "" - isSuccessful "Network migration completed:" - isSuccessful " Apps updated: $apps_updated" - if [[ $apps_failed -gt 0 ]]; then - isError "Apps failed: $apps_failed" - fi -} diff --git a/scripts/docker/network/migrate/migrate_check_app_network_compatibility.sh b/scripts/docker/network/migrate/migrate_check_app_network_compatibility.sh deleted file mode 100755 index b6a90e9..0000000 --- a/scripts/docker/network/migrate/migrate_check_app_network_compatibility.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/bash - -checkAppNetworkCompatibility() -{ - local target_subnet="$1" - local target_base="${target_subnet%/*}" - - # Get list of installed apps - local installed_apps=$(getInstalledApps) - - if [[ -z "$installed_apps" ]]; then - : - fi - - local incompatible_apps=0 - - for app_name in $installed_apps; do - local compose_file="$containers_dir/$app_name/compose.yml" - - if [[ -f "$compose_file" ]]; then - # Check for static IP assignments that might be incompatible - local static_ips=$(grep -E "ipv4_addresses:|ip:" "$compose_file" 2>/dev/null) - - if [[ -n "$static_ips" ]]; then - # Check if any IPs are outside the target subnet range - while read -r ip_line; do - local ip=$(echo "$ip_line" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | head -1) - if [[ -n "$ip" && ! "$ip" =~ ^${target_base%.*} ]]; then - isNotice " $app_name has incompatible IP: $ip (target: $target_base.0/24)" - ((incompatible_apps++)) - fi - done <<< "$static_ips" - fi - fi - done - - if [[ $incompatible_apps -gt 0 ]]; then - isNotice "Found $incompatible_apps apps with network settings that may need updating" - else - : - fi -} diff --git a/scripts/docker/network/migrate/migrate_get_installed_apps.sh b/scripts/docker/network/migrate/migrate_get_installed_apps.sh deleted file mode 100755 index 72a15aa..0000000 --- a/scripts/docker/network/migrate/migrate_get_installed_apps.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -getInstalledApps() -{ - # Get list of directories in containers that have compose files - local apps="" - for dir in "$containers_dir"/*; do - if [[ -d "$dir" && -f "$dir/compose.yml" ]]; then - local app_name=$(basename "$dir") - apps="$apps $app_name" - fi - done - echo "$apps" -} diff --git a/scripts/docker/network/migrate/migrate_update_compose_file_network.sh b/scripts/docker/network/migrate/migrate_update_compose_file_network.sh deleted file mode 100755 index d7c2451..0000000 --- a/scripts/docker/network/migrate/migrate_update_compose_file_network.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash - -updateComposeFileNetwork() -{ - local compose_file="$1" - local old_subnet="$2" - local new_subnet="$3" - - # Update network subnet references - sed -i "s|subnet: $old_subnet|subnet: $new_subnet|g" "$compose_file" - - # Update IP range references - local old_ip_range="${old_subnet%.*}.0/24" - local new_ip_range="${new_subnet%.*}.0/24" - sed -i "s|ip-range: $old_ip_range|ip-range: $new_ip_range|g" "$compose_file" - - # Update gateway references - local old_gateway="${old_subnet%.*}.1" - local new_gateway="${new_subnet%.*}.1" - sed -i "s|gateway: $old_gateway|gateway: $new_gateway|g" "$compose_file" - - # Update static IP assignments if any - local old_network_base="${old_subnet%/*}" - local new_network_base="${new_subnet%/*}" - sed -i "s|$old_network_base\.|$new_network_base\.|g" "$compose_file" - -} diff --git a/scripts/docker/network/migrate/migrate_update_docker_network_config.sh b/scripts/docker/network/migrate/migrate_update_docker_network_config.sh deleted file mode 100755 index 977bdd9..0000000 --- a/scripts/docker/network/migrate/migrate_update_docker_network_config.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash - -updateDockerNetworkConfig() -{ - local new_subnet="$1" - - if [[ -z "$new_subnet" ]]; then - isNotice "No subnet provided to Update Network Config. Skipping..." - else - if checkAppNetworkCompatibility "$new_subnet"; then - updateConfigOption "CFG_NETWORK_SUBNET" "$new_subnet" - checkSuccess "Updated network configuration to: $new_subnet" - CFG_NETWORK_SUBNET="$new_subnet" - isSuccessful "Network configuration updated successfully." - else - isNotice "App network assignments need to be updated for the new subnet." - updateConfigOption "CFG_NETWORK_SUBNET" "$new_subnet" - checkSuccess "Updated network configuration to: $new_subnet" - CFG_NETWORK_SUBNET="$new_subnet" - isNotice "Note: You may need to reinstall applications to ensure proper network connectivity." - fi - fi -} diff --git a/scripts/source/files/arrays/files_docker.sh b/scripts/source/files/arrays/files_docker.sh index 695e01b..38bf19c 100755 --- a/scripts/source/files/arrays/files_docker.sh +++ b/scripts/source/files/arrays/files_docker.sh @@ -43,11 +43,6 @@ docker_scripts=( "docker/install/rootless/rootless_start_setup.sh" "docker/install/rootless/rootless_uninstall.sh" "docker/install/rootless/rootless_user.sh" - "docker/network/migrate/migrate_apps_to_new_network.sh" - "docker/network/migrate/migrate_check_app_network_compatibility.sh" - "docker/network/migrate/migrate_get_installed_apps.sh" - "docker/network/migrate/migrate_update_compose_file_network.sh" - "docker/network/migrate/migrate_update_docker_network_config.sh" "docker/network/network_prune.sh" "docker/network/network_randomize_subnet.sh" "docker/network/network_setup.sh"