]> git.ozlabs.org Git - petitboot/blob - utils/pb-console
test/parser: cleanup parser allocations on exit
[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         echo "pb-console [OPTIONS] console_dev" >&2
14         echo "OPTIONS" >&2
15         echo "     -d, --detach" >&2
16         echo "             Start in a detached (background) state." >&2
17         echo "     -h, --help" >&2
18         echo "             Print a help message." >&2
19         exit 1
20 }
21
22 while [ -n "$1" ]
23 do
24         case "$1" in
25         --detach | -d)
26                 detach=1
27                 ;;
28         --help | -h)
29                 usage
30                 ;;
31         --)
32                 ;;
33         *)
34                 console=$1
35                 ;;
36         esac
37         shift
38 done
39
40 if [ -n "$console" -a "${console#/dev/}" = "$console" ]
41 then
42         console="/dev/$console"
43 fi
44
45 pb_loop() {
46         while :
47         do
48                 $ui
49                 echo "Exiting petitboot. Type 'exit' to return."
50                 $shell
51         done
52 }
53
54 if [ -n "$console" ]
55 then
56         exec <$console >$console 2>&1
57 fi
58
59 if [ "$detach" = 1 ]
60 then
61         (
62                 pb_loop
63         ) &
64 else
65         pb_loop
66 fi