source: src-sh/pc-installdialog/pc-installdialog.sh @ 0843d04d

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

Add a *VERY* basic text-frontend to "pc-sysinstall". This will
allow users to use text-mode to install PC-BSD / TrueOS. i

Still need to link it into the install media.

Over time this will evolve into a more full-featured installer, but
for now it gets us started.

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