core: update dynamic values in LXC profile on update_motd_ip (#11268)

* 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
This commit is contained in:
CanbiZ (MickLesk)
2026-01-28 13:26:20 +01:00
committed by GitHub
parent ea116222f4
commit ff4f5f6a0a

View File

@@ -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
}