diff --git a/misc/build.func b/misc/build.func index ed08660a..1fe025a2 100644 --- a/misc/build.func +++ b/misc/build.func @@ -157,6 +157,36 @@ arch_check() { fi } +# Function to get the current IP address based on the distribution +get_current_ip() { + if [ -f /etc/os-release ]; then + # Check for Debian/Ubuntu (uses hostname -I) + if grep -qE 'ID=debian|ID=ubuntu' /etc/os-release; then + CURRENT_IP=$(hostname -I | awk '{print $1}') + # Check for Alpine (uses ip command) + elif grep -q 'ID=alpine' /etc/os-release; then + CURRENT_IP=$(ip -4 addr show eth0 | awk '/inet / {print $2}' | cut -d/ -f1 | head -n 1) + else + CURRENT_IP="Unknown" + fi + fi + echo "$CURRENT_IP" +} + +# Function to update the IP address in the MOTD file +update_motd_ip() { + MOTD_FILE="/etc/motd" + + if [ -f "$MOTD_FILE" ]; then + # Remove existing IP Address lines to prevent duplication + sed -i '/IP Address:/d' "$MOTD_FILE" + + IP=$(get_current_ip) + # Add the new IP address + echo -e "${TAB}${NETWORK}${YW} IP Address: ${GN}${IP}${CL}" >> "$MOTD_FILE" + fi +} + # This function sets the APP-Name into an ASCII Header in Slant, figlet needed on proxmox main node. header_info() { if [ -f /etc/debian_version ]; then