]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - release/instdist.sh
This commit was generated by cvs2svn to compensate for changes in r4974,
[FreeBSD/FreeBSD.git] / release / instdist.sh
1 #!/stand/sh
2 #
3 # instdist - Install a distribution from some sort of media.
4 #
5 # Written:  November 11th, 1994
6 # Copyright (C) 1994 by Jordan K. Hubbard
7 #
8 # Permission to copy or use this software for any purpose is granted
9 # provided that this message stay intact, and at this location (e.g. no
10 # putting your name on top after doing something trivial like reindenting
11 # it, just to make it look like you wrote it!).
12 #
13 # $Id: instdist.sh,v 1.40 1994/12/02 21:15:19 jkh Exp $
14
15 if [ "${_INSTINST_SH_LOADED_}" = "yes" ]; then
16         return 0
17 else
18         _INSTINST_SH_LOADED_=yes
19 fi
20
21 # Grab the miscellaneous functions.
22 . /stand/miscfuncs.sh
23
24 # Set the initial state for media installation.
25 media_set_defaults()
26 {
27         MEDIA_TYPE=""
28         MEDIA_DEVICE=""
29         MEDIA_DISTRIBUTION=""
30         DISTRIB_SUBDIR=""
31         TMPDIR="/usr/tmp"
32         FTP_PATH=""
33         NFS_PATH=""
34 }
35
36 # Set the installation media to undefined.
37 media_reset()
38 {
39         MEDIA_DEVICE=""
40         MEDIA_TYPE=""
41         MEDIA_DISTRIBUTION=""
42         FTP_PATH=""
43         NFS_PATH=""
44         NFS_OPTIONS=""
45 }
46
47 # Set the location of our temporary unpacking directory.
48 media_set_tmpdir()
49 {
50         TITLE="Choose temporary directory"
51         DEFAULT_VALUE="${TMPDIR}"
52         if ! input \
53 "Please specify the name of a directory containing enough free
54 space to hold the temporary files for this distribution.  At
55 minimum, a binary distribution will require around 21MB of
56 temporary space.  At maximum, a srcdist may take 30MB or more.
57 If the directory you specify does not exist, it will be created
58 for you.  If you do not have enough free space to hold both the
59 packed and unpacked distribution files, consider using the NFS
60 or CDROM installation methods as they require no temporary
61 storage."; then return 1; fi
62         TMPDIR=${ANSWER}
63         mkdir -p ${TMPDIR}
64         return 0
65 }
66
67 media_cd_tmpdir()
68 {
69         if ! cd ${TMPDIR} > /dev/ttyv1 2>&1; then
70                 error "No such file or directory for ${TMPDIR}, sorry!  Please fix this and try again."
71                 return 1
72         fi
73 }
74
75 media_rm_tmpdir()
76 {
77         cd /
78         if [ -d ${TMPDIR}/${MEDIA_DISTRIBUTION} ]; then
79                 if dialog --title "Delete contents?" --yesno \
80                   "Do you wish to delete ${TMPDIR}/${MEDIA_DISTRIBUTION}?" -1 -1; then
81                         rm -rf ${TMPDIR}/${MEDIA_DISTRIBUTION}
82                 fi
83         else
84                 if dialog --title "Delete contents?" --yesno \
85                   "Do you wish to delete the contents of ${TMPDIR}?" -1 -1; then
86                         rm -rf ${TMPDIR}/*
87                 fi
88         fi
89 }
90
91 media_select_ftp_site()
92 {
93         dialog --title "Please specify an ftp site" --menu \
94 "FreeBSD is distributed from a number of sites on the Internet.\n\
95 Please select the site closest to you or \"other\" if you'd like\n\
96 to specify another choice.  Also note that not all sites carry\n\
97 every possible distribution!  Distributions other than the basic\n\
98 binary set are only guaranteed to be available from the Primary site." \
99 -1 -1 5 \
100    "Primary" "ftp://ftp.freebsd.org/pub/FreeBSD/${DISTNAME}" \
101    "U.S-2" "ftp://ftp.dataplex.net/pub/FreeBSD/${DISTNAME}" \
102    "U.S-3" "ftp://kryten.atinc.com/pub/FreeBSD/${DISTNAME}" \
103    "U.S-4" "ftp://ref.tfs.com/pub/FreeBSD/${DISTNAME}" \
104    "Holland" "ftp://ftp.nl.net:/pub/os/FreeBSD/${DISTNAME}" \
105    "Israel" "ftp://orgchem.weizmann.ac.il/pub/FreeBSD-${DISTNAME}" \
106    "Taiwan" "ftp://netbsd.csie.nctu.edu.tw/pub/FreeBSD/${DISTNAME}" \
107    "Australia" "ftp://ftp.physics.usyd.edu.au/FreeBSD/${DISTNAME}" \
108    "France" "ftp://ftp.ibp.fr/pub/FreeBSD/${DISTNAME}" \
109    "Finland" "ftp://nic.funet.fi:/pub/unix/FreeBSD/${DISTNAME}" \
110    "Russia" "ftp://ftp.kiae.su/FreeBSD/${DISTNAME}" \
111    "Japan" "ftp://ftp.sra.co.jp/pub/os/FreeBSD/distribution/${DISTNAME}" \
112    "Japan-2" "ftp://ftp.mei.co.jp/free/PC-UNIX/FreeBSD/${DISTNAME}" \
113    "Japan-3" "ftp://ftp.waseda.ac.jp/pub/FreeBSD/${DISTNAME}" \
114    "Japan-4" "ftp://ftp.pu-toyama.ac.jp/pub/FreeBSD/${DISTNAME}" \
115    "Japan-5" "ftp://ftpsv1.u-aizu.ac.jp/pub/os/FreeBSD/${DISTNAME}" \
116    "other" "None of the above.  I want to specify my own." \
117       2> ${TMP}/menu.tmp.$$
118         RETVAL=$?
119         ANSWER=`cat ${TMP}/menu.tmp.$$`
120         rm -f ${TMP}/menu.tmp.$$
121         if ! handle_rval ${RETVAL}; then return 1; fi
122    case ${ANSWER} in
123    Primary) FTP_PATH="ftp://ftp.freebsd.org/pub/FreeBSD/${DISTNAME}" ;;
124    U.S-2) FTP_PATH="ftp://ftp.dataplex.net/pub/FreeBSD/${DISTNAME}" ;;
125    U.S-3) FTP_PATH="ftp://kryten.atinc.com/pub/FreeBSD/${DISTNAME}" ;;
126    U.S-4) FTP_PATH="ftp://ref.tfs.com/pub/FreeBSD/${DISTNAME}" ;;
127    Holland) FTP_PATH="ftp://ftp.nl.net:/pub/os/FreeBSD/${DISTNAME}" ;;
128    Israel) FTP_PATH="ftp://orgchem.weizmann.ac.il/pub/FreeBSD-${DISTNAME}" ;;
129    Taiwan) FTP_PATH="ftp://netbsd.csie.nctu.edu.tw/pub/FreeBSD/${DISTNAME}" ;;
130    Australia) FTP_PATH="ftp://ftp.physics.usyd.edu.au/FreeBSD/${DISTNAME}" ;;
131    France) FTP_PATH="ftp://ftp.ibp.fr/pub/FreeBSD/${DISTNAME}" ;;
132    Finland) FTP_PATH="ftp://nic.funet.fi:/pub/unix/FreeBSD/${DISTNAME}" ;;
133    Japan) FTP_PATH="ftp://ftp.sra.co.jp/pub/os/FreeBSD/distribution/${DISTNAME}" ;;
134    Japan-2) FTP_PATH="ftp://ftp.mei.co.jp/free/PC-UNIX/FreeBSD/${DISTNAME}" ;;
135    Japan-3) FTP_PATH="ftp://ftp.waseda.ac.jp/pub/FreeBSD/${DISTNAME}" ;;
136    Japan-4) FTP_PATH="ftp://ftp.pu-toyama.ac.jp/pub/FreeBSD/${DISTNAME}" ;;
137    Japan-5) FTP_PATH="ftp://ftpsv1.u-aizu.ac.jp/pub/os/FreeBSD/${DISTNAME}" ;;
138    Russia) FTP_PATH="ftp://ftp.kiae.su/FreeBSD/${DISTNAME}" ;;
139    other)
140         TITLE="FTP Installation Information"
141         DEFAULT_VALUE="${FTP_PATH}"
142         if ! input \
143 "Please specify the machine and directory location of the
144 distribution you wish to load.  This should be either a \"URL style\"
145 specification (e.g. ftp://ftp.freeBSD.org/pub/FreeBSD/...) or simply
146 the name of a host to connect to.  If only a host name is specified,
147 the installation assumes that you will properly connect and \"mget\"
148 the files yourself."; then return 1; fi
149         FTP_PATH=${ANSWER}
150    ;;
151    esac
152 }
153
154 media_extract_dist()
155 {
156         if [ -f do_cksum.sh ]; then
157                 message "Verifying checksums for distribution.  Please wait!"
158                 if sh ./do_cksum.sh; then
159                         if [ -f extract.sh ]; then
160                                 message "Extracting ${MEDIA_DISTRIBUTION} distribution.  Please wait!"
161                                 if [ -f ./is_interactive ]; then
162                                         sh ./extract.sh
163                                 else
164                                         sh ./extract.sh < /dev/ttyv1 > /dev/ttyv1 2>&1
165                                 fi
166                                 dialog --title "Extraction Complete" --msgbox "Please press return to continue" -1 -1
167                         else
168                                 error "No installation script found!"
169                         fi
170                 else
171                         error "Checksum error(s) found.  Please check media!"
172                 fi
173         else    
174                 error "Improper distribution.  No checksum script found!"
175                 media_reset
176         fi
177 }
178
179 media_install_set()
180 {
181         case ${MEDIA_TYPE} in
182         cdrom|nfs|ufs|doshd)
183                 if ! cd ${MEDIA_DEVICE}/${MEDIA_DISTRIBUTION} > /dev/ttyv1 2>&1; then
184                         error "Unable to cd to ${MEDIA_DEVICE}/${MEDIA_DISTRIBUTION} directory."
185                         media_reset
186                 else
187                         media_extract_dist
188                         cd /
189                 fi
190                 return
191         ;;
192
193         tape)
194                 if ! media_set_tmpdir; then return; fi
195                 if ! media_cd_tmpdir; then return; fi
196                 if dialog --title "Please mount tape for ${MEDIA_DEVICE}." \
197                   --yesno "Please enter the next tape and select\n<Yes> to continue or <No> if finished" -1 -1; then
198                         message "Loading distribution from ${MEDIA_DEVICE}.\nUse ALT-F2 to see output, ALT-F1 to return."
199                         if [ "${MEDIA_DEVICE}" = "ftape" ]; then
200                                 progress "${FT_CMD} | ${TAR_CMD} ${TAR_FLAGS} -"
201                                 ${FT_CMD} | ${TAR_CMD} ${TAR_FLAGS} - > /dev/ttyv1 2>&1
202                         else
203                                 progress "${TAR_CMD} ${TAR_FLAGS} ${MEDIA_DEVICE}"
204                                 ${TAR_CMD} ${TAR_FLAGS} ${MEDIA_DEVICE} > /dev/ttyv1 2>&1
205                         fi
206                 fi
207                 if [ -d ${MEDIA_DISTRIBUTION} ]; then cd ${MEDIA_DISTRIBUTION}; fi
208                 media_extract_dist
209                 media_rm_tmpdir
210         ;;
211
212         dosfd)
213                 if ! media_set_tmpdir; then return; fi
214                 if ! media_cd_tmpdir; then return; fi
215                 COPYING="yes"
216                 progress "Preparing to extract from DOS floppies"
217                 while [ "${COPYING}" = "yes" ]; do
218                         progress "Asking for DOS diskette"
219                         if dialog --title "Insert distribution diskette" \
220                           --yesno "Please enter the next diskette and select\n<Yes> to continue or <No> if finished" -1 -1; then
221                                 umount ${MNT} > /dev/null 2>&1
222                                 if ! mount_msdos -o ro ${MEDIA_DEVICE} ${MNT}; then
223                                         error "Unable to mount floppy!  Please correct."
224                                 else
225                                         message "Loading distribution from ${MEDIA_DEVICE}.\nUse ALT-F2 to see output, ALT-F1 to return."
226                                         ( ${TAR_CMD} -cf - -C ${MNT} . | ${TAR_CMD} -xvf - ) >/dev/ttyv1 2>&1
227                                         umount ${MNT}
228                                 fi
229                         else
230                                 COPYING="no"
231                         fi
232                 done
233                 media_extract_dist
234                 media_rm_tmpdir
235                 return
236         ;;
237
238         ftp)
239                 if ! media_set_tmpdir; then return; fi
240                 if ! media_cd_tmpdir; then return; fi
241                 if ! echo ${MEDIA_DEVICE} | grep -q -v 'ftp://'; then
242                         message "Fetching distribution using ncftp.\nUse ALT-F2 to see output, ALT-F1 to return."
243                         if ! ncftp ${MEDIA_DEVICE}/${MEDIA_DISTRIBUTION}/* < /dev/null > /dev/ttyv1 2>&1; then
244                                 error "Couldn't fetch ${MEDIA_DISTRIBUTION} distribution from\n${MEDIA_DEVICE}!"
245                         else
246                                 media_extract_dist
247                         fi
248                 else
249                         dialog --clear
250                         ftp ${MEDIA_DEVICE}
251                         dialog --clear
252                         media_extract_dist
253                 fi
254                 media_rm_tmpdir
255                 return
256         ;;
257         esac
258 }
259
260 media_select_distribution()
261 {
262         MEDIA_DISTRIBUTION=""
263         while [ "${MEDIA_DISTRIBUTION}" = "" ]; do
264
265         dialog --title "Please specify a distribution to load" \
266         --menu \
267 "FreeBSD is separated into a number of distributions for ease of\n\
268 installation.  With repeated passes through this screen, you'll be\n\
269 given the chance to load one or all of them.  Mandatory distributions\n\
270 MUST be loaded!  Please also note that the secrdist is NOT FOR EXPORT\n\
271 from the U.S.  Please don't endanger U.S. ftp sites by getting it\n\
272 illegally, thanks!  When finished, select <Cancel>." \
273 -1 -1 10 \
274   "?diskfree"  "How much disk space do I have free?" \
275   "bindist" "Binary base files (mandatory - ${BINSIZE})" \
276   "games" "Games and other frivolities (optional - ${GAMESIZE})" \
277   "manpages" "Manual pages (optional - ${MANSIZE})" \
278   "proflibs" "Profiled libraries (optional - ${PROFSIZE})" \
279   "dict" "Spelling checker dictionary files (optional - ${DICTSIZE})" \
280   "srcdist" "Sources for everything but DES (optional - ${SRCSIZE})" \
281   "secrdist" "DES encryption code (and sources) (optional - ${SECRSIZE})" \
282   "compat1xdist" "FreeBSD 1.x binary compatability (optional - ${COMPATSIZE})" \
283   "XFree86-3.1" "The XFree86 3.1 distribution (optional - ${X11SIZE})" \
284      2> ${TMP}/menu.tmp.$$
285         RETVAL=$?
286         MEDIA_DISTRIBUTION=`cat ${TMP}/menu.tmp.$$`
287         rm -f ${TMP}/menu.tmp.$$
288         if ! handle_rval ${RETVAL}; then return 1; fi
289         if [ "${MEDIA_DISTRIBUTION}" = "?diskfree" ]; then
290                 if df -k > ${TMP}/df.out; then
291                         dialog --title "How much free space do I have?" \
292                           --textbox ${TMP}/df.out 15 76
293                 else
294                         error "Couldn't get disk usage information! :-("
295                 fi
296                 MEDIA_DISTRIBUTION=""
297         fi
298         done
299 }
300
301 media_get_possible_subdir()
302 {
303         if [ -f ${MNT}/${MEDIA_DISTRIBUTION}/extract.sh ]; then return; fi
304         DEFAULT_VALUE="${DISTRIB_SUBDIR}"
305         TITLE="Distribution Subdirectory"
306         if input \
307 "If the distributions are in a subdirectory of the mount point,
308 please enter it here (no leading slash - it should be relative
309 to the mount point).  The directory you enter should be the
310 *parent* directory of any distribution subdirectories."; then
311                 if [ "${ANSWER}" != "" ]; then
312                         MEDIA_DEVICE=${MEDIA_DEVICE}/${ANSWER}
313                         DISTRIB_SUBDIR=${ANSWER}
314                 fi
315         else
316                 return 1
317         fi
318 }
319
320 # Get values into $MEDIA_TYPE and $MEDIA_DEVICE.  Call network initialization
321 # if necessary.
322 media_chose()
323 {
324         while [ "${MEDIA_DEVICE}" = "" ]; do
325
326         dialog --title "Installation From" \
327 --menu \
328 "Before installing a distribution, you need to chose and/or configure\n\
329 a method of installation.  Please pick from one of the following options.\n\
330 If none of the listed options works for you, then your best bet may be to\n\
331 simply hit ESC twice to get a subshell and proceed manually on your own.\n\
332 If you are already finished with the installation process, select cancel\n\
333 to proceed." -1 -1 7 \
334         "?Kern" "Please show me the kernel boot messages again!" \
335         "Tape" "Load distribution from SCSI, QIC-02 or floppy tape" \
336         "CDROM" "Load distribution from SCSI or Mitsumi CDROM" \
337         "DOS" "Load from DOS floppies or a DOS hard disk partition" \
338         "FTP" "Load distribution using FTP" \
339         "UFS" "Load the distribution from existing UFS partition" \
340         "NFS" "Load the distribution over NFS" 2> ${TMP}/menu.tmp.$$
341         RETVAL=$?
342         CHOICE=`cat ${TMP}/menu.tmp.$$`
343         rm -f ${TMP}/menu.tmp.$$
344         if ! handle_rval ${RETVAL}; then return 1; fi
345
346         case ${CHOICE} in
347         ?Kern)
348                 if dmesg > ${TMP}/dmesg.out; then
349                         dialog --title "Kernel boot message output" \
350                           --textbox ${TMP}/dmesg.out 22 76
351                 else
352                         error "Couldn't get dmesg information! :-("
353                 fi
354         ;;
355
356         Tape)
357                 dialog --title "Choose Tape Type" --menu \
358 "Which type of tape drive do you have attached to your \n\
359 system?  FreeBSD supports the following types:\n" -1 -1 3 \
360                 "SCSI" "SCSI tape drive attached to supported SCSI controller" \
361                 "QIC-02" "QIC-02 tape drive (Colorado Jumbo, etc)" \
362                 "floppy" "Floppy tape drive (QIC-40/QIC-80)" 2> ${TMP}/menu.tmp.$$
363                 RETVAL=$?
364                 CHOICE=`cat ${TMP}/menu.tmp.$$`
365                 rm -f ${TMP}/menu.tmp.$$
366                 if ! handle_rval ${RETVAL}; then continue; fi
367                 MEDIA_TYPE=tape;
368                 case ${CHOICE} in
369                         SCSI)
370                                 MEDIA_DEVICE=/dev/rst0
371                         ;;
372
373                         QIC-02)
374                                 MEDIA_DEVICE=/dev/rwt0
375                         ;;
376
377                         floppy)
378                                 MEDIA_DEVICE=ftape
379                         ;;
380                 esac
381         ;;
382
383         CDROM)
384                 dialog --title "Choose CDROM Type" --menu \
385 "Which type of CDROM drive do you have attached to your \n\
386 system?  FreeBSD supports the following types:\n" -1 -1 2 \
387                 "SCSI" "SCSI CDROM drive attached to supported SCSI controller" \
388                 "Mitsumi" "Mitsumi CDROM drive" \
389                         2> ${TMP}/menu.tmp.$$
390                 RETVAL=$?
391                 CHOICE=`cat ${TMP}/menu.tmp.$$`
392                 rm -f ${TMP}/menu.tmp.$$
393                 if ! handle_rval ${RETVAL}; then continue; fi
394                 MEDIA_TYPE=cdrom;
395                 case ${CHOICE} in
396                         SCSI)
397                                 MEDIA_DEVICE=/dev/cd0a
398                         ;;
399                         Mitsumi)
400                                 MEDIA_DEVICE=/dev/mcd0a
401                         ;;
402                 esac
403                 umount ${MNT} > /dev/null 2>&1
404                 if ! mount_cd9660 ${MEDIA_DEVICE} ${MNT} > /dev/ttyv1 2>&1; then
405                         error "Unable to mount ${MEDIA_DEVICE} on ${MNT}"
406                         MEDIA_DEVICE=""
407                 else
408                         MEDIA_DEVICE=${MNT}
409                         media_get_possible_subdir
410                         return 0
411                 fi
412         ;;
413
414         DOS)
415                 DEFAULT_VALUE="/dev/fd0"
416                 if input \
417 "Please specify the device pointing at your DOS partition or
418 floppy media.  For a hard disk, this might be something like
419 /dev/wd0h or /dev/sd0h (as identified in the disklabel editor).
420 For the "A" floppy drive, it's /dev/fd0, for the "B" floppy
421 drive it's /dev/fd1\n"; then
422                         MEDIA_DEVICE=${ANSWER}
423                         if echo ${MEDIA_DEVICE} | grep -q -v fd; then
424                                 umount ${MNT} > /dev/null 2>&1
425                                 if ! mount_msdos ${MEDIA_DEVICE} ${MNT} > /dev/ttyv1 2>&1; then
426                                         error "Unable to mount ${MEDIA_DEVICE}"
427                                         MEDIA_DEVICE=""
428                                 else
429                                         MEDIA_TYPE=doshd
430                                         MEDIA_DEVICE=${MNT}
431                                         media_get_possible_subdir
432                                         return 0
433                                 fi
434                         else
435                                 MEDIA_TYPE=dosfd
436                                 return 0
437                         fi
438                 fi
439         ;;
440
441         FTP)
442                 if ! network_setup; then continue; fi
443                 if media_select_ftp_site; then
444                         MEDIA_TYPE=ftp
445                         MEDIA_DEVICE=${FTP_PATH}
446                         return 0
447                 fi
448         ;;
449
450         NFS)
451                 if ! network_setup; then continue; fi
452                 TITLE="NFS Installation Information"
453                 DEFAULT_VALUE="${NFS_PATH}"
454                 if ! input \
455 "Please specify a machine and directory mount point for the
456 distribution you wish to load.  This must be in machine:dir
457 format (e.g. zooey:/a/FreeBSD/${DISTNAME}).  The remote
458 directory *must* be be exported to your machine (or globally)
459 for this to work!\n"; then continue; fi
460                 NFS_PATH=${ANSWER}
461
462                 DEFAULT_VALUE="${NFS_OPTIONS}"
463                 if input \
464 "Do you wish to specify any options to NFS?  If you're installing
465 from a Sun 4.1.x system, you may wish to specify \`-o resvport' to send
466 NFS requests over a privileged port (use this if you get nasty
467 \`\`credential too weak'' errors from the server).  When using a slow
468 ethernet card or network link, \`-o -r=1024,-w=1024' may also prove helpful.
469 Options, if any, should be separated by commas."; then
470                         if [ "${ANSWER}" != "" ]; then
471                                 NFS_OPTIONS="${ANSWER}"
472                         fi
473                 fi
474                 MEDIA_TYPE=nfs
475                 umount ${MNT} > /dev/null 2>&1
476                 if ! mount_nfs ${NFS_OPTIONS} ${NFS_PATH} ${MNT} > /dev/ttyv1 2>&1; then
477                         error "Unable to mount ${NFS_PATH}"
478                 else
479                         message "${NFS_PATH} mounted successfully"
480                         MEDIA_DEVICE=${MNT}
481                         media_get_possible_subdir
482                         return 0
483                 fi
484         ;;
485
486         UFS)
487                 dialog --title "User Intervention Requested" --msgbox "
488 Please mount the filesystem you wish to use somewhere convenient and
489 exit the shell when you're through.  I'll ask you for the location
490 of the distribution's parent directory when we come back." -1 -1
491                 dialog --clear
492                 /stand/sh
493                 TITLE="Please enter directory"
494                 DEFAULT_VALUE="${MNT}"
495                 if input "Ok, now give me the full pathname of the parent directorys for the distribution(s)."; then
496                         MEDIA_TYPE=ufs
497                         MEDIA_DEVICE=${ANSWER}
498                         return 0
499                 fi
500         ;;
501         esac
502         done
503 }