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

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

Always start with a fresh install script

  • Property mode set to 100755
File size: 8.8 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
43
44get_target_disk()
45{
46  # Now we prompt for the disk to install on
47  dOpts=""
48  pc-sysinstall disk-list > /tmp/.dList.$$
49  while read i
50  do
51     fOpt="on"
52     d=`echo $i | cut -d ':' -f 1`
53     desc=`echo $i | cut -d ':' -f 2`
54     dOpts="$dOpts $d \"$desc\" $fOpt" 
55     if [ -z "$fOpt" ] ; then fOpt="off"; fi
56  done < /tmp/.dList.$$
57  rm /tmp/.dList.$$
58  get_dlg_ans "--radiolist \"Select target disk\" 12 50 5 ${dOpts}"
59  if [ -z "$ANS" ] ; then
60     exit_err "Invalid disk selected!"
61  fi
62  SYSDISK="$ANS"
63}
64
65get_target_part()
66{
67  # Now prompt for the full-disk or partition to install onto
68  pc-sysinstall disk-part $SYSDISK > /tmp/.dList.$$
69  dOpts="ALL \"Use entire disk\" on"
70  dFmt=`grep "$SYSDISK-format:" /tmp/.dList.$$ | awk '{print $2}'` 
71  if [ "$dFmt" = "MBR" ] ; then
72    dChar="s"
73    DISKFORMAT="MBR"
74  else
75    dChar="p"
76    DISKFORMAT="GPT"
77  fi
78  i=1
79  while :
80  do
81     partRAW="${dChar}${i}"
82     part="${SYSDISK}${dChar}${i}"
83     [ -e "/dev/${part}" ] || break
84     desc="`cat /tmp/.dList.$$ | grep ^${part}-label | cut -d ':' -f 2`"
85     mb="`cat /tmp/.dList.$$ | grep ^${part}-sizemb | awk '{print $2}'`"
86     dOpts="$dOpts $partRAW \"${mb}MB -$desc\" off" 
87     i="`expr $i + 1`"
88  done
89  rm /tmp/.dList.$$
90  get_dlg_ans "--radiolist \"Select target partition\" 12 80 5 ${dOpts}"
91  if [ -z "$ANS" ] ; then
92     exit_err "Invalid disk selected!"
93  fi
94  DISKPART="$ANS"
95}
96
97get_root_pw()
98{
99  while :
100  do
101    get_dlg_ans "--passwordbox 'Enter the root password' 8 30"
102    if [ -z "$ANS" ] ; then
103       exit_err "Invalid password entered!"
104    fi
105    ROOTPW="$ANS"
106    get_dlg_ans "--passwordbox 'Confirm root password' 8 30"
107    if [ -z "$ANS" ] ; then
108       exit_err "Invalid password entered!"
109    fi
110    ROOTPWCONFIRM="$ANS"
111    if [ "$ROOTPWCONFIRM" = "$ROOTPW" ] ; then break; fi
112    get_dlg_ans "--yesno 'Password Mismatch, try again?' 8 30"
113    if [ $? -eq 0 ] ; then continue ; fi
114    exit_err "Failed setting root password!"
115  done
116}
117
118get_user_pw()
119{
120  while :
121  do
122    get_dlg_ans "--passwordbox \"Enter the password for $USERNAME\" 8 40"
123    if [ -z "$ANS" ] ; then
124       exit_err "Invalid password entered!"
125    fi
126    USERPW="$ANS"
127    get_dlg_ans "--passwordbox 'Confirm password' 8 40"
128    if [ -z "$ANS" ] ; then
129       exit_err "Invalid password entered!"
130    fi
131    USERPWCONFIRM="$ANS"
132    if [ "$USERPWCONFIRM" = "$USERPW" ] ; then break; fi
133    get_dlg_ans "--yesno 'Password Mismatch, try again?' 8 30"
134    if [ $? -eq 0 ] ; then continue ; fi
135    exit_err "Failed setting password!"
136  done
137}
138
139get_user_name()
140{
141    get_dlg_ans "--inputbox 'Enter a username' 8 40"
142    if [ -z "$ANS" ] ; then
143       exit_err "Invalid username entered!"
144    fi
145    USERNAME="$ANS"
146}
147
148get_user_realname()
149{
150    get_dlg_ans "--inputbox \"Enter the real name for $USERNAME\" 8 40"
151    if [ -z "$ANS" ] ; then
152       exit_err "Invalid real name entered!"
153    fi
154    USERREALNAME="$ANS"
155}
156
157get_user_shell()
158{
159    get_dlg_ans "--menu \"Select the users shell\" 12 45 10 /bin/sh SH /bin/csh CSH /bin/tcsh TCSH /bin/bash BASH"
160    if [ -z "$ANS" ] ; then
161       exit_err "Invalid SHELL entered!"
162    fi
163    USERSHELL="$ANS"
164}
165
166gen_pc-sysinstall_cfg()
167{
168   # Start the header information
169   echo "# Auto-Generated pc-sysinstall configuration" >${CFGFILE}
170   echo "installInteractive=no" >>${CFGFILE}
171   echo "installMode=fresh" >>${CFGFILE}
172   if [ "$SYSTYPE" = "desktop" ] ; then
173     echo "installType=PCBSD" >>${CFGFILE}
174     echo "netSaveDev=AUTO-DHCP-SLAAC" >> ${CFGFILE}
175   else
176     echo "installType=FreeBSD" >>${CFGFILE}
177   fi
178   echo "packageType=dist" >> ${CFGFILE}
179   if [ "`uname -m`" = "amd64" ] ; then
180     echo "distFiles=base doc games kernel lib32" >> ${CFGFILE}
181   else
182     echo "distFiles=base doc games kernel" >> ${CFGFILE}
183   fi
184   echo "installMedium=local" >>${CFGFILE}
185   echo "localPath=/dist" >>${CFGFILE}
186
187   # Now do the disk block
188   echo "" >> ${CFGFILE}
189   echo "# Disk Setup for $SYSDISK" >> ${CFGFILE}
190   echo "disk0=$SYSDISK" >> ${CFGFILE}
191   echo "partition=$DISKPART" >> ${CFGFILE}
192   echo "bootManager=GRUB" >> ${CFGFILE}
193   echo "partscheme=$DISKFORMAT" >> ${CFGFILE}
194   echo "commitDiskPart" >> ${CFGFILE}
195
196   # Now the partition block
197   echo "" >> ${CFGFILE}
198   echo "# Partition Setup for ${SYSDISK}($DISKPART)" >> ${CFGFILE}
199   echo "# All sizes are expressed in MB" >> ${CFGFILE}
200   echo "# Avail FS Types, UFS, UFS+S, UFS+SUJ, UFS+J, ZFS, SWAP" >> ${CFGFILE}
201   echo "# UFS.eli, UFS+S.eli, UFS+SUJ, UFS+J.eli, ZFS.eli, SWAP.eli" >> ${CFGFILE}
202   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}
203   echo "disk0-part=SWAP 2000 none" >> ${CFGFILE}
204   echo "commitDiskLabel" >> ${CFGFILE}
205   echo "" >> ${CFGFILE}
206
207   # Now the packages
208   if [ "$SYSTYPE" = "desktop" ] ; then
209     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}
210     echo "" >> ${CFGFILE}
211     # Set our markers for desktop to run the first-time boot wizards
212     echo "runCommand=sh /usr/local/share/pcbsd/scripts/sys-init.sh desktop en_US" >> ${CFGFILE}
213     echo "runCommand=touch /var/.runxsetup" >> ${CFGFILE}
214     echo "runCommand=touch /var/.pcbsd-firstboot" >> ${CFGFILE}
215     echo "runCommand=touch /var/.pcbsd-firstgui" >> ${CFGFILE}
216   else
217     echo "installPackages=trueos-base" >> ${CFGFILE}
218     echo "" >> ${CFGFILE}
219     echo "runCommand=sh /usr/local/share/pcbsd/scripts/sys-init.sh server" >> ${CFGFILE}
220     echo "" >> ${CFGFILE}
221
222     # Since on TrueOS, lets save username / passwords
223     echo "rootPass=${ROOTPW}" >> ${CFGFILE}
224     echo "" >> ${CFGFILE}
225     echo "userName=${USERNAME}" >> ${CFGFILE}
226     echo "userPass=${USERPW}" >> ${CFGFILE}
227     echo "userShell=${USERSHELL}" >> ${CFGFILE}
228     echo "userHome=/home/${USERNAME}" >> ${CFGFILE}
229     echo "userGroups=wheel,operator" >> ${CFGFILE}
230     echo "commitUser" >> ${CFGFILE}
231
232     # KPM - TODO, add blocks to create network config, hostname / ssh settings
233   fi
234
235   # Last cleanup stuff
236   echo "" >> ${CFGFILE}
237   echo "runExtCmd=/root/save-config.sh" >> ${CFGFILE}
238   echo "runCommand=newaliases" >> ${CFGFILE}
239 
240 
241}
242
243change_disk_selection() {
244  get_target_disk
245  get_target_part
246  gen_pc-sysinstall_cfg
247}
248
249start_full_wizard() 
250{
251  # Start the wizard
252  get_sys_type
253  get_target_disk
254  get_target_part
255
256  # If doing a server setup, need to prompt for some more details
257  if [ "$SYSTYPE" = "server" ] ; then
258     get_root_pw
259     get_user_name
260     get_user_pw
261     get_user_realname
262     get_user_shell
263  fi
264  gen_pc-sysinstall_cfg
265}
266
267start_menu_loop()
268{
269
270  while :
271  do
272    dialog --title "PC-BSD Text Install" --menu "Please select from the following options:" 15 40 10 wizard "Run install wizard" disk "Change disk ($SYSDISK)" view "View install script" edit "Edit install script" install "Start the installation" quit "Quit install wizard" 2>/tmp/answer
273    if [ $? -ne 0 ] ; then break ; fi
274
275    ANS="`cat /tmp/answer`"
276
277    case $ANS in
278     wizard) start_full_wizard
279             rtn
280             ;;
281       disk) change_disk_selection
282             rtn
283             ;;
284       view) more ${CFGFILE}
285             rtn
286             ;;
287       edit) vi ${CFGFILE}
288             rtn
289             ;;
290    install) echo "This will begin the installation, continue?"
291             echo -e "(y/n)\c"
292             read tmp
293             if [ "$tmp" = "y" -o "$tmp" = "Y" ] ; then
294                pc-sysinstall -c ${CFGFILE}
295                rtn
296             fi
297             ;;
298       quit) break ;;
299          *) ;;
300    esac
301  done
302
303}
304
305
306
307if [ ! -e "$CFGFILE" ] ; then
308   cp ${CFGFILE} ${CFGFILE}.bak
309   rm ${CFGFILE}
310fi
311
312start_menu_loop
313
314exit 0
Note: See TracBrowser for help on using the repository browser.