From d6811a33833fe7afaedc46f5499a2e4de26724f6 Mon Sep 17 00:00:00 2001 From: "CanbiZ (MickLesk)" <47820557+MickLesk@users.noreply.github.com> Date: Mon, 19 Jan 2026 17:32:44 +0100 Subject: [PATCH] Fix ip import (#10964) * Rename import_local_ip to get_local_ip Replaces all references to the helper function import_local_ip with get_local_ip across scripts and documentation for consistency. Updates usage examples and comments to reflect the new function name. * Rename get_local_ip to get_lxc_ip and update usage Replaces all references to get_local_ip with get_lxc_ip across scripts, documentation, and templates for clarity and consistency. Updates the implementation in core.func to improve IP detection for LXC containers, and adjusts helper functions in addon scripts accordingly. --- ct/homepage.sh | 2 +- docs/contribution/HELPER_FUNCTIONS.md | 8 ++++---- .../templates_install/AppName-install.sh | 12 ++++++------ misc/core.func | 19 ++++++++++++++++++- tools/addon/copyparty.sh | 2 +- tools/addon/glances.sh | 4 ++-- tools/addon/jellystat.sh | 2 +- tools/addon/nextcloud-exporter.sh | 2 +- tools/addon/pihole-exporter.sh | 2 +- tools/addon/qbittorrent-exporter.sh | 2 +- 10 files changed, 36 insertions(+), 19 deletions(-) diff --git a/ct/homepage.sh b/ct/homepage.sh index 19ed1648a..a66bf9b2e 100644 --- a/ct/homepage.sh +++ b/ct/homepage.sh @@ -28,7 +28,7 @@ function update_script() { exit fi - import_local_ip + get_lxc_ip NODE_VERSION="22" NODE_MODULE="pnpm@latest" setup_nodejs if ! command -v jq &>/dev/null; then $STD msg_info "Installing jq..." diff --git a/docs/contribution/HELPER_FUNCTIONS.md b/docs/contribution/HELPER_FUNCTIONS.md index b5cc6ead3..1b52ce7db 100644 --- a/docs/contribution/HELPER_FUNCTIONS.md +++ b/docs/contribution/HELPER_FUNCTIONS.md @@ -434,12 +434,12 @@ create_self_signed_cert ## Utility Functions -### `import_local_ip` +### `get_lxc_ip` Set the `$LOCAL_IP` variable with the container's IP address. ```bash -import_local_ip +get_lxc_ip echo "Container IP: $LOCAL_IP" # Use in config files @@ -528,7 +528,7 @@ msg_ok "Installed Dependencies" NODE_VERSION="22" setup_nodejs PG_VERSION="17" setup_postgresql PG_DB_NAME="myapp" PG_DB_USER="myapp" setup_postgresql_db -import_local_ip +get_lxc_ip # Download app using fetch_and_deploy (handles version tracking) fetch_and_deploy_gh_release "myapp" "example/myapp" "tarball" "latest" "/opt/myapp" @@ -664,7 +664,7 @@ PHP_VERSION="8.4" PHP_FPM="YES" PHP_MODULE="bcmath,curl,gd,intl,mbstring,mysql,x setup_composer setup_mariadb MARIADB_DB_NAME="myapp" MARIADB_DB_USER="myapp" setup_mariadb_db -import_local_ip +get_lxc_ip # Download pre-built release (with asset pattern) fetch_and_deploy_gh_release "myapp" "example/myapp" "prebuild" "latest" "/opt/myapp" "myapp-*.tar.gz" diff --git a/docs/contribution/templates_install/AppName-install.sh b/docs/contribution/templates_install/AppName-install.sh index e96138df5..10f62ec37 100644 --- a/docs/contribution/templates_install/AppName-install.sh +++ b/docs/contribution/templates_install/AppName-install.sh @@ -58,7 +58,7 @@ msg_ok "Installed Dependencies" # fetch_and_deploy_gh_release "appname" "owner/repo" "prebuild" "latest" "/opt/appname" "app-*.tar.gz" # # --- Tools & Utilities --- -# import_local_ip # Sets $LOCAL_IP variable (call early!) +# get_lxc_ip # Sets $LOCAL_IP variable (call early!) # setup_ffmpeg # Install FFmpeg with codecs # setup_hwaccel # Setup GPU hardware acceleration # setup_imagemagick # Install ImageMagick 7 @@ -72,7 +72,7 @@ msg_ok "Installed Dependencies" # NODE_VERSION="22" setup_nodejs # PG_VERSION="17" setup_postgresql # PG_DB_NAME="myapp" PG_DB_USER="myapp" setup_postgresql_db -# import_local_ip +# get_lxc_ip # fetch_and_deploy_gh_release "myapp" "owner/myapp" "tarball" "latest" "/opt/myapp" # # msg_info "Configuring MyApp" @@ -89,7 +89,7 @@ msg_ok "Installed Dependencies" # EXAMPLE 2: Python Application with uv # ============================================================================= # PYTHON_VERSION="3.13" setup_uv -# import_local_ip +# get_lxc_ip # fetch_and_deploy_gh_release "myapp" "owner/myapp" "tarball" "latest" "/opt/myapp" # # msg_info "Setting up MyApp" @@ -108,7 +108,7 @@ msg_ok "Installed Dependencies" # setup_composer # setup_mariadb # MARIADB_DB_NAME="myapp" MARIADB_DB_USER="myapp" setup_mariadb_db -# import_local_ip +# get_lxc_ip # fetch_and_deploy_gh_release "myapp" "owner/myapp" "prebuild" "latest" "/opt/myapp" "myapp-*.tar.gz" # # msg_info "Configuring MyApp" @@ -126,7 +126,7 @@ msg_ok "Installed Dependencies" # YOUR APPLICATION INSTALLATION # ============================================================================= # 1. Setup runtimes and databases FIRST -# 2. Call import_local_ip if you need the container IP +# 2. Call get_lxc_ip if you need the container IP # 3. Use fetch_and_deploy_gh_release to download the app (handles version tracking) # 4. Configure the application # 5. Create systemd service @@ -134,7 +134,7 @@ msg_ok "Installed Dependencies" # --- Setup runtimes/databases --- NODE_VERSION="22" setup_nodejs -import_local_ip +get_lxc_ip # --- Download and install app --- fetch_and_deploy_gh_release "[appname]" "[owner/repo]" "tarball" "latest" "/opt/[appname]" diff --git a/misc/core.func b/misc/core.func index ef2af9287..5b4351743 100644 --- a/misc/core.func +++ b/misc/core.func @@ -895,9 +895,26 @@ function get_lxc_ip() { 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 + # Try hostname -I first (most reliable for LXC containers) + if command -v hostname >/dev/null 2>&1; then + ip=$(hostname -I 2>/dev/null | awk '{print $1}') + if [[ -n "$ip" && "$ip" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "$ip" + return 0 + fi + fi + + # Fallback: Try direct interface lookup for eth0 + ip=$(ip -4 addr show eth0 2>/dev/null | awk '/inet / {print $2}' | cut -d/ -f1 | head -n1) + if [[ -n "$ip" ]]; then + echo "$ip" + return 0 + fi + + # Last resort: Use routing table + local targets=("8.8.8.8" "1.1.1.1" "default") 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)}') diff --git a/tools/addon/copyparty.sh b/tools/addon/copyparty.sh index ac8c41e3c..c54cf6a22 100644 --- a/tools/addon/copyparty.sh +++ b/tools/addon/copyparty.sh @@ -303,7 +303,7 @@ UPDATEEOF # ============================================================================== header_info ensure_usr_local_bin_persist -import_local_ip +get_lxc_ip # Handle type=update (called from update script) if [[ "${type:-}" == "update" ]]; then diff --git a/tools/addon/glances.sh b/tools/addon/glances.sh index f6b2b6567..4dec041e2 100644 --- a/tools/addon/glances.sh +++ b/tools/addon/glances.sh @@ -30,7 +30,7 @@ function msg_info() { echo -e "${INFO} ${YW}$1...${CL}"; } function msg_ok() { echo -e "${CM} ${GN}$1${CL}"; } function msg_error() { echo -e "${CROSS} ${RD}$1${CL}"; } -get_local_ip() { +get_lxc_ip() { if command -v hostname >/dev/null 2>&1 && hostname -I 2>/dev/null; then hostname -I | awk '{print $1}' elif command -v ip >/dev/null 2>&1; then @@ -39,7 +39,7 @@ get_local_ip() { echo "127.0.0.1" fi } -IP=$(get_local_ip) +IP=$(get_lxc_ip) install_glances_debian() { msg_info "Installing dependencies" diff --git a/tools/addon/jellystat.sh b/tools/addon/jellystat.sh index 0127b8115..83926634d 100644 --- a/tools/addon/jellystat.sh +++ b/tools/addon/jellystat.sh @@ -325,7 +325,7 @@ if [[ "${type:-}" == "update" ]]; then fi header_info -import_local_ip +get_lxc_ip # Check if already installed if [[ -d "$INSTALL_PATH" && -f "$INSTALL_PATH/package.json" ]]; then diff --git a/tools/addon/nextcloud-exporter.sh b/tools/addon/nextcloud-exporter.sh index 621f01a54..4e29f1680 100644 --- a/tools/addon/nextcloud-exporter.sh +++ b/tools/addon/nextcloud-exporter.sh @@ -155,7 +155,7 @@ UPDATEEOF # ============================================================================== header_info ensure_usr_local_bin_persist -import_local_ip +get_lxc_ip # Handle type=update (called from update script) if [[ "${type:-}" == "update" ]]; then diff --git a/tools/addon/pihole-exporter.sh b/tools/addon/pihole-exporter.sh index 2ad01734f..7aa959679 100644 --- a/tools/addon/pihole-exporter.sh +++ b/tools/addon/pihole-exporter.sh @@ -192,7 +192,7 @@ UPDATEEOF # ============================================================================== header_info ensure_usr_local_bin_persist -import_local_ip +get_lxc_ip # Handle type=update (called from update script) if [[ "${type:-}" == "update" ]]; then diff --git a/tools/addon/qbittorrent-exporter.sh b/tools/addon/qbittorrent-exporter.sh index 93810a1d4..39554384a 100644 --- a/tools/addon/qbittorrent-exporter.sh +++ b/tools/addon/qbittorrent-exporter.sh @@ -185,7 +185,7 @@ UPDATEEOF # ============================================================================== header_info ensure_usr_local_bin_persist -import_local_ip +get_lxc_ip # Handle type=update (called from update script) if [[ "${type:-}" == "update" ]]; then