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

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

Move ZFS layout to a variable in prep for a ZFS dataset editing dialog

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