#!/bin/ash
###############################
#
# Boot CMD options:
#
#   * runcmd="/bin/some_command"   - Override the binary ran, instead of nwipe_launcher
#
#   * nowipe|ttyshell|shelltty|usetty|enabletty   - All of these boot flags are the same - they force 
#     a normal console to be launched on boot instead of nwipe_launcher
#
#   * console_baud                 - Override the console baud rate, which is normally auto-detected from the console= arg
#
#   * simple|basic|vt100           - Use the VT100 console, which disables fancy colours and symbols
#
#   * term="vt100"                 - Specify a custom console type to use, e.g. vt100
#
# NWIPE Options:
# 
#   * autonuke|autowipe|autoformat|noninteractive|autoerase - Automatically format ALL DRIVES on the system.
#
#   * rounds=1                      - Number of times to run 'method'
#
#   * nwipe_verify=last             - Whether to perform verification of erasure (default: last)
#                                     off   - Do not verify
#                                     last  - Verify after the last pass
#                                     all   - Verify every pass
#
#
#   * method=zero                   - Method to use to auto-wipe the drives (default: zero)
#
#     Available Methods:
#
#     dod522022m / dod       - 7 pass DOD 5220.22-M method
#     dodshort / dod3pass    - 3 pass DOD method
#     gutmann                - Peter Gutmann's Algorithm
#     ops2                   - RCMP TSSIT OPS-II
#     random / prng / stream - PRNG Stream
#     zero / quick           - Overwrite with zeros
#
#
###############################

#######
# extractpr [param]
# get_cmd [param]
# has_cmd [param]
# has_cmd_word [word]
source /usr/bin/cmdline.sh


get_console() {
  xcn="$(get_cmd console)"
  conq='s/([a-zA-Z0-9]+),?([0-9]+)?.*/\'
  z_console="$(echo "$xcn" | sed -rn "${conq}1/p")"
  z_baud="$(echo "$xcn" | sed -rn "${conq}2/p")"
  [ -z "$z_console" ] && z_console="console"
  [ -z "$z_baud" ] && z_baud=0
  export z_console
  export z_baud
  echo "$z_console"
  #echo "$z_baud"
}

console="$(get_console)"
baud_rate="$z_baud"

has_cmd console_baud && baud_rate="$(get_cmd console_baud)"
has_cmd runcmd && tty_cmd="$(get_cmd runcmd)" || tty_cmd="/usr/bin/nwipe_launcher"

[ $# -gt 0 ] && console="$1"
[ $# -gt 1 ] && tty_cmd="$2"

if has_cmd_word nowipe ttyshell shelltty usetty enabletty; then
    #/sbin/getty -L "$baud_rate" "$console" vt100
    /sbin/getty -L "$console" "$baud_rate" vt100
else
    if has_cmd_word simple vt100 basic; then
        /sbin/getty "$baud_rate" "$console" vt100 -n -l "$tty_cmd"
    elif has_cmd term; then
        /sbin/getty "$baud_rate" "$console" "$(get_cmd term)" -n -l "$tty_cmd"
    else
        /sbin/getty "$baud_rate" "$console" -n -l "$tty_cmd"
    fi
fi


