Skip to content

Instantly share code, notes, and snippets.

@huwan
Last active November 2, 2016 03:40
Show Gist options
  • Save huwan/da52f2605dbe4a841c9e to your computer and use it in GitHub Desktop.
Save huwan/da52f2605dbe4a841c9e to your computer and use it in GitHub Desktop.
Create welcome message with access information.
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
DATA_DIR="/tmp/welcome"
get_local_ip_address () {
ip=`ifconfig | grep 'inet addr' | \
awk '{ print $2 }' | \
awk 'BEGIN { FS=":" } { print $2 }' | \
grep -v '127\.0\.0\.1' | \
head -1`
if [ "x$ip" = "x" ] ; then
return 1
fi
echo $ip
}
welcome_message_branding_logo() {
# /bin/echo -e " ____ _ _ ";
# /bin/echo -e " / ___| _ _ ___| | __ _| |__ ";
# /bin/echo -e " \___ \| | | / __| | / _\` | '_ \ ";
# /bin/echo -e " ___) | |_| \__ \ |__| (_| | |_) |";
# /bin/echo -e " |____/ \__, |___/_____\__,_|_.__/ ";
# /bin/echo -e " |___/ ";
/bin/echo -e " ____ ____ _ _ ";
/bin/echo -e " / ___/ ___|| | __ _| |__ ";
/bin/echo -e " \___ \___ \| | / _\` | '_ \ ";
/bin/echo -e " ___) |__) | |___ (_| | |_) | ";
/bin/echo -e " |____/____/|_____\__,_|_.__/ ";
/bin/echo -e " ";
}
welcome_message_header() {
/bin/echo -e "\033[0;36m"
welcome_message_branding_logo
/bin/echo -e "\033[0m"
/bin/echo -e "\033[1m*** Welcome to System Software Laboratory."
/bin/echo -e "\033[1m*** Built using Ubuntu 10.04 - Kernel \\\\r. \033[0m"
}
welcome_message_with_networking() {
/bin/echo -e "\033[1;33m"
/bin/echo -e "\033[1m*** IP: @@HOSTNAME@@ \033[0m"
}
welcome_message_no_networking() {
/bin/echo -e "\033[1;33m"
/bin/echo -e "\033[1m*** The machine could not configure the network interface."
/bin/echo -e "\033[0m"
}
welcome_message_footer() {
password="toor"
if [ "x$password" != "x" ] ; then
/bin/echo -e "\033[1;31m"
/bin/echo -e "\033[1m*** Username: root"
/bin/echo -e "\033[1m*** Password: $password \033[0m"
/bin/echo -e "\033[0m"
fi
}
# initialize empty directory for template parts
mkdir -p "$DATA_DIR/welcome_message.d" && chmod 0700 "$DATA_DIR/welcome_message.d" && rm -f "$DATA_DIR/welcome_message.d/*"
welcome_message_header >$DATA_DIR/welcome_message.d/header
welcome_message_with_networking >$DATA_DIR/welcome_message.d/with_networking
welcome_message_no_networking >$DATA_DIR/welcome_message.d/no_networking
welcome_message_footer >$DATA_DIR/welcome_message.d/footer
IP=`get_local_ip_address`
if [ "x$IP" = "x" ] ; then
if [ -f "/etc/init.d/networking" ]; then
/etc/init.d/networking force-reload
IP=`get_local_ip_address`
elif [ -f "/etc/init.d/network" ]; then
/etc/init.d/network force-reload
IP=`get_local_ip_address`
fi
fi
if [ "x$IP" != "x" ] ; then
cat \
$DATA_DIR/welcome_message.d/header \
$DATA_DIR/welcome_message.d/with_networking \
$DATA_DIR/welcome_message.d/footer \
| sed "s,@@HOSTNAME@@,$IP,g" \
>/etc/issue
else
cat \
$DATA_DIR/welcome_message.d/header \
$DATA_DIR/welcome_message.d/no_networking \
$DATA_DIR/welcome_message.d/footer \
>/etc/issue
fi
exit 0

welcome_msg

Create welcome message with access information.

Usage: add script code snippet below to /etc/rc.local just before "exit 0"

Copyright 2015 Bitnami.com All Rights Reserved

DATA_DIR="/tmp/welcome"

get_local_ip_address () {
  ip=`ifconfig | grep 'inet addr' | \
    awk '{ print $2 }' | \
    awk 'BEGIN { FS=":" } { print $2 }' | \
    grep -v '127\.0\.0\.1' | \
    head -1`
  if [ "x$ip" = "x" ] ; then
    return 1
  fi
  echo $ip
}

welcome_message_branding_logo() {
  /bin/echo -e "  ____            _          _     ";
  /bin/echo -e " / ___| _   _ ___| |    __ _| |__  ";
  /bin/echo -e " \___ \| | | / __| |   / _\` | '_ \ ";
  /bin/echo -e "  ___) | |_| \__ \ |__| (_| | |_) |";
  /bin/echo -e " |____/ \__, |___/_____\__,_|_.__/ ";
  /bin/echo -e "        |___/                      ";
}

welcome_message_header() {
  /bin/echo -e "\033[0;36m"
  welcome_message_branding_logo
  /bin/echo -e "\033[0m"
  /bin/echo -e "\033[1m***       Welcome to the System Software Lab.      ***"
  /bin/echo -e "\033[1m*** Built using Ubuntu 14.04 - Kernel \\\\r. ***\033[0m"
}

welcome_message_with_networking() {
  /bin/echo -e "\033[1;33m"
  /bin/echo -e "\033[1m*** You can access the guest at http://@@HOSTNAME@@ ***\033[0m"
}

welcome_message_no_networking() {
  /bin/echo -e "\033[1;33m"
  /bin/echo -e "\033[1m*** The machine could not configure the network interface. ***"
  /bin/echo -e "\033[0m"
}

welcome_message_footer() {
  password="password"
  if [ "x$password" != "x" ] ; then
    /bin/echo -e "\033[1;31m"
    /bin/echo -e "**********************************************************"
    /bin/echo -e "   To access the console, please use login 'root'"
    /bin/echo -e "   and password '$password'"
    /bin/echo -e "**********************************************************\033[0m"
  fi
}


# initialize empty directory for template parts
mkdir -p "$DATA_DIR/welcome_message.d" && chmod 0700 "$DATA_DIR/welcome_message.d" && rm -f "$DATA_DIR/welcome_message.d/*"
welcome_message_header >$DATA_DIR/welcome_message.d/header
welcome_message_with_networking >$DATA_DIR/welcome_message.d/with_networking
welcome_message_no_networking >$DATA_DIR/welcome_message.d/no_networking
welcome_message_footer >$DATA_DIR/welcome_message.d/footer

IP=`get_local_ip_address`

if [ "x$IP" = "x" ] ; then
  if [ -f "/etc/init.d/networking" ]; then
    /etc/init.d/networking force-reload
    IP=`get_local_ip_address`
  elif [ -f "/etc/init.d/network" ]; then
    /etc/init.d/network force-reload
    IP=`get_local_ip_address`
  fi
fi

if [ "x$IP" != "x" ] ; then
  cat \
    $DATA_DIR/welcome_message.d/header \
    $DATA_DIR/welcome_message.d/with_networking \
    $DATA_DIR/welcome_message.d/footer \
    | sed "s,@@HOSTNAME@@,$IP,g" \
    >/etc/issue
else
  cat \
    $DATA_DIR/welcome_message.d/header \
    $DATA_DIR/welcome_message.d/no_networking \
    $DATA_DIR/welcome_message.d/footer \
    >/etc/issue
fi
@huwan
Copy link
Author

huwan commented Dec 12, 2015

demo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment