source: src-sh/pc-installdialog/pc-installdialog.sh @ 9855292

9.2-releasereleng/10.0releng/10.0.1releng/10.0.2releng/10.0.3releng/10.1
Last change on this file since 9855292 was 9855292, checked in by Kris Moore <kris@…>, 13 months ago

Update text-installer, add option to change boot-loader.

In addition do some cleanup, and prompt the user if they want to cancel,
in case they hit Cancel by mistake

  • Property mode set to 100755
File size: 11.8 KB
Line 
1#!/bin/sh
2# License: BSD
3# Author: Kris Moore (kris@pcbsd.org)
4########################################################
5# This script is fairly linear, it will walk through a series of questions
6# and when finished, generate a pc-sysinstall script
7
8# Source our functions
9. /usr/local/share/pcbsd/scripts/functions.sh
10
11TITLE="PC-BSD Install Dialog"
12
13TANS="/tmp/.pcinsdialog.$$"
14
15CFGFILE="/tmp/sys-install.cfg"
16
17get_dlg_ans()
18{
19    if [ -e "$TANS" ] ; then rm ${TANS}; fi
20    if [ -e "$TANS.dlg" ] ; then rm ${TANS}.dlg; fi
21    while :
22    do
23      echo "dialog --title \"$TITLE\" ${@}" >${TANS}.dlg
24      sh ${TANS}.dlg 2>${TANS}
25      if [ $? -ne 0 ] ; then
26        dialog --title "$TITLE" --yesno 'Exit the installer?' 8 30
27        if [ $? -eq 0 ] ; then exit_err "User canceled install" ; fi
28        continue
29      fi
30
31      if [ ! -e "$TANS" ] ; then
32         ANS=""
33         return
34      fi
35      ANS=`cat ${TANS}`
36      return
37    done
38}
39
40
41get_sys_type()
42{
43  # First ask the system type
44  get_dlg_ans "--radiolist \"System type\" 12 50 5 desktop \"PC-BSD Desktop\" on server \"TrueOS / FreeBSD Server\" off"
45  if [ -z "$ANS" ] ; then
46     exit_err "Invalid system type"
47  fi
48  SYSTYPE="$ANS"
49
50  # If on a desktop, lets just set DHCP
51  if [ "$SYSTYPE" = "desktop" ] ; then
52     SYSNIC="AUTO-DHCP-SLAAC"
53  fi
54}
55
56get_sys_bootmanager()
57{
58  # Ask the boot-manager
59  get_dlg_ans "--radiolist \"Boot Manager\" 12 50 5 GRUB \"GRUB - Recommended\" on BSD \"FreeBSD Boot-Loader\" off none \"No boot-loader\" off"
60  if [ -z "$ANS" ] ; then
61     exit_err "Invalid bootmanager type"
62  fi
63  SYSBOOTMANAGER="$ANS"
64}
65
66get_target_disk()
67{
68  # Now we prompt for the disk to install on
69  dOpts=""
70  pc-sysinstall disk-list > /tmp/.dList.$$
71  while read i
72  do
73     fOpt="on"
74     d=`echo $i | cut -d ':' -f 1`
75     desc=`echo $i | cut -d ':' -f 2`
76     dOpts="$dOpts $d \"$desc\" $fOpt" 
77     if [ -z "$fOpt" ] ; then fOpt="off"; fi
78  done < /tmp/.dList.$$
79  rm /tmp/.dList.$$
80  get_dlg_ans "--radiolist \"Select target disk\" 12 50 5 ${dOpts}"
81  if [ -z "$ANS" ] ; then
82     exit_err "Invalid disk selected!"
83  fi
84  SYSDISK="$ANS"
85}
86
87get_target_part()
88{
89  # Now prompt for the full-disk or partition to install onto
90  pc-sysinstall disk-part $SYSDISK > /tmp/.dList.$$
91  dOpts="ALL \"Use entire disk\" on"
92  dFmt=`grep "$SYSDISK-format:" /tmp/.dList.$$ | awk '{print $2}'` 
93  if [ "$dFmt" = "MBR" ] ; then
94    dChar="s"
95    DISKFORMAT="MBR"
96  else
97    dChar="p"
98    DISKFORMAT="GPT"
99  fi
100  i=1
101  while :
102  do
103     partRAW="${dChar}${i}"
104     part="${SYSDISK}${dChar}${i}"
105     [ -e "/dev/${part}" ] || break
106     desc="`cat /tmp/.dList.$$ | grep ^${part}-label | cut -d ':' -f 2`"
107     mb="`cat /tmp/.dList.$$ | grep ^${part}-sizemb | awk '{print $2}'`"
108     dOpts="$dOpts $partRAW \"${mb}MB -$desc\" off" 
109     i="`expr $i + 1`"
110  done
111  rm /tmp/.dList.$$
112  get_dlg_ans "--radiolist \"Select target partition\" 12 80 5 ${dOpts}"
113  if [ -z "$ANS" ] ; then
114     exit_err "Invalid disk selected!"
115  fi
116  DISKPART="$ANS"
117}
118
119get_root_pw()
120{
121  while :
122  do
123    get_dlg_ans "--passwordbox 'Enter the root password' 8 30"
124    if [ -z "$ANS" ] ; then
125       exit_err "Invalid password entered!"
126    fi
127    ROOTPW="$ANS"
128    get_dlg_ans "--passwordbox 'Confirm root password' 8 30"
129    if [ -z "$ANS" ] ; then
130       exit_err "Invalid password entered!"
131    fi
132    ROOTPWCONFIRM="$ANS"
133    if [ "$ROOTPWCONFIRM" = "$ROOTPW" ] ; then break; fi
134    dialog --title "$TITLE" --yesno 'Password Mismatch, try again?' 8 30
135    if [ $? -eq 0 ] ; then continue ; fi
136    exit_err "Failed setting root password!"
137  done
138}
139
140get_user_pw()
141{
142  while :
143  do
144    get_dlg_ans "--passwordbox \"Enter the password for $USERNAME\" 8 40"
145    if [ -z "$ANS" ] ; then
146       exit_err "Invalid password entered!"
147    fi
148    USERPW="$ANS"
149    get_dlg_ans "--passwordbox 'Confirm password' 8 40"
150    if [ -z "$ANS" ] ; then
151       exit_err "Invalid password entered!"
152    fi
153    USERPWCONFIRM="$ANS"
154    if [ "$USERPWCONFIRM" = "$USERPW" ] ; then break; fi
155    dialog --title "$TITLE" --yesno 'Password Mismatch, try again?' 8 30
156    if [ $? -eq 0 ] ; then continue ; fi
157    exit_err "Failed setting password!"
158  done
159}
160
161get_user_name()
162{
163    get_dlg_ans "--inputbox 'Enter a username' 8 40"
164    if [ -z "$ANS" ] ; then
165       exit_err "Invalid username entered!"
166    fi
167    USERNAME="$ANS"
168}
169
170get_user_realname()
171{
172    get_dlg_ans "--inputbox \"Enter the real name for $USERNAME\" 8 40"
173    if [ -z "$ANS" ] ; then
174       exit_err "Invalid real name entered!"
175    fi
176    USERREALNAME="$ANS"
177}
178
179get_user_shell()
180{
181    get_dlg_ans "--menu \"Select the users shell\" 12 45 10 /bin/sh SH /bin/csh CSH /bin/tcsh TCSH /bin/bash BASH"
182    if [ -z "$ANS" ] ; then
183       exit_err "Invalid SHELL entered!"
184    fi
185    USERSHELL="$ANS"
186}
187
188get_hostname()
189{
190    get_dlg_ans "--inputbox 'Enter a system Hostname' 8 40"
191    if [ -z "$ANS" ] ; then
192       exit_err "Invalid hostname entered!"
193    fi
194    SYSHOSTNAME="$ANS"
195}
196
197get_sshd()
198{
199  SYSSSHD=""
200  dialog --title "$TITLE" --yesno 'Enable SSH?' 8 30
201  if [ $? -ne 0 ] ; then return ; fi
202  SYSSSHD="YES"
203}
204
205get_netconfig()
206{
207  SYSNIC=""
208  SYSNICIP=""
209  SYSNICDNS=""
210  SYSNICMASK=""
211  SYSNICROUTE=""
212
213  dialog --title "$TITLE" --yesno 'Enable networking?' 6 30
214  if [ $? -ne 0 ] ; then return ; fi
215
216  dOpts="auto \"Automatic DHCP\" on"
217  pc-sysinstall detect-nics > /tmp/.dList.$$
218  while read i
219  do
220     d="`echo $i | cut -d ':' -f 1`"
221     desc="`echo $i | cut -d '<' -f 2 | cut -d '>' -f 1`"
222     dOpts="$dOpts $d \"$desc\" off"
223  done < /tmp/.dList.$$
224  rm /tmp/.dList.$$
225  get_dlg_ans "--radiolist \"Select network card to configure\" 12 50 5 ${dOpts}"
226  if [ -z "$ANS" ] ; then
227     exit_err "Invalid NIC selected!"
228  fi
229  SYSNIC="$ANS"
230  if [ "$SYSNIC" = "auto" ] ; then
231     SYSNIC="AUTO-DHCP-SLAAC"
232     return
233  fi
234
235  get_dlg_ans "--inputbox \"Enter the IP address for $SYSNIC\" 8 40"
236  if [ -z "$ANS" ] ; then
237     exit_err "Invalid IP entered!"
238  fi
239  SYSNICIP="$ANS"
240
241  get_dlg_ans "--inputbox \"Enter the Netmask for $SYSNIC\" 8 40"
242  if [ -z "$ANS" ] ; then
243     exit_err "Invalid real name entered!"
244  fi
245  SYSNICMASK="$ANS"
246
247  get_dlg_ans "--inputbox \"Enter the DNS address for $SYSNIC\" 8 40"
248  if [ -z "$ANS" ] ; then
249     exit_err "Invalid real name entered!"
250  fi
251  SYSNICDNS="$ANS"
252
253  get_dlg_ans "--inputbox \"Enter the Gateway address for $SYSNIC\" 8 40"
254  if [ -z "$ANS" ] ; then
255     exit_err "Invalid real name entered!"
256  fi
257  SYSNICROUTE="$ANS"
258
259}
260
261gen_pc-sysinstall_cfg()
262{
263   # Start the header information
264   echo "# Auto-Generated pc-sysinstall configuration" >${CFGFILE}
265   echo "installInteractive=no" >>${CFGFILE}
266   echo "installMode=fresh" >>${CFGFILE}
267   if [ "$SYSTYPE" = "desktop" ] ; then
268     echo "installType=PCBSD" >>${CFGFILE}
269   else
270     echo "installType=FreeBSD" >>${CFGFILE}
271   fi
272   echo "packageType=dist" >> ${CFGFILE}
273   if [ "`uname -m`" = "amd64" ] ; then
274     echo "distFiles=base doc games kernel lib32" >> ${CFGFILE}
275   else
276     echo "distFiles=base doc games kernel" >> ${CFGFILE}
277   fi
278   echo "installMedium=local" >>${CFGFILE}
279   echo "localPath=/dist" >>${CFGFILE}
280
281   if [ -n "$SYSHOSTNAME" ] ; then
282      echo "" >> ${CFGFILE}
283      echo "hostname=$SYSHOSTNAME" >> ${CFGFILE}
284   fi
285   if [ -n "$SYSNIC" ] ; then
286      echo "" >> ${CFGFILE}
287      echo "netSaveDev=$SYSNIC" >> ${CFGFILE}
288      if [ "$SYSNIC" != "AUTO-DHCP-SLAAC" ] ; then
289        echo "netSaveIP_${SYSNIC}=$SYSNICIP" >> ${CFGFILE}
290        echo "netSaveMask_${SYSNIC}=$SYSNICMASK" >> ${CFGFILE}
291        echo "netSaveNameServer_${SYSNIC}=$SYSNICDNS" >> ${CFGFILE}
292        echo "netSaveDefaultRouter_${SYSNIC}=$SYSNICROUTE" >> ${CFGFILE}
293      fi
294   fi
295
296
297   # Now do the disk block
298   echo "" >> ${CFGFILE}
299   echo "# Disk Setup for $SYSDISK" >> ${CFGFILE}
300   echo "disk0=$SYSDISK" >> ${CFGFILE}
301   echo "partition=$DISKPART" >> ${CFGFILE}
302   echo "bootManager=${SYSBOOTMANAGER}" >> ${CFGFILE}
303   echo "partscheme=$DISKFORMAT" >> ${CFGFILE}
304   echo "commitDiskPart" >> ${CFGFILE}
305
306   # Now the partition block
307   echo "" >> ${CFGFILE}
308   echo "# Partition Setup for ${SYSDISK}($DISKPART)" >> ${CFGFILE}
309   echo "# All sizes are expressed in MB" >> ${CFGFILE}
310   echo "# Avail FS Types, UFS, UFS+S, UFS+SUJ, UFS+J, ZFS, SWAP" >> ${CFGFILE}
311   echo "# UFS.eli, UFS+S.eli, UFS+SUJ, UFS+J.eli, ZFS.eli, SWAP.eli" >> ${CFGFILE}
312   echo "disk0-part=ZFS 0 /,/root,/tmp(compress=lz4),/usr(canmount=off),/usr/home,/usr/jails,/usr/obj(compress=lz4),/usr/pbi,/usr/ports(compress=lz4),/usr/ports/distfiles(compress=off),/usr/src(compress=lz4),/var(canmount=off),/var/audit(compress=lz4),/var/log(compress=lz4),/var/tmp(compress=lz4)" >> ${CFGFILE}
313   echo "disk0-part=SWAP 2000 none" >> ${CFGFILE}
314   echo "commitDiskLabel" >> ${CFGFILE}
315   echo "" >> ${CFGFILE}
316
317   # Now the packages
318   if [ "$SYSTYPE" = "desktop" ] ; then
319     echo "installPackages=pcbsd-base pcbsd-meta-kde pcbsd-meta-kde-accessibility pcbsd-meta-kde-artwork pcbsd-meta-kde-graphics pcbsd-meta-kde-multimedia pcbsd-meta-kde-network pcbsd-meta-kde-pim" >> ${CFGFILE}
320     echo "" >> ${CFGFILE}
321     # Set our markers for desktop to run the first-time boot wizards
322     echo "runCommand=sh /usr/local/share/pcbsd/scripts/sys-init.sh desktop en_US" >> ${CFGFILE}
323     echo "runCommand=touch /var/.runxsetup" >> ${CFGFILE}
324     echo "runCommand=touch /var/.pcbsd-firstboot" >> ${CFGFILE}
325     echo "runCommand=touch /var/.pcbsd-firstgui" >> ${CFGFILE}
326   else
327     echo "installPackages=trueos-base" >> ${CFGFILE}
328     echo "" >> ${CFGFILE}
329     echo "runCommand=sh /usr/local/share/pcbsd/scripts/sys-init.sh server" >> ${CFGFILE}
330     echo "" >> ${CFGFILE}
331
332     # Since on TrueOS, lets save username / passwords
333     echo "rootPass=${ROOTPW}" >> ${CFGFILE}
334     echo "" >> ${CFGFILE}
335     echo "userName=${USERNAME}" >> ${CFGFILE}
336     echo "userPass=${USERPW}" >> ${CFGFILE}
337     echo "userShell=${USERSHELL}" >> ${CFGFILE}
338     echo "userHome=/home/${USERNAME}" >> ${CFGFILE}
339     echo "userGroups=wheel,operator" >> ${CFGFILE}
340     echo "commitUser" >> ${CFGFILE}
341   fi
342
343   # Last cleanup stuff
344   echo "" >> ${CFGFILE}
345   echo "runExtCmd=/root/save-config.sh" >> ${CFGFILE}
346   echo "runCommand=newaliases" >> ${CFGFILE}
347
348   # Are we enabling SSHD?
349   if [ "$SYSSSHD" = "YES" ] ; then
350     echo "runCommand=echo 'sshd_enable=\"YES\"' >> /etc/rc.conf" >> ${CFGFILE}
351   fi
352
353}
354
355change_disk_selection() {
356  get_target_disk
357  get_target_part
358  get_sys_bootmanager
359  gen_pc-sysinstall_cfg
360}
361
362start_full_wizard() 
363{
364  # Start the wizard
365  get_sys_type
366  get_target_disk
367  get_target_part
368  get_sys_bootmanager
369
370  # If doing a server setup, need to prompt for some more details
371  if [ "$SYSTYPE" = "server" ] ; then
372     get_root_pw
373     get_user_name
374     get_user_pw
375     get_user_realname
376     get_user_shell
377  fi
378  gen_pc-sysinstall_cfg
379}
380
381# Adjust network options
382change_networking() {
383  get_hostname
384  get_netconfig
385  get_sshd
386  gen_pc-sysinstall_cfg
387}
388
389start_menu_loop()
390{
391
392  while :
393  do
394    dialog --title "PC-BSD Text Install" --menu "Please select from the following options:" 15 40 10 wizard "Run install wizard" disk "Change disk ($SYSDISK)" network "Change networking" view "View install script" edit "Edit install script" install "Start the installation" quit "Quit install wizard" 2>/tmp/answer
395    if [ $? -ne 0 ] ; then break ; fi
396
397    ANS="`cat /tmp/answer`"
398
399    case $ANS in
400     wizard) start_full_wizard
401             rtn
402             ;;
403       disk) change_disk_selection
404             rtn
405             ;;
406    network) change_networking
407             ;;
408       view) more ${CFGFILE}
409             rtn
410             ;;
411       edit) vi ${CFGFILE}
412             rtn
413             ;;
414    install) echo "This will begin the installation, continue?"
415             echo -e "(y/n)\c"
416             read tmp
417             if [ "$tmp" = "y" -o "$tmp" = "Y" ] ; then
418                pc-sysinstall -c ${CFGFILE}
419                rtn
420             fi
421             ;;
422       quit) break ;;
423          *) ;;
424    esac
425  done
426
427}
428
429
430
431if [ ! -e "$CFGFILE" ] ; then
432   cp ${CFGFILE} ${CFGFILE}.bak
433   rm ${CFGFILE}
434fi
435
436start_full_wizard
437start_menu_loop
438
439exit 0
Note: See TracBrowser for help on using the repository browser.