]> git.ozlabs.org Git - petitboot/blobdiff - utils/pb-console
utils/pb-console: establish PATH before running pb-config
[petitboot] / utils / pb-console
index c96ac9825d870e3039fb24d86706b50e4c988871..36b9c034e51af0eeaae7b54a03b5ed323798d5dc 100644 (file)
 
 ui=petitboot-nc
 shell=sh
-
+getty=/sbin/getty
+use_getty=0
 detach=0
+pb_config=pb-config
 
 usage() {
-       echo "pb-console [OPTIONS] console_dev" >&2
-       echo "OPTIONS" >&2
-       echo "     -d, --detach" >&2
-       echo "             Start in a detached (background) state." >&2
-       echo "     -h, --help" >&2
-       echo "             Print a help message." >&2
+       cat >&2 <<EOF
+pb-console [OPTIONS] -- [ARGS]
+OPTIONS
+     -d, --detach
+             Start in a detached (background) state.
+
+     -g, --getty[=PATH]
+             Start a getty (specified by PATH, otherwise $getty),
+             passing additional ARGS to the getty process
+
+     -s, --shell=PATH
+             Use PATH as the exit-to-shell shell
+
+     -u, --ui=PATH
+             Use PATH as the petitboot UI
+
+     -h, --help
+             Print a help message.
+EOF
        exit 1
 }
 
-while [ -n "$1" ]
+opts=$(getopt --options 'hdg::s:u:' \
+              --long 'help,detach,getty::,shell:,ui:' \
+              -- "$@")
+[ $? = 0 ] || exit 1
+
+eval set -- "$opts"
+
+while :
 do
        case "$1" in
-       --detach | -d)
+       -d | --detach)
                detach=1
+               shift
+               ;;
+       -g | --getty)
+               use_getty=1
+               getty_arg="$2"
+               shift 2
+               ;;
+       -s | --shell)
+               shell="$2"
+               shift 2
+               ;;
+       -u | --ui)
+               ui="$2"
+               shift 2
                ;;
        --help | -h)
                usage
                ;;
        --)
+               shift
+               break
                ;;
        *)
-               console=$1
-               ;;
+               echo "getopt error"
+               exit 1
        esac
-       shift
 done
 
-if [ -n "$console" -a "${console#/dev/}" = "$console" ]
+if [ "$use_getty" = 1 ]
 then
-       console="/dev/$console"
+       if [ -n "$getty_arg" ]
+       then
+               getty="$getty_arg"
+       fi
+       if [ "$detach" = 1 ]
+       then
+               $getty -l $0 "$@" &
+               exit
+       else
+               exec $getty -l $0 "$@"
+       fi
 fi
 
-pb_loop() {
-       while :
-       do
-               $ui
-               echo "Exiting petitboot. Type 'exit' to return."
-               $shell
-       done
-}
+for f in /etc/environment /etc/locale
+do
+       if [ -e "$f" ]
+       then
+               export $(cat "$f")
+       fi
+done
 
-if [ -n "$console" ]
+# we force local terminals to use the linux termcap definition
+case "$(tty)" in
+/dev/tty[0-9]*)
+       export TERM=linux
+       ;;
+esac
+
+# we may have been run from udev - ensure we have a sensible PATH
+if [ -z "$PATH" ]
 then
-       exec <$console >$console 2>&1
+       PATH=/usr/bin:/usr/sbin:/bin:/sbin
 fi
+export PATH
 
-if [ "$detach" = 1 ]
+verbose_opt=
+if $pb_config debug | grep -q enabled
 then
-       (
-               pb_loop
-       ) &
-else
-       pb_loop
+       verbose_opt=--verbose
 fi
+
+while :
+do
+       $ui $verbose_opt
+       reset
+       echo "Exiting petitboot. Type 'exit' to return."
+       $shell
+done