-
-
Save samrocketman/9d6621d5a46c537e60df to your computer and use it in GitHub Desktop.
Show IP address on prelogin message
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# based on http://offbytwo.com/2008/05/09/show-ip-address-of-vm-as-console-pre-login-message.html | |
# based on https://gist.github.com/rm/3780228 | |
# A better IP address method https://www.linuxquestions.org/questions/blog/sag47-492023/using-a-script-to-get-your-ip-address-35251/ | |
# 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 | |
#get ip address based on default route | |
ip -o ro get \$(ip ro | awk '\$1 == "default" { print \$3 }') | awk '{print \$5}' | |
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