mirror of
https://github.com/community-scripts/ProxmoxVE.git
synced 2026-02-03 20:03:25 +01:00
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.
This commit is contained in:
committed by
GitHub
parent
38a0757e4e
commit
d6811a3383
@@ -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..."
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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]"
|
||||
|
||||
@@ -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)}')
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user