keep nc, pkill and killall on miniroot
[unleashed-kayak.git] / kayak-menu.sh
blobee80032d38337f3ce584f6a2518fe8d8faa915fc
1 #!/bin/ksh
3 # CDDL HEADER START
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
20 # CDDL HEADER END
23 # Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
24 # Copyright 2017 OmniTI Computer Consulting, Inc. All rights reserved.
27 # This started its life as the Caiman text-installer menu.
29 # LOGNAME variable is needed to display the shell prompt appropriately
30 export LOGNAME=root
32 # Block all signals which could terminate the menu or return to a parent process
33 trap "" TSTP INT TERM ABRT QUIT
35 # Determine which shell program to use by grabbing this user's login-shell
36 # from /etc/passwd
37 ROOT_SHELL=$(/usr/bin/getent passwd $LOGNAME |/usr/bin/cut -d':' -f7)
39 # On the off chance that $LOGNAME has no shell (default grabbed from passwd(4)p)
40 if [[ -z "$ROOT_SHELL" ]]; then
41 ROOT_SHELL="/usr/bin/sh"
44 # Get the user's keyboard choice out of the way now.
45 /usr/bin/kbd -s
46 /usr/bin/loadkeys
47 # Remember it post-installation scribbling into installed-image /etc/default/kbd
48 ktype=`/usr/bin/kbd -l | grep type | awk -F= '{print $2}'`
49 layout=`/usr/bin/kbd -l | grep layout | awk -F= '{print $2}' | awk '{print $1}'`
50 klang=`grep -w $layout /usr/share/lib/keytables/type_$ktype/kbd_layouts | awk -F= '{print $1}'`
52 # Define the menu of commands and prompts
53 menu_items=( \
54 (menu_str="Find disks, create rpool, and install unleashed" \
55 cmds=("/kayak/find-and-install.sh $klang") \
56 do_subprocess="true" \
57 msg_str="") \
58 (menu_str="Install to a preconfigured rpool" \
59 cmds=("/kayak/rpool-install.sh rpool $klang") \
60 do_subprocess="true" \
61 msg_str="") \
62 (menu_str="Shell (for manual rpool creation, or post-install ops on /mnt)" \
63 cmds=("$ROOT_SHELL") \
64 do_subprocess="true" \
65 msg_str="To return to the main menu, exit the shell") \
66 # this string gets overwritten every time $TERM is updated
67 (menu_str="Terminal type (currently ""$TERM)" \
68 cmds=("prompt_for_term_type") \
69 do_subprocess="false" \
70 msg_str="") \
71 (menu_str="Reboot" \
72 cmds=("/usr/sbin/reboot" "/usr/bin/sleep 10000") \
73 do_subprocess="true" \
74 msg_str="") \
77 # Update the menu_str for the terminal type
78 # entry. Every time the terminal type has been
79 # updated, this function must be called.
80 function update_term_menu_str
82 # update the menu string to reflect the current TERM
83 for i in "${!menu_items[@]}"; do
84 if [[ "${menu_items[$i].cmds[0]}" = "prompt_for_term_type" ]] ; then
85 menu_items[$i].menu_str="Terminal type (currently $TERM)"
87 done
90 # Set the TERM variable as follows:
92 # Just set it to "sun-color" for now.
94 function set_term_type
96 export TERM=sun-color
97 update_term_menu_str
100 # Prompt the user for terminal type
101 function prompt_for_term_type
103 integer i
105 # list of suggested termtypes
106 typeset termtypes=(
107 typeset -a fixedlist
108 integer list_len # number of terminal types
111 # hard coded common terminal types
112 termtypes.fixedlist=(
113 [0]=( name="sun-color" desc="PC Console" )
114 [1]=( name="xterm" desc="xterm" )
115 [2]=( name="vt100" desc="DEC VT100" )
118 termtypes.list_len=${#termtypes.fixedlist[@]}
120 # Start with a newline before presenting the choices
121 print
122 printf "Indicate the type of terminal being used, such as:\n"
124 # list suggested terminal types
125 for (( i=0 ; i < termtypes.list_len ; i++ )) ; do
126 nameref node=termtypes.fixedlist[$i]
127 printf " %-10s %s\n" "${node.name}" "${node.desc}"
128 done
130 print
131 # Prompt user to select terminal type and check for valid entry
132 typeset term=""
133 while true ; do
134 read "term?Enter terminal type [$TERM]: " || continue
136 # if the user just hit return, don't set the term variable
137 [[ "${term}" = "" ]] && return
139 # check if the user specified option is valid
140 term_entry=`/usr/bin/ls /usr/gnu/share/terminfo/*/$term 2> /dev/null`
141 [[ ! -z ${term_entry} ]] && break
142 print "terminal type not supported. Supported terminal types can be \n" "${term}"
143 print "found by using the Shell to list the contents of /usr/gnu/share/terminfo.\n\n"
144 done
146 export TERM="${term}"
147 update_term_menu_str
150 set_term_type
152 # default to the Installer option
153 defaultchoice=1
155 for ((;;)) ; do
157 # Display the menu.
158 stty sane
159 clear
160 printf \
161 "Welcome to the unleashed installation menu"
162 print " \n\n"
163 for i in "${!menu_items[@]}"; do
164 print "\t$((${i} + 1)) ${menu_items[$i].menu_str}"
165 done
167 # Take an entry (by number). If multiple numbers are
168 # entered, accept only the first one.
169 input=""
170 dummy=""
171 print -n "\nPlease enter a number [${defaultchoice}]: "
172 read input dummy 2>/dev/null
174 # If no input was supplied, select the default option
175 [[ -z ${input} ]] && input=$defaultchoice
177 # First char must be a digit.
178 if [[ ${input} =~ [^1-9] || ${input} > ${#menu_items[@]} ]] ; then
179 continue
182 # Reorient to a zero base.
183 input=$((${input} - 1))
185 nameref msg_str=menu_items[$input].msg_str
187 # Launch commands as a subprocess.
188 # However, launch the functions within the context
189 # of the current process.
190 if [[ "${menu_items[$input].do_subprocess}" = "true" ]] ; then
192 trap - TSTP INT TERM ABRT QUIT
193 # Print out a message if requested
194 [[ ! -z "${msg_str}" ]] && printf "%s\n" "${msg_str}"
195 for j in "${!menu_items[$input].cmds[@]}"; do
196 ${menu_items[${input}].cmds[$j]}
197 done
199 else
200 # Print out a message if requested
201 [[ ! -z "${msg_str}" ]] && printf "%s\n" "${msg_str}"
202 for j in "${!menu_items[$input].cmds[@]}"; do
203 ${menu_items[${input}].cmds[$j]}
204 done
206 done