forked from omniosorg/kayak
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kayak-menu
executable file
·292 lines (259 loc) · 7.54 KB
/
kayak-menu
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
#!/bin/ksh
#
# {{{ CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END }}}
# Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
# Copyright 2017 OmniTI Computer Consulting, Inc. All rights reserved.
# Copyright 2021 OmniOS Community Edition (OmniOSce) Association.
# This started its life as the Caiman text-installer menu, hence the old
# OpenSolaris CDDL statement.
# Block all signals which could terminate the menu or return to a parent
# process, except if started with the '-t' option for testing.
debug=0
[ "$1" != '-t' ] && trap "" TSTP INT TERM ABRT QUIT || debug=1
# LOGNAME variable is needed to display the shell prompt appropriately
export LOGNAME=root
# Running on the console so use the appropriate terminal type
export TERM=sun-color
export VERSION=`head -1 /etc/release | awk '{print $3}'`
. /kayak/lib/install_help.sh
. /kayak/lib/dialog.sh
if [ $debug -eq 0 ]; then
echo
echo "Scanning for media..."
mkdir /.cdrom
mkdir /.usbdrive
/kayak/bin/mount_media $VERSION
fi
if [ ! -f /.cdrom/.volsetid ]; then
echo
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "!!! Could not mount installation media !!!"
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo
read a
fi
# If dialogue is supported, offer the user a choice.
if [ -n "$USE_DIALOG" ]; then
i=10
echo; echo
echo "Press return to start the OmniOS installer."
while [ $i -gt 0 ]; do
unit=second
[ $i -gt 1 ] && unit=seconds
printf "\rTo use the old text installer, press T within %d %s..." $i $unit
read -t 1 -N 1 mode
stat=$?
case $stat/$mode in
0/[tT]) export USE_DIALOG=; break ;;
0/*) break ;;
esac
((i = i - 1))
done
echo
fi
# Print a message if in debug mode
function dmsg {
[ $debug -eq 1 ] && echo "$@"
}
# If an installation has been completed, there will be a boot environment
# and it will be mounted on /mnt
function installed {
[ -d /mnt/lib ] || return 1
beadm list -H > /dev/null 2>&1
}
# Get the user's keyboard choice out of the way now.
if [ -n "$USE_DIALOG" ]; then
tmpf=`mktemp`
dialog \
--title "Please select a keyboard layout" \
--no-ok \
--no-tags \
--no-lines \
--nocancel \
--default-item US-English \
--menu "Use the arrow keys to move up and down the list" \
19 0 16 \
`cat /kayak/etc/kbd.list | sed 's/.*/& &/'` \
2> $tmpf
stat=$?
if [ $stat -eq 0 ]; then
layout=`cat $tmpf`
elif [ $debug -eq 1 -a $stat -gt 4 ]; then
exit 0
else
layout=US-English
fi
rm -f $tmpf
/usr/bin/kbd -s $layout
else
/usr/bin/kbd -s
fi
/usr/bin/loadkeys
# Remember it for configuration of final installed image.
ktype=`/usr/bin/kbd -l | grep '^type=' | cut -d= -f2`
layout=`/usr/bin/kbd -l | grep '^layout=' | cut -d= -f2 | awk '{print $1}'`
klang=`grep -w $layout /usr/share/lib/keytables/type_$ktype/kbd_layouts \
| cut -d= -f1`
dmsg "klang = $klang"
# Define the menu of commands and prompts
function d_detecting {
d_info "Detecting disks, please wait..."
}
# Preinstall menu
menu_items=( \
(menu_str="Find disks, create rpool, and install OmniOS" \
cmds=("/kayak/installer/find-and-install $klang") \
dcmds=("d_detecting x", "/kayak/installer/dialog-install $klang")\
default="true" \
do_subprocess="true") \
(menu_str="Install OmniOS straight on to a preconfigured rpool" \
cmds=("/kayak/installer/rpool-install rpool $klang") \
do_subprocess="true") \
(menu_str="Shell (for manual rpool creation)" \
cmds=("/usr/bin/bash") \
do_subprocess="true" \
msg_str="To return to the main menu, exit the shell") \
(menu_str="Reboot" \
cmds=("/usr/sbin/reboot") \
do_subprocess="true" \
noreturn="true" \
msg_str="Restarting, please wait...") \
(menu_str="Halt" \
cmds=("/sbin/beadm umount /mnt" "/sbin/uadmin 2 6") \
do_subprocess="true" \
noreturn="true" \
msg_str="Halting system, please wait...") \
)
# Postinstall menu
pi_menu_items=( \
(menu_str="Configure the installed OmniOS system" \
cmds=("/kayak/installer/config-menu") \
dcmds=("/kayak/installer/config-menu -dialog") \
default="true" \
do_subprocess="true") \
(menu_str="Shell (for post-install ops on /mnt)" \
cmds=("/usr/bin/bash") \
do_subprocess="true" \
msg_str="To return to the main menu, exit the shell") \
(menu_str="Reboot" \
cmds=("/usr/sbin/reboot") \
do_subprocess="true" \
noreturn="true" \
msg_str="Restarting, please wait...") \
(menu_str="Halt" \
cmds=("/sbin/beadm umount /mnt" "/sbin/uadmin 2 6") \
do_subprocess="true" \
noreturn="true" \
msg_str="Halting system, please wait...") \
)
function display_text_menu {
# Display the menu.
stty sane
clear
printf "Welcome to the OmniOS installation menu\n\n"
for i in "${!menu[@]}"; do
nameref item=menu[$i]
print "\t$((i + 1)) ${item.menu_str}"
[ -n "${item.default}" ] && defaultchoice=$((i + 1))
done
# Take an entry (by number). If multiple numbers are
# entered, accept only the first one.
input=""
dummy=""
print -n "\nPlease enter a number [${defaultchoice}]: "
read input dummy 2>/dev/null
}
function display_dialog_menu {
typeset -a args=()
for i in "${!menu[@]}"; do
nameref item=menu[$i]
args+=($((i + 1)) "${item.menu_str}")
[ -n "${item.default}" ] && defaultchoice=$((i + 1))
done
tmpf=`mktemp`
dialog \
--title "Welcome to the OmniOS installer" \
--hline "Use arrow or hot keys to select one of the options above" \
--no-ok \
--no-tags \
--no-lines \
--nocancel \
--default-item $defaultchoice \
--menu "\n " \
0 0 0 \
"${args[@]}" 2> $tmpf
stat=$?
if [ $stat -eq 0 ]; then
input=`cat $tmpf`
elif [ $debug -eq 1 -a $stat -gt 4 ]; then
exit 0
else
input=err
fi
rm -f $tmpf
}
function display_menu {
[ -n "$USE_DIALOG" ] && display_dialog_menu || display_text_menu
}
function run_cmds {
if [ -n "$USE_DIALOG" -a -n "${item.dcmds}" ]; then
for j in "${!item.dcmds[@]}"; do
${item.dcmds[$j]}
done
else
for j in "${!item.cmds[@]}"; do
${item.cmds[$j]}
done
fi
}
while :; do
# Pick the right menu
installed && nameref menu=pi_menu_items || nameref menu=menu_items
display_menu
# If no input was supplied, select the default option
[ -z "${input}" ] && input=$defaultchoice
# Choice must only contain digits
if [[ ${input} =~ [^1-9] || ${input} > ${#menu[@]} ]]; then
continue
fi
# Re-orient to a zero base.
((input = input - 1))
nameref item=menu[$input]
# Print out a message if requested
[ -n "${item.msg_str}" ] && printf "%s\n" "${item.msg_str}"
# Launch commands as a subprocess.
# However, launch the functions within the context
# of the current process.
if [ "${item.do_subprocess}" = "true" ]; then
(
trap - TSTP INT TERM ABRT QUIT
run_cmds
)
else
run_cmds
fi
if [ "${item.noreturn}" = "true" ]; then
while :; do
sleep 10000
done
fi
done
# Vim hints
# vim:fdm=marker