]> git.ozlabs.org Git - petitboot/blob - utils/pb-console
00b25acf44c8d996bafaf178673805766a0f88b0
[petitboot] / utils / pb-console
1 #!/bin/sh
2 #
3 # Petitboot utility script for running a petitboot UI program
4 # on a console tty.
5 #
6
7 ui=petitboot-nc
8 shell=sh
9
10 detach=0
11
12 usage() {
13         cat >&2 <<EOF
14 pb-console [OPTIONS] console_dev
15 OPTIONS
16      -d, --detach
17              Start in a detached (background) state.
18      -h, --help
19              Print a help message.
20 EOF
21         exit 1
22 }
23
24 while [ -n "$1" ]
25 do
26         case "$1" in
27         --detach | -d)
28                 detach=1
29                 ;;
30         --help | -h)
31                 usage
32                 ;;
33         --)
34                 ;;
35         *)
36                 console=$1
37                 ;;
38         esac
39         shift
40 done
41
42 if [ -n "$console" -a "${console#/dev/}" = "$console" ]
43 then
44         console="/dev/$console"
45 fi
46
47 pb_loop() {
48         while :
49         do
50                 $ui
51                 echo "Exiting petitboot. Type 'exit' to return."
52                 $shell
53         done
54 }
55
56 if [ -n "$console" ]
57 then
58         exec <$console >$console 2>&1
59 fi
60
61 if [ "$detach" = 1 ]
62 then
63         (
64                 pb_loop
65         ) &
66 else
67         pb_loop
68 fi