]> git.ozlabs.org Git - petitboot/blob - utils/pb-console
lib/process: Add process helpers
[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 getty=/sbin/getty
10 use_getty=0
11 detach=0
12
13 usage() {
14         cat >&2 <<EOF
15 pb-console [OPTIONS] -- [ARGS]
16 OPTIONS
17      -d, --detach
18              Start in a detached (background) state.
19
20      -g, --getty[=PATH]
21              Start a getty (specified by PATH, otherwise $getty),
22              passing additional ARGS to the getty process
23
24      -s, --shell=PATH
25              Use PATH as the exit-to-shell shell
26
27      -u, --ui=PATH
28              Use PATH as the petitboot UI
29
30      -h, --help
31              Print a help message.
32 EOF
33         exit 1
34 }
35
36 opts=$(getopt --options 'hdg::s:u:' \
37               --long 'help,detach,getty::,shell:,ui:' \
38               -- "$@")
39 [ $? = 0 ] || exit 1
40
41 eval set -- "$opts"
42
43 while :
44 do
45         case "$1" in
46         -d | --detach)
47                 detach=1
48                 shift
49                 ;;
50         -g | --getty)
51                 use_getty=1
52                 getty_arg="$2"
53                 shift 2
54                 ;;
55         -s | --shell)
56                 shell="$2"
57                 shift 2
58                 ;;
59         -u | --ui)
60                 ui="$2"
61                 shift 2
62                 ;;
63         --help | -h)
64                 usage
65                 ;;
66         --)
67                 shift
68                 break
69                 ;;
70         *)
71                 echo "getopt error"
72                 exit 1
73         esac
74 done
75
76 if [ "$use_getty" = 1 ]
77 then
78         if [ -n "$getty_arg" ]
79         then
80                 getty="$getty_arg"
81         fi
82         if [ "$detach" = 1 ]
83         then
84                 $getty -l $0 "$@" &
85         else
86                 exec $getty -l $0 "$@"
87         fi
88 fi
89
90 for f in /etc/environment /etc/locale
91 do
92         if [ -e "$f" ]
93         then
94                 export $(cat "$f")
95         fi
96 done
97
98 while :
99 do
100         $ui
101         echo "Exiting petitboot. Type 'exit' to return."
102         $shell
103 done