source: src-sh/pc-installdialog/pc-installdialog.sh @ 59f05558

9.2-releasereleng/10.0releng/10.0.1
Last change on this file since 59f05558 was 59f05558, checked in by Kris Moore <kris@…>, 6 months ago

Update pc-textinstall.sh, add options to change ZFS dataset layout / options

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