From db5a6bacf443bcdf1da25150d87d72cd70c0d222 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Slavi=C5=A1a=20Are=C5=BEina?= <58952836+tremor021@users.noreply.github.com> Date: Mon, 19 Jan 2026 15:43:12 +0100 Subject: [PATCH] [core]: Make LXC IP a global variable (#10951) --- misc/core.func | 45 +++++++++++++++++++++++++++++++++++++++++++++ misc/tools.func | 44 -------------------------------------------- 2 files changed, 45 insertions(+), 44 deletions(-) diff --git a/misc/core.func b/misc/core.func index 1ff6fb797..ef2af9287 100644 --- a/misc/core.func +++ b/misc/core.func @@ -38,6 +38,7 @@ load_functions() { icons default_vars set_std_mode + get_lxc_ip } # ------------------------------------------------------------------------------ @@ -878,6 +879,50 @@ check_or_create_swap() { fi } +# ------------------------------------------------------------------------------ +# Loads LOCAL_IP from persistent store or detects if missing. +# +# Description: +# - Loads from /run/local-ip.env or performs runtime lookup +# ------------------------------------------------------------------------------ + +function get_lxc_ip() { + local IP_FILE="/run/local-ip.env" + if [[ -f "$IP_FILE" ]]; then + # shellcheck disable=SC1090 + source "$IP_FILE" + fi + + if [[ -z "${LOCAL_IP:-}" ]]; then + get_current_ip() { + local targets=("8.8.8.8" "1.1.1.1" "192.168.1.1" "10.0.0.1" "172.16.0.1" "default") + local ip + + for target in "${targets[@]}"; do + if [[ "$target" == "default" ]]; then + ip=$(ip route get 1 2>/dev/null | awk '{for(i=1;i<=NF;i++) if ($i=="src") print $(i+1)}') + else + ip=$(ip route get "$target" 2>/dev/null | awk '{for(i=1;i<=NF;i++) if ($i=="src") print $(i+1)}') + fi + if [[ -n "$ip" ]]; then + echo "$ip" + return 0 + fi + done + + return 1 + } + + LOCAL_IP="$(get_current_ip || true)" + if [[ -z "$LOCAL_IP" ]]; then + msg_error "Could not determine LOCAL_IP" + return 1 + fi + fi + + export LOCAL_IP +} + # ============================================================================== # SIGNAL TRAPS # ============================================================================== diff --git a/misc/tools.func b/misc/tools.func index f8e8a773c..ba309d873 100644 --- a/misc/tools.func +++ b/misc/tools.func @@ -2004,50 +2004,6 @@ function fetch_and_deploy_gh_release() { rm -rf "$tmpdir" } -# ------------------------------------------------------------------------------ -# Loads LOCAL_IP from persistent store or detects if missing. -# -# Description: -# - Loads from /run/local-ip.env or performs runtime lookup -# ------------------------------------------------------------------------------ - -function import_local_ip() { - local IP_FILE="/run/local-ip.env" - if [[ -f "$IP_FILE" ]]; then - # shellcheck disable=SC1090 - source "$IP_FILE" - fi - - if [[ -z "${LOCAL_IP:-}" ]]; then - get_current_ip() { - local targets=("8.8.8.8" "1.1.1.1" "192.168.1.1" "10.0.0.1" "172.16.0.1" "default") - local ip - - for target in "${targets[@]}"; do - if [[ "$target" == "default" ]]; then - ip=$(ip route get 1 2>/dev/null | awk '{for(i=1;i<=NF;i++) if ($i=="src") print $(i+1)}') - else - ip=$(ip route get "$target" 2>/dev/null | awk '{for(i=1;i<=NF;i++) if ($i=="src") print $(i+1)}') - fi - if [[ -n "$ip" ]]; then - echo "$ip" - return 0 - fi - done - - return 1 - } - - LOCAL_IP="$(get_current_ip || true)" - if [[ -z "$LOCAL_IP" ]]; then - msg_error "Could not determine LOCAL_IP" - return 1 - fi - fi - - export LOCAL_IP -} - # ------------------------------------------------------------------------------ # Installs Adminer (Debian/Ubuntu via APT, Alpine via direct download). #