mirror of
https://github.com/community-scripts/ProxmoxVED.git
synced 2026-02-25 05:57:26 +00:00
Merge from VE
This commit is contained in:
140
misc/core.func
140
misc/core.func
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copyright (c) 2021-2026 community-scripts ORG
|
||||
# License: MIT | https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/LICENSE
|
||||
# License: MIT | https://git.community-scripts.org/community-scripts/ProxmoxVED/raw/branch/main/LICENSE
|
||||
|
||||
# ==============================================================================
|
||||
# CORE FUNCTIONS - LXC CONTAINER UTILITIES
|
||||
@@ -123,6 +123,7 @@ icons() {
|
||||
CREATING="${TAB}🚀${TAB}${CL}"
|
||||
ADVANCED="${TAB}🧩${TAB}${CL}"
|
||||
FUSE="${TAB}🗂️${TAB}${CL}"
|
||||
GPU="${TAB}🎮${TAB}${CL}"
|
||||
HOURGLASS="${TAB}⏳${TAB}"
|
||||
}
|
||||
|
||||
@@ -551,11 +552,8 @@ msg_info() {
|
||||
if ! declare -p MSG_INFO_SHOWN &>/dev/null || ! declare -A MSG_INFO_SHOWN &>/dev/null; then
|
||||
declare -gA MSG_INFO_SHOWN=()
|
||||
fi
|
||||
# Sanitize message for use as associative array key (remove ANSI codes and special chars)
|
||||
local sanitized_msg
|
||||
sanitized_msg=$(printf '%s' "$msg" | sed 's/\x1b\[[0-9;]*m//g; s/[^a-zA-Z0-9_]/_/g')
|
||||
[[ -n "${MSG_INFO_SHOWN["$sanitized_msg"]+x}" ]] && return
|
||||
MSG_INFO_SHOWN["$sanitized_msg"]=1
|
||||
[[ -n "${MSG_INFO_SHOWN["$msg"]+x}" ]] && return
|
||||
MSG_INFO_SHOWN["$msg"]=1
|
||||
|
||||
stop_spinner
|
||||
SPINNER_MSG="$msg"
|
||||
@@ -600,7 +598,6 @@ msg_ok() {
|
||||
stop_spinner
|
||||
clear_line
|
||||
echo -e "$CM ${GN}${msg}${CL}"
|
||||
# Sanitize message for use as associative array key (remove ANSI codes and special chars)
|
||||
local sanitized_msg
|
||||
sanitized_msg=$(printf '%s' "$msg" | sed 's/\x1b\[[0-9;]*m//g; s/[^a-zA-Z0-9_]/_/g')
|
||||
unset 'MSG_INFO_SHOWN['"$sanitized_msg"']' 2>/dev/null || true
|
||||
@@ -717,7 +714,7 @@ exit_script() {
|
||||
# ------------------------------------------------------------------------------
|
||||
get_header() {
|
||||
local app_name=$(echo "${APP,,}" | tr -d ' ')
|
||||
local app_type=${APP_TYPE:-ct} # Default zu 'ct' falls nicht gesetzt
|
||||
local app_type=${APP_TYPE:-ct} # Default to 'ct' if not set
|
||||
local header_url="https://git.community-scripts.org/community-scripts/ProxmoxVED/raw/branch/main/${app_type}/headers/${app_name}"
|
||||
local local_header_path="/usr/local/community-scripts/headers/${app_type}/${app_name}"
|
||||
|
||||
@@ -820,71 +817,64 @@ is_verbose_mode() {
|
||||
# ------------------------------------------------------------------------------
|
||||
# cleanup_lxc()
|
||||
#
|
||||
# - Comprehensive cleanup of package managers, caches, and logs
|
||||
# - Supports Alpine (apk), Debian/Ubuntu (apt), Fedora/Rocky/CentOS (dnf/yum),
|
||||
# openSUSE (zypper), Gentoo (emerge), and language package managers
|
||||
# - Cleans: Python (pip/uv), Node.js (npm/yarn/pnpm), Go, Rust, Ruby, PHP
|
||||
# - Truncates log files and vacuums systemd journal
|
||||
# - Run at end of container creation to minimize disk usage
|
||||
# - Cleans package manager and language caches (safe for installs AND updates)
|
||||
# - Supports Alpine (apk), Debian/Ubuntu (apt), Python, Node.js, Go, Rust, Ruby, PHP
|
||||
# - Uses fallback error handling to prevent cleanup failures from breaking installs
|
||||
# ------------------------------------------------------------------------------
|
||||
cleanup_lxc() {
|
||||
msg_info "Cleaning up"
|
||||
# OS-specific package manager cleanup
|
||||
|
||||
if is_alpine; then
|
||||
$STD apk cache clean 2>/dev/null || true
|
||||
$STD apk cache clean || true
|
||||
rm -rf /var/cache/apk/*
|
||||
elif command -v apt &>/dev/null; then
|
||||
# Debian/Ubuntu/Devuan
|
||||
$STD apt -y autoremove 2>/dev/null || true
|
||||
$STD apt -y autoclean 2>/dev/null || true
|
||||
$STD apt -y clean 2>/dev/null || true
|
||||
elif command -v dnf &>/dev/null; then
|
||||
# Fedora/Rocky/AlmaLinux/CentOS 8+
|
||||
$STD dnf clean all 2>/dev/null || true
|
||||
$STD dnf autoremove -y 2>/dev/null || true
|
||||
elif command -v yum &>/dev/null; then
|
||||
# CentOS 7/older RHEL
|
||||
$STD yum clean all 2>/dev/null || true
|
||||
elif command -v zypper &>/dev/null; then
|
||||
# openSUSE
|
||||
$STD zypper clean --all 2>/dev/null || true
|
||||
elif command -v emerge &>/dev/null; then
|
||||
# Gentoo
|
||||
$STD emerge --quiet --depclean 2>/dev/null || true
|
||||
$STD eclean-dist -d 2>/dev/null || true
|
||||
$STD eclean-pkg -d 2>/dev/null || true
|
||||
else
|
||||
$STD apt -y autoremove 2>/dev/null || msg_warn "apt autoremove failed (non-critical)"
|
||||
$STD apt -y autoclean 2>/dev/null || msg_warn "apt autoclean failed (non-critical)"
|
||||
$STD apt -y clean 2>/dev/null || msg_warn "apt clean failed (non-critical)"
|
||||
fi
|
||||
|
||||
# Clear temp artifacts (keep sockets/FIFOs; ignore errors)
|
||||
find /tmp /var/tmp -type f -name 'tmp*' -delete 2>/dev/null || true
|
||||
find /tmp /var/tmp -type f -name 'tempfile*' -delete 2>/dev/null || true
|
||||
|
||||
# Truncate writable log files silently (permission errors ignored)
|
||||
if command -v truncate >/dev/null 2>&1; then
|
||||
find /var/log -type f -writable -print0 2>/dev/null |
|
||||
xargs -0 -n1 truncate -s 0 2>/dev/null || true
|
||||
# Python
|
||||
if command -v pip &>/dev/null; then
|
||||
rm -rf /root/.cache/pip 2>/dev/null || true
|
||||
fi
|
||||
if command -v uv &>/dev/null; then
|
||||
rm -rf /root/.cache/uv 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# Node.js npm
|
||||
# Node.js
|
||||
if command -v npm &>/dev/null; then
|
||||
rm -rf /root/.npm/_cacache /root/.npm/_logs 2>/dev/null || true
|
||||
fi
|
||||
# Node.js yarn
|
||||
#if command -v yarn &>/dev/null; then $STD yarn cache clean 2>/dev/null || true; fi
|
||||
# Node.js pnpm
|
||||
if command -v pnpm &>/dev/null; then $STD pnpm store prune 2>/dev/null || true; fi
|
||||
# Go
|
||||
if command -v go &>/dev/null; then $STD go clean -cache -modcache 2>/dev/null || true; fi
|
||||
# Rust cargo
|
||||
if command -v cargo &>/dev/null; then $STD cargo clean 2>/dev/null || true; fi
|
||||
# Ruby gem
|
||||
if command -v gem &>/dev/null; then $STD gem cleanup 2>/dev/null || true; fi
|
||||
# Composer (PHP)
|
||||
if command -v composer &>/dev/null; then $STD composer clear-cache 2>/dev/null || true; fi
|
||||
|
||||
if command -v journalctl &>/dev/null; then
|
||||
$STD journalctl --vacuum-time=10m 2>/dev/null || true
|
||||
if command -v yarn &>/dev/null; then
|
||||
rm -rf /root/.cache/yarn /root/.yarn/cache 2>/dev/null || true
|
||||
fi
|
||||
if command -v pnpm &>/dev/null; then
|
||||
pnpm store prune &>/dev/null || true
|
||||
fi
|
||||
|
||||
# Go (only build cache, not modules)
|
||||
if command -v go &>/dev/null; then
|
||||
$STD go clean -cache 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# Rust (only registry cache, not build artifacts)
|
||||
if command -v cargo &>/dev/null; then
|
||||
rm -rf /root/.cargo/registry/cache /root/.cargo/.package-cache 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# Ruby
|
||||
if command -v gem &>/dev/null; then
|
||||
rm -rf /root/.gem/cache 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# PHP
|
||||
if command -v composer &>/dev/null; then
|
||||
rm -rf /root/.composer/cache 2>/dev/null || true
|
||||
fi
|
||||
|
||||
msg_ok "Cleaned"
|
||||
}
|
||||
|
||||
@@ -954,14 +944,14 @@ function get_lxc_ip() {
|
||||
get_current_ip() {
|
||||
local ip
|
||||
|
||||
# Try direct interface lookup for eth0 FIRST (most reliable for LXC)
|
||||
# Try direct interface lookup for eth0 FIRST (most reliable for LXC) - IPv4
|
||||
ip=$(ip -4 addr show eth0 2>/dev/null | awk '/inet / {print $2}' | cut -d/ -f1 | head -n1)
|
||||
if [[ -n "$ip" && "$ip" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
|
||||
echo "$ip"
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Fallback: Try hostname -I
|
||||
# Fallback: Try hostname -I (returns IPv4 first if available)
|
||||
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
|
||||
@@ -970,9 +960,9 @@ function get_lxc_ip() {
|
||||
fi
|
||||
fi
|
||||
|
||||
# Last resort: Use routing table
|
||||
local targets=("8.8.8.8" "1.1.1.1" "default")
|
||||
for target in "${targets[@]}"; do
|
||||
# Try routing table with IPv4 targets
|
||||
local ipv4_targets=("8.8.8.8" "1.1.1.1" "default")
|
||||
for target in "${ipv4_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
|
||||
@@ -984,6 +974,32 @@ function get_lxc_ip() {
|
||||
fi
|
||||
done
|
||||
|
||||
# IPv6 fallback: Try direct interface lookup for eth0
|
||||
ip=$(ip -6 addr show eth0 scope global 2>/dev/null | awk '/inet6 / {print $2}' | cut -d/ -f1 | head -n1)
|
||||
if [[ -n "$ip" && "$ip" =~ : ]]; then
|
||||
echo "$ip"
|
||||
return 0
|
||||
fi
|
||||
|
||||
# IPv6 fallback: Try hostname -I for IPv6
|
||||
if command -v hostname >/dev/null 2>&1; then
|
||||
ip=$(hostname -I 2>/dev/null | tr ' ' '\n' | grep -E ':' | head -n1)
|
||||
if [[ -n "$ip" && "$ip" =~ : ]]; then
|
||||
echo "$ip"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
# IPv6 fallback: Use routing table with IPv6 targets
|
||||
local ipv6_targets=("2001:4860:4860::8888" "2606:4700:4700::1111")
|
||||
for target in "${ipv6_targets[@]}"; do
|
||||
ip=$(ip -6 route get "$target" 2>/dev/null | awk '{for(i=1;i<=NF;i++) if ($i=="src") print $(i+1)}')
|
||||
if [[ -n "$ip" && "$ip" =~ : ]]; then
|
||||
echo "$ip"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user