From ff4f5f6a0a15f7fd892ee49eb4c5cc83813e44ed Mon Sep 17 00:00:00 2001 From: "CanbiZ (MickLesk)" <47820557+MickLesk@users.noreply.github.com> Date: Wed, 28 Jan 2026 13:26:20 +0100 Subject: [PATCH] core: update dynamic values in LXC profile on update_motd_ip (#11268) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(build.func): update dynamic values in LXC profile on update_motd_ip - Updates only OS/Hostname/IP lines in /etc/profile.d/00_lxc-details.sh - Checks if values changed before updating (avoids unnecessary I/O) - Preserves user customizations (app name, GitHub link, custom lines) - Only updates if file exists and contains 'community-scripts' marker - Fixes outdated OS version display after in-place upgrades (e.g., Bookworm → Trixie) - Now reads OS name/version from /etc/os-release at login time Fixes community-scripts/ProxmoxVE issue with static MOTD after OS upgrade * add update_motd_ip in routine --- misc/build.func | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/misc/build.func b/misc/build.func index f395601cb..8bcf5bb79 100644 --- a/misc/build.func +++ b/misc/build.func @@ -195,9 +195,11 @@ get_current_ip() { # # - Updates /etc/motd with current container IP # - Removes old IP entries to avoid duplicates +# - Regenerates /etc/profile.d/00_lxc-details.sh with dynamic OS/IP info # ------------------------------------------------------------------------------ update_motd_ip() { MOTD_FILE="/etc/motd" + PROFILE_FILE="/etc/profile.d/00_lxc-details.sh" if [ -f "$MOTD_FILE" ]; then # Remove existing IP Address lines to prevent duplication @@ -207,6 +209,26 @@ update_motd_ip() { # Add the new IP address echo -e "${TAB}${NETWORK}${YW} IP Address: ${GN}${IP}${CL}" >>"$MOTD_FILE" fi + + # Update dynamic LXC details profile if values changed (e.g., after OS upgrade) + # Only update if file exists and is from community-scripts + if [ -f "$PROFILE_FILE" ] && grep -q "community-scripts" "$PROFILE_FILE" 2>/dev/null; then + # Get current values + local current_os="$(grep ^NAME /etc/os-release | cut -d= -f2 | tr -d '"') - Version: $(grep ^VERSION_ID /etc/os-release | cut -d= -f2 | tr -d '"')" + local current_hostname="$(hostname)" + local current_ip="$(hostname -I | awk '{print $1}')" + + # Update only if values actually changed + if ! grep -q "OS:.*$current_os" "$PROFILE_FILE" 2>/dev/null; then + sed -i "s|OS:.*|OS: \${GN}$current_os\${CL}\\\"|" "$PROFILE_FILE" + fi + if ! grep -q "Hostname:.*$current_hostname" "$PROFILE_FILE" 2>/dev/null; then + sed -i "s|Hostname:.*|Hostname: \${GN}$current_hostname\${CL}\\\"|" "$PROFILE_FILE" + fi + if ! grep -q "IP Address:.*$current_ip" "$PROFILE_FILE" 2>/dev/null; then + sed -i "s|IP Address:.*|IP Address: \${GN}$current_ip\${CL}\\\"|" "$PROFILE_FILE" + fi + fi } # ------------------------------------------------------------------------------ @@ -3310,6 +3332,7 @@ start() { set_std_mode ensure_profile_loaded update_script + update_motd_ip cleanup_lxc else CHOICE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "${APP} LXC Update/Setting" --menu \ @@ -3336,6 +3359,7 @@ start() { esac ensure_profile_loaded update_script + update_motd_ip cleanup_lxc fi }