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

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

Add networking support to PC-BSD text installer

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