summaryrefslogtreecommitdiffstats
path: root/utils/pb-console
blob: 1c2bf62784f62f0aff6faae911063cb385dc71d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/sh
#
# Petitboot utility script for running a petitboot UI program
# on a console tty.
#

ui=petitboot-nc
shell=sh
getty=/sbin/getty
use_getty=0
detach=0

usage() {
	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
}

opts=$(getopt --options 'hdg::s:u:' \
              --long 'help,detach,getty::,shell:,ui:' \
              -- "$@")
[ $? = 0 ] || exit 1

eval set -- "$opts"

while :
do
	case "$1" in
	-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
		;;
	*)
		echo "getopt error"
		exit 1
	esac
done

if [ "$use_getty" = 1 ]
then
	if [ -n "$getty_arg" ]
	then
		getty="$getty_arg"
	fi
	if [ "$detach" = 1 ]
	then
		$getty -l $0 "$@" &
		exit
	else
		exec $getty -l $0 "$@"
	fi
fi

for f in /etc/environment /etc/locale
do
	if [ -e "$f" ]
	then
		export $(cat "$f")
	fi
done

# we force local terminals to use the linux termcap definition
case "$(tty)" in
/dev/tty[0-9]*)
	export TERM=linux
	;;
esac

verbose_opt=
sysinfo_bin=$(dirname $0)/pb-sysinfo
if [ -x $sysinfo_bin ] && $sysinfo_bin --debug-enabled
then
	verbose_opt=--verbose
fi

while :
do
	$ui $verbose_opt
	reset
	echo "Exiting petitboot. Type 'exit' to return."
	$shell
done
OpenPOWER on IntegriCloud