#!/bin/bash
# Filename:      run-welcome
# Purpose:       customized zsh login welcome screen for use at Grml
# Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
# Bug-Reports:   see http://grml.org/bugs/
# License:       This file is licensed under the GPL v2.
################################################################################

# shellcheck disable=SC1091
. /etc/grml/script-functions

export SHELL=/bin/zsh

[ -r /etc/grml_version ] && GRMLVERSION=$(cat /etc/grml_version) || GRMLVERSION='(no version information available)'
PATH=$HOME/bin:/bin:/sbin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/usr/games:/home/grml/bin
CMDLINE=$(cat /proc/cmdline)
[ -n "$distri" ] || distri="grml"

# welcome beep
case "$CMDLINE" in
  *\ nobeep*)
    ;;
  *)
    (for f in 1000 2000 1500 1750; do beep -f $f -l 150; done) &
    ;;
esac

case "$CMDLINE" in
   # allow customized startup via bootoption startup:
   *startup=*)
       script="$(getbootparam startup)"
       if [ -x "$(command -v "$script")" ] ; then
          $script
       fi
       ;;

   # do nothing if booting with bootoption noquick:
   *\ noquick*)
      ;;
   *) # by default run grml-quickconfig, but only if running as root
      if [ "$(id -u)" = "0" ] ; then
         command -v grml-quickconfig &>/dev/null && grml-quickconfig
      fi
esac

case "$CMDLINE" in
  *\ nowelcome*)
    # just print out an empty line if bootoption "nowelcome" is present
    echo
    ;;
  *)
    # ... otherwise allow customized release information
    if [ -r /etc/release_info ] ; then
      cat /etc/release_info
    else # ... or finally fall back to grml's default
      # display version information depending on the version:
      if grep -q -- '-rc[0-9]' /etc/grml_version 2>/dev/null ; then
        echo
        echo
        echo 'NOTICE: This is a release candidate version!'
        echo 'Please notice that this is not yet a stable release.'
        echo 'Please report any bugs you notice: http://grml.org/bugs/'
        echo
      fi

      if grep -q 'daily' /etc/grml_version 2>/dev/null ; then
        echo
        echo
        echo 'NOTICE: This is a daily snapshot version!'
        echo 'Please notice that this is not yet a stable release.'
        echo 'See http://daily.grml.org/ for more details.'
        echo 'Please report any bugs you notice: http://grml.org/bugs/'
        echo
      fi

      echo "
Welcome to ${GRMLVERSION}!

New to ${distri}? Want to read some documentation?
Start via running 'grml-info'.
Get tips and hints via 'grml-tips \$KEYWORD'.
New to zsh? Run 'zsh-help'.

Switch to other consoles via alt-F<number> keys.

Happy hacking!               http://grml.org/
"
    fi
esac

exec "$SHELL" -l

## END OF FILE #################################################################
