From 4dadaec99bcf1793801d514e85dcd0111ce16dc9 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 4 May 2018 15:48:02 +0200 Subject: [SSPS] Fix IP detection in bashrc --- satellit_installer/includes/90-patch_misc_files.inc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/satellit_installer/includes/90-patch_misc_files.inc b/satellit_installer/includes/90-patch_misc_files.inc index 22ba205..1edf931 100644 --- a/satellit_installer/includes/90-patch_misc_files.inc +++ b/satellit_installer/includes/90-patch_misc_files.inc @@ -3,14 +3,16 @@ patch_bashrc() { echo "# As one of the last things here we will set a new prompt to distinguish" echo "# the bwLehrpool satellite server from other servers. To accomplish this" echo "# we will set a very classy prompt. This will take effect at next root login." + local ifname=$( ifconfig | grep -oEm1 '^e\w+' ) echo "# Setting prompt..." if grep -q '^IP=' /root/.bashrc; then echo "...already done." else - cat >> /root/.bashrc <<-"ENDO" - IP=$(ip -4 a show eth0 | grep '^\s*inet\s' | awk -F ' ' '{print $2}') + sed "s/%ifname%/$ifname/g" >> /root/.bashrc <<-"ENDO" + IP=$( ip -4 a show "%ifname%" 2>/dev/null | grep '^\s*inet\s' | awk -F ' ' '{print $2}' ) [ -z "$IP" ] && IP=$(ip -4 a | grep '^\s*inet\s'| grep -v '127.0.0' | head -n 1 | awk -F ' ' '{print $2}') IP=${IP%/*} + [ -z "$IP" ] && IP="noip???" PS1="\[\033[01;31m\]\u\[\033[00m\]@\[\033[01;32m\]\h \[\033[00m\]($IP) \[\033[01;34m\]\w\[\033[00m\] # " ENDO -- cgit v1.2.3-55-g7522