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

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

Add a list of ZFS props which we will eventually use for text installer

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