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

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

Fix which pc-sysinstall we are calling for text-installs

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