Skip to content

Instantly share code, notes, and snippets.

@samrocketman
Forked from rm/show-ip-before-login.sh
Last active August 29, 2015 14:13
Show Gist options
  • Save samrocketman/488c735fc2339a06bac2 to your computer and use it in GitHub Desktop.
Save samrocketman/488c735fc2339a06bac2 to your computer and use it in GitHub Desktop.
#!/bin/sh
# based on http://offbytwo.com/2008/05/09/show-ip-address-of-vm-as-console-pre-login-message.html
# need to be root to write out these files
if [ `id -u` != 0 ]; then
echo "Need to run as root. Maybe use sudo..."
exit
fi
GET_IP_ADDRESS='/usr/local/bin/get-ip-address'
if [ ! -f $GET_IP_ADDRESS ]; then
cat >$GET_IP_ADDRESS <<EOF
#!/bin/sh
ip address show dev eth0 | grep "inet " | awk '{ print \$2 }' | awk -F/ '{ print \$1 }'
EOF
chmod 0755 $GET_IP_ADDRESS
fi
if [ ! -f '/etc/issue-standard' ]; then
cp /etc/issue /etc/issue-standard
cat >'/etc/network/if-up.d/show-ip-before-login' <<EOF
#/bin/sh
if [ "\$METHOD" = loopback ]; then
exit 0
fi
# Only run from ifup.
if [ "\$MODE" != start ]; then
exit 0
fi
grep -v "^\$" /etc/issue-standard >/etc/issue
echo -n " " >>/etc/issue
$GET_IP_ADDRESS >>/etc/issue
echo "" >> /etc/issue
EOF
chmod 0755 /etc/network/if-up.d/show-ip-before-login
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment