Skip to content

Commit fe3ff91

Browse files
authored
Add MOTD IP Update (#1067)
1 parent d4c9577 commit fe3ff91

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

misc/build.func

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,36 @@ arch_check() {
157157
fi
158158
}
159159

160+
# Function to get the current IP address based on the distribution
161+
get_current_ip() {
162+
if [ -f /etc/os-release ]; then
163+
# Check for Debian/Ubuntu (uses hostname -I)
164+
if grep -qE 'ID=debian|ID=ubuntu' /etc/os-release; then
165+
CURRENT_IP=$(hostname -I | awk '{print $1}')
166+
# Check for Alpine (uses ip command)
167+
elif grep -q 'ID=alpine' /etc/os-release; then
168+
CURRENT_IP=$(ip -4 addr show eth0 | awk '/inet / {print $2}' | cut -d/ -f1 | head -n 1)
169+
else
170+
CURRENT_IP="Unknown"
171+
fi
172+
fi
173+
echo "$CURRENT_IP"
174+
}
175+
176+
# Function to update the IP address in the MOTD file
177+
update_motd_ip() {
178+
MOTD_FILE="/etc/motd"
179+
180+
if [ -f "$MOTD_FILE" ]; then
181+
# Remove existing IP Address lines to prevent duplication
182+
sed -i '/IP Address:/d' "$MOTD_FILE"
183+
184+
IP=$(get_current_ip)
185+
# Add the new IP address
186+
echo -e "${TAB}${NETWORK}${YW} IP Address: ${GN}${IP}${CL}" >> "$MOTD_FILE"
187+
fi
188+
}
189+
160190
# This function sets the APP-Name into an ASCII Header in Slant, figlet needed on proxmox main node.
161191
header_info() {
162192
if [ -f /etc/debian_version ]; then

0 commit comments

Comments
 (0)