diff --git a/infrastructure_files/getting-started.sh b/infrastructure_files/getting-started.sh index af58346bd..49e0b5011 100755 --- a/infrastructure_files/getting-started.sh +++ b/infrastructure_files/getting-started.sh @@ -476,17 +476,16 @@ configure_docker_subnet() { return 0 fi - # Skip our own network (_netbird) in the conflict check. Resolve the - # directory the way compose does (physical path, so a symlinked install dir - # still yields the real directory name) and normalize the basename the way - # compose-go NormalizeProjectName does: lowercase, drop leading and trailing - # invalid characters, collapse each inner run of invalid characters to a - # single "-", then trim leading "_" and "-". Deleting invalid characters - # instead would be compose v1 behaviour and would miss our own network. + # Skip our own network (_netbird) in the conflict check. Compose + # derives the project name from the basename of the logical working directory + # (verified against Compose v5.4.0: a symlinked directory yields the symlink + # name, not its target), lowercases it, deletes every character outside + # [a-z0-9_-], then trims leading "_" and "-". Verified: "nb.test" -> "nbtest", + # "my nb" -> "mynb", "NetBird-1.0" -> "netbird-10". Networks are then named + # _. local project - project="${COMPOSE_PROJECT_NAME:-$(basename "$(pwd -P)")}" - project=$(echo "$project" | tr '[:upper:]' '[:lower:]' \ - | sed 's/^[^a-z0-9_-]*//; s/[^a-z0-9_-]*$//; s/[^a-z0-9_-][^a-z0-9_-]*/-/g; s/^[_-]*//') + project="${COMPOSE_PROJECT_NAME:-$(basename "$PWD")}" + project=$(echo "$project" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9_-]//g; s/^[_-]*//') check_docker_subnet_conflicts "${project}_netbird" return 0 } diff --git a/infrastructure_files/migrate.sh b/infrastructure_files/migrate.sh index 9d9c4f2af..b31d6cd7c 100755 --- a/infrastructure_files/migrate.sh +++ b/infrastructure_files/migrate.sh @@ -265,18 +265,18 @@ check_docker_subnet_conflicts() { # that generates a compose file pinning a subnet; the exposed-ports compose for # custom proxies lets Docker pick. configure_docker_subnet() { - # Skip our own network (_netbird) in the conflict check. The new - # compose runs from INSTALL_DIR, so resolve it the way compose does (a - # relative --install-dir still yields the real directory name) and normalize - # the basename the way compose-go NormalizeProjectName does: lowercase, drop - # leading and trailing invalid characters, collapse each inner run of invalid - # characters to a single "-", then trim leading "_" and "-". Deleting invalid - # characters instead would be compose v1 behaviour and would miss our own - # network. + # Skip our own network (_netbird) in the conflict check. start_new_services + # runs "cd $INSTALL_DIR && compose up", a logical cd, and compose derives the + # project name from the basename of that logical path -- so resolve it the same + # way with a plain "pwd" (a relative --install-dir still yields an absolute + # path, and a symlinked install dir keeps the symlink name, which is what + # compose sees). "pwd -P" here would resolve the symlink target and no longer + # match. Compose then lowercases, deletes every character outside [a-z0-9_-], + # and trims leading "_" and "-"; verified against Compose v5.4.0 that + # "nb.test" -> "nbtest" and "my nb" -> "mynb". local project - project="${COMPOSE_PROJECT_NAME:-$(basename "$(cd -- "$INSTALL_DIR" && pwd -P)")}" - project=$(echo "$project" | tr '[:upper:]' '[:lower:]' \ - | sed 's/^[^a-z0-9_-]*//; s/[^a-z0-9_-]*$//; s/[^a-z0-9_-][^a-z0-9_-]*/-/g; s/^[_-]*//') + project="${COMPOSE_PROJECT_NAME:-$(basename "$(cd -- "$INSTALL_DIR" && pwd)")}" + project=$(echo "$project" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9_-]//g; s/^[_-]*//') check_docker_subnet_conflicts "${project}_netbird" return 0 }