]> git.ozlabs.org Git - petitboot/blob - utils/pb-console
Add encrypted file support
[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 pb_config=pb-config
13
14 usage() {
15         cat >&2 <<EOF
16 pb-console [OPTIONS] -- [ARGS]
17 OPTIONS
18      -d, --detach
19              Start in a detached (background) state.
20
21      -g, --getty[=PATH]
22              Start a getty (specified by PATH, otherwise $getty),
23              passing additional ARGS to the getty process
24
25      -s, --shell=PATH
26              Use PATH as the exit-to-shell shell
27
28      -u, --ui=PATH
29              Use PATH as the petitboot UI
30
31      -h, --help
32              Print a help message.
33 EOF
34         exit 1
35 }
36
37 opts=$(getopt --options 'hdg::s:u:' \
38               --long 'help,detach,getty::,shell:,ui:' \
39               -- "$@")
40 [ $? = 0 ] || exit 1
41
42 eval set -- "$opts"
43
44 while :
45 do
46         case "$1" in
47         -d | --detach)
48                 detach=1
49                 shift
50                 ;;
51         -g | --getty)
52                 use_getty=1
53                 getty_arg="$2"
54                 shift 2
55                 ;;
56         -s | --shell)
57                 shell="$2"
58                 shift 2
59                 ;;
60         -u | --ui)
61                 ui="$2"
62                 shift 2
63                 ;;
64         --help | -h)
65                 usage
66                 ;;
67         --)
68                 shift
69                 break
70                 ;;
71         *)
72                 echo "getopt error"
73                 exit 1
74         esac
75 done
76
77 if [ "$use_getty" = 1 ]
78 then
79         if [ -n "$getty_arg" ]
80         then
81                 getty="$getty_arg"
82         fi
83         if [ "$detach" = 1 ]
84         then
85                 $getty -l $0 "$@" &
86                 exit
87         else
88                 exec $getty -l $0 "$@"
89         fi
90 fi
91
92 for f in /etc/environment /etc/locale
93 do
94         if [ -e "$f" ]
95         then
96                 export $(cat "$f")
97         fi
98 done
99
100 # we force local terminals to use the linux termcap definition
101 case "$(tty)" in
102 /dev/tty[0-9]*)
103         export TERM=linux
104         ;;
105 esac
106
107 # we may have been run from udev - ensure we have a sensible PATH
108 if [ -z "$PATH" ]
109 then
110         PATH=/usr/bin:/usr/sbin:/bin:/sbin
111 fi
112 PATH=/var/lib/pb-plugins/bin:$PATH
113 export PATH
114
115 verbose_opt=
116 if $pb_config debug | grep -q enabled
117 then
118         verbose_opt=--verbose
119 fi
120
121 # kernel messages may write over the ncurses ui - change log level to only
122 # show particularly important messages
123 dmesg -n 1
124
125 while :
126 do
127         $ui $verbose_opt
128         reset
129         echo "Exiting petitboot. Type 'exit' to return."
130         echo "You may run 'pb-sos' to gather diagnostic data"
131         $shell
132 done