]> git.ozlabs.org Git - yaboot.git/blob - ybin/ybin
Remove devel debugging code
[yaboot.git] / ybin / ybin
1 #! /bin/sh
2
3 ###############################################################################
4 ##
5 ## ybin (YaBoot INstaller) installs/updates the yaboot bootloader.
6 ## Copyright (C) 2000, 2001, 2002, 2003 Ethan Benson
7 ##
8 ## This program is free software; you can redistribute it and/or
9 ## modify it under the terms of the GNU General Public License
10 ## as published by the Free Software Foundation; either version 2
11 ## of the License, or (at your option) any later version.
12 ##
13 ## This program is distributed in the hope that it will be useful,
14 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 ## GNU General Public License for more details.
17 ##
18 ## You should have received a copy of the GNU General Public License
19 ## along with this program; if not, write to the Free Software
20 ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21 ##
22 ###############################################################################
23
24 PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin"
25 ## allow to run out of /target in boot-floppies
26 if [ -n "$PATH_PREFIX" ] ; then
27     PATH="${PATH}:${PATH_PREFIX}/sbin:${PATH_PREFIX}/bin:${PATH_PREFIX}/usr/sbin:${PATH_PREFIX}/usr/bin:${PATH_PREFIX}/usr/local/sbin:${PATH_PREFIX}/usr/local/bin"
28 fi
29 PRG="${0##*/}"
30 ABSPRG="$0"
31 SIGINT="$PRG: Interrupt caught ... exiting"
32 VERSION=1.3.13
33 DEBUG=0
34 VERBOSE=0
35 TMP="${TMPDIR:-/tmp}"
36 export LC_COLLATE=C
37
38 ## avoid older versions of ofpath shipped in debian boot-floppies etc.
39 if [ -x "${PATH_PREFIX}/usr/sbin/ofpath" ] ; then
40     OFPATH="${PATH_PREFIX}/usr/sbin/ofpath"
41 else
42     OFPATH=ofpath
43 fi
44
45 ## catch signals, clean up junk in /tmp.
46 trap "cleanup" 0
47 trap "exit 129" 1
48 trap "echo 1>&2 $SIGINT ; exit 130" 2
49 trap "exit 131" 3
50 trap "exit 143" 15
51
52 ## allow for non-existent config file, in which case it will be
53 ## generated from command line arguments.
54 if [ -f /etc/yaboot.conf ] ; then
55     CONF=/etc/yaboot.conf
56     bootconf=$CONF
57     ERR=" Error in $CONF:"
58 else
59     CONF=/dev/null
60     bootconf=/dev/null
61 fi
62
63 ## define default configuration
64 boot=unconfigured
65
66 ## allow default to work on packaged and non-packaged yaboot.
67 ## no default for magicboot since it is not required everywhere.
68 if [ -f /usr/local/lib/yaboot/yaboot ] ; then
69     install=/usr/local/lib/yaboot/yaboot
70 elif [ -f /usr/lib/yaboot/yaboot ] ; then
71     install=/usr/lib/yaboot/yaboot
72 fi
73
74 ## defaults
75 usemount=no
76 if (cat /proc/cpuinfo 2> /dev/null | grep ^machine | grep -q 'CHRP IBM') ; then
77     fstype=raw
78 else
79     fstype=hfs
80 fi
81 hfstype=tbxi
82 hfscreator=UNIX
83 bless=yes
84 protect=no
85 hide=no
86 nonvram=0
87 defaultos=linux
88 brokenosx=no
89 cdrom=no
90 network=no
91 of=no
92 fgcolor=white
93 bgcolor=black
94
95 ## yaboot autoconf defaults
96 label=Linux
97 timeout=40
98 image=/vmlinux
99 partition=3
100 root=/dev/hda3
101 device=hd:
102
103 ## this program behaves differently based on how its called, this
104 ## ensures that nothing nasty happens if someone makes a bogus
105 ## symlink.
106 case "$PRG" in
107     ybin)
108     ;;
109     mkofboot)
110     ;;
111     *)
112     echo 1>&2 "This program must be called as either \`ybin' or \`mkofboot'"
113     exit 1
114     ;;
115 esac
116
117 ## check for printf, use it if possible otherwise fall back on
118 ## unreliable echo -e -n ("SUS" says echo shall support no switches)
119 if [ "$(printf printf_test 2>/dev/null)" = printf_test ] ; then
120     PRINTF=printf
121 else
122     PRINTF="echo -e -n"
123 fi
124
125 ## make fake `id' if its missing, outputs 0 since if its missing we
126 ## are probably running on boot floppies and thus are root.
127 if (command -v id > /dev/null 2>&1) ; then
128     true
129 else
130     id()
131     {
132     echo 0
133     }
134 fi
135
136 ## --version output
137 version()
138 {
139 echo \
140 "$PRG $VERSION
141 Written by Ethan Benson
142
143 Copyright (C) 2000, 2001, 2002, 2003 Ethan Benson
144 This is free software; see the source for copying conditions.  There is NO
145 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
146 }
147
148 ## --help output.
149 usage()
150 {
151 echo \
152 "Usage: $PRG [OPTION]...
153 Update/install bootloader onto a bootstrap partition.
154
155   -b, --boot                 set bootstrap partition device [ -b /dev/hda2 ]
156   -o, --ofboot               set bootstrap partition OpenFirmware device
157                                default: automatically determined [ -o hd:2 ]
158   -i, --install              pathname to the actual bootloader binary
159                                default: /usr/{local/}lib/yaboot/yaboot same as
160                                install= in config file [ -i bootloader_file ]
161   -C, --config               use alternate configuration file (ybin and yaboot)
162                                [ -C config_file ]
163   -m, --magicboot            pathname to a OpenFirmware magicboot (CHRP) script
164       --filesystem           set the filesystem type of the bootstrap partition
165                                available options are hfs, msdos, and raw
166                                [ --filesystem hfs ] default is hfs
167       --nobless              don't bless the root directory, this should only
168                                be used if you are using a MacOS boot partition
169                                as the bootstrap partition (not recommended)
170   -M, --mount                don't use userspace hfsutils to modify the
171                                bootstrap instead try and mount the filesystem
172                                directly.  Note that attributes cannot be set
173                                this way and you will have to manually modify
174                                OpenFirmware to make your system bootable
175       --protect              set the read-only (locked) bit on all bootstrap
176                                files
177       --hide                 set the invisible bit on all bootstrap files
178                                this is useful of you don't want them to be
179                                visible from MacOS.
180       --nonvram              do not update the boot-device variable in nvram.
181       --force                don't ever ask for confirmation
182   -v, --verbose              make $PRG more verbose
183       --debug                print boring junk only useful for debugging
184   -h, --help                 display this help and exit
185   -V, --version              output version information and exit"
186 }
187
188 ## configuration file parsing. FIXME: need a method which can parse
189 ## image= sections.
190 parseconf()
191 {
192 case "$1" in
193     str)
194        v=`grep "^$2[\ ,=]" "$CONF"` ; echo "${v#*=}"
195        ;;
196     flag)
197        grep "^$2\>" "$CONF" > /dev/null && echo 0 || echo 1
198        ;;
199     ck)
200        grep "^$2[\ ,=]" "$CONF" > /dev/null && echo 0 || echo 1
201        ;;
202 esac
203 }
204
205 ## check for existence of a configuration file, and make sure we have
206 ## read permission.
207 confexist()
208 {
209     if [ ! -e "$CONF" ] ; then
210         echo 1>&2 "$PRG: $CONF: No such file or directory"
211         return 1
212     elif [ ! -f "$CONF" ] ; then
213         echo 1>&2 "$PRG: $CONF: Not a regular file"
214         return 1
215     elif [ ! -r "$CONF" ] ; then
216         echo 1>&2 "$PRG: $CONF: Permission denied"
217         return 1
218     else
219         return 0
220     fi
221 }
222
223 ## check to make sure the configuration file is sane and correct.
224 ## maybe this is an insane ammount of error checking, but I want to
225 ## make sure (hopfully) nothing unexpected ever happens.  and i just
226 ## like useful errors from programs.  every error just marks an error
227 ## variable so we give the user as much info as possible before we
228 ## abandon ship.
229 checkconf()
230 {
231     if [ ! -e "$boot" ] ; then
232         echo 1>&2 "$PRG: $boot: No such file or directory"
233         local CONFERR=1
234     elif [ ! -b "$boot" -a ! -f "$boot" ] ; then
235         echo 1>&2 "$PRG: $boot: Not a regular file or block device"
236         local CONFERR=1
237     elif [ ! -w "$boot" -o ! -r "$boot" ] ; then
238         [ -z "$mntpoint" ] && echo 1>&2 "$PRG: $boot: Permission denied"
239         [ -z "$mntpoint" ] && CONFERR=1
240     fi
241
242     if [ ! -e "$install" ] ; then
243         echo 1>&2 "$PRG: $install: No such file or directory"
244         local CONFERR=1
245     elif [ ! -f "$install" ] ; then
246         echo 1>&2 "$PRG: $bootconf: Not a regular file"
247         local CONFERR=1
248     elif [ ! -r "$install" ] ; then
249         echo 1>&2 "$PRG: $install: Permission denied"
250         local CONFERR=1
251     fi
252
253     if [ "$bootconf" = auto ] ; then
254         true
255     elif [ ! -e "$bootconf" ] ; then
256         echo 1>&2 "$PRG: $bootconf: No such file or directory"
257         local CONFERR=1
258     elif [ ! -f "$bootconf" ] ; then
259         echo 1>&2 "$PRG: $bootconf: Not a regular file"
260         local CONFERR=1
261     elif [ ! -r "$bootconf" ] ; then
262         echo 1>&2 "$PRG: $bootconf: Permission denied"
263         local CONFERR=1
264     fi
265
266     if [ -n "$magicboot" ] ; then
267         if [ ! -e "$magicboot" ] ; then
268             echo 1>&2 "$PRG: $magicboot: No such file or directory"
269             local CONFERR=1
270         elif [ ! -f "$magicboot" ] ; then
271             echo 1>&2 "$PRG: $magicboot: Not a regular file"
272             local CONFERR=1
273         elif [ ! -r "$magicboot" ] ; then
274             echo 1>&2 "$PRG: $magicboot: Permission denied"
275             local CONFERR=1
276         fi
277     fi
278
279     case "$fstype" in
280         hfs|msdos|raw)
281          ;;
282         *)
283          if [ "$ARGFS" = 1 ] ; then
284             echo 1>&2 "$PRG: --filesystem must be either \`hfs', \`msdos', or \`raw'"
285          else
286             echo 1>&2 "$PRG:$ERR \`fstype' must be either \`hfs', \`msdos', or \`raw'"
287          fi
288          local CONFERR=1
289          ;;
290     esac
291
292     ## if we are not using HFS filesystems we don't care about HFS
293     ## specific options.
294     if [ "$fstype" = hfs ] ; then
295         if [ `echo ${#hfstype}` != 4 ] ; then
296             if [ "$ARGTP" = 1 ] ; then
297                 echo 1>&2 "$PRG: --type must be 4 characters"
298             else
299                 echo 1>&2 "$PRG:$ERR \`hfstype' must be 4 characters"
300             fi
301             local CONFERR=1
302         fi
303
304         if [ `echo ${#hfscreator}` != 4 ] ; then
305             if [ "$ARGCT" = 1 ] ; then
306                 echo 1>&2 "$PRG: --creator must be 4 characters"
307             else
308                 echo 1>&2 "$PRG:$ERR \`hfscreator' must be 4 characters"
309             fi
310             local CONFERR=1
311         fi
312     fi
313
314     ## some options are not compatible with fstype=raw
315     if [ "$fstype" = raw ] ; then
316         if [ -n "$mntpoint" ] ; then
317             echo 1>&2 "$PRG:$ERR \`mntpoint' is not compatible with fstype=raw"
318             local CONFERR=1
319         fi
320         if [ "$usemount" = yes ] ; then
321             echo 1>&2 "$PRG:$ERR \`usemount' is not compatible with fstype=raw"
322             local CONFERR=1
323         fi
324         if [ -n "$magicboot" ] ; then
325             echo 1>&2 "$PRG:$ERR \`magicboot' scripts cannot be used with fstype=raw"
326             local CONFERR=1
327         fi
328     fi
329
330     if [ -n "$mntpoint" ] ; then
331         ## standard checks
332         if [ ! -e "$mntpoint" ] ; then
333             echo 1>&2 "$PRG: $mntpoint: No such file or directory"
334             local CONFERR=1
335         elif [ ! -d "$mntpoint" ] ; then
336             echo 1>&2 "$PRG: $mntpoint: Not a directory"
337             local CONFERR=1
338         elif [ ! -w "$mntpoint" -o ! -r "$mntpoint" ] ; then
339             echo 1>&2 "$PRG: $mntpoint: Permission denied"
340             local CONFERR=1
341         elif [ ! -O "$mntpoint" -a `id -u` != 0 ] ; then
342             echo 1>&2 "$PRG: $mntpoint: Permission denied (not owner)"
343             local CONFERR=1
344         fi
345
346         ## make sure no embedded spaces exist
347         echo "$mntpoint" | grep -q [[:space:]]
348         if [ $? = 0 ] ; then
349             echo 1>&2 "$PRG:$ERR \`mntpoint=$mntpoint' contains embedded spaces, don't use lame filenames"
350             local CONFERR=1
351         fi
352
353         ## make sure $mntpoint is on $boot, this matters to nvram updating.
354         if [ "$(v=`df "$mntpoint" 2> /dev/null | grep ^/dev/` ; echo ${v%%[ ]*})" != "$boot" -a -d "$mntpoint" ] ; then
355             echo 1>&2 "$PRG: $mntpoint is not located on $boot"
356             local CONFERR=1
357             ## more then one subdirectory deep is not supported. no sed available on boot floppies ( / -> \ )
358         elif [ "$mntpoint" != "$(v=`df "$mntpoint" 2> /dev/null | grep ^/dev/` ; echo ${v##*[ ]})" ] ; then
359             echo "$(v=`df "$mntpoint" 2>/dev/null | grep ^/dev/`; m=${v##*[ ]}; echo "${mntpoint##*$m/}")" | grep -q /
360             if [ $? = 0 ] ; then
361                 echo 1>&2 "$PRG:$ERR $mntpoint is more then one subdirectory deep from root of $boot"
362                 local CONFERR=1
363             else
364                 OFDIR="$(v=`df "$mntpoint" 2>/dev/null | grep ^/dev/`; m=${v##*[ ]}; echo "${mntpoint##*$m/}")"
365             fi
366         fi
367
368         if [ "$usemount" = no ] ; then
369             echo 1>&2 "$PRG:$ERR \`mntpoint=' requires \`usemount' be set"
370             local CONFERR=1
371         fi
372     fi
373
374     if [ -n "$magicboot" ] ; then
375         ## check for bsd loader
376         if [ -n "$bsd" ] ; then
377             if [ -f /usr/lib/yaboot/ofwboot -a -r /usr/lib/yaboot/ofwboot ] ; then
378                 BSDLOADER="/usr/lib/yaboot/ofwboot"
379             elif [ -f /usr/local/lib/yaboot/ofwboot -a -r /usr/local/lib/yaboot/ofwboot ] ; then
380                 BSDLOADER="/usr/local/lib/yaboot/ofwboot"
381             else
382                 echo 1>&2 "$PRG: /usr/local/lib/yaboot/ofwboot: No such file or directory"
383                 echo 1>&2 "$PRG: With the bsd= option set you must have the bsd boot loader ofwboot"
384                 CONFERR=1
385             fi
386         fi
387
388         ## convert defaultos variable
389         case "$defaultos" in
390             linux|Linux|GNU|Gnu|gnu)
391                 defaultos=bootyaboot
392                 ;;
393             bootyaboot)
394                 ;;
395             bsd)
396                 defaultos=bootbsd
397                 if [ -z "$bsd" ] ; then
398                     echo 1>&2 "$PRG:$ERR no entry for \`bsd' found, but defaultos is set to \`bsd'"
399                     local CONFERR=1
400                 fi
401                 ;;
402             macos)
403                 defaultos=bootmacos
404                 if [ -z "$macos" ] ; then
405                     echo 1>&2 "$PRG:$ERR no entry for \`macos' found, but defaultos is set to \`macos'"
406                     local CONFERR=1
407                 fi
408                 ;;
409             macosx)
410                 defaultos=bootmacosx
411                 if [ -z "$macosx" ] ; then
412                     echo 1>&2 "$PRG:$ERR no entry for \`macosx' found, but defaultos is set to \`macosx'"
413                     local CONFERR=1
414                 fi
415                 ;;
416             darwin)
417                 defaultos=bootdarwin
418                 if [ -z "$darwin" ] ; then
419                     echo 1>&2 "$PRG:$ERR no entry for \`darwin' found, but defaultos is set to \`darwin'"
420                     local CONFERR=1
421                 fi
422                 ;;
423             *)
424                 echo 1>&2 "$PRG:$ERR \`defaultos' must be either \`linux', \`bsd', \`macos' or \`macosx'"
425                 local CONFERR=1
426                 ;;
427         esac
428     fi
429
430     ## nvsetenv requires /proc
431     if [ ! -f /proc/uptime -a "$nonvram" = 0 ] ; then
432         echo 1>&2 "$PRG: /proc filesystem is not mounted, nvram will not be updated"
433         nonvram=1
434     fi
435
436     if [ "$nonvram" = 0 ] ; then
437         ## see if nvsetenv exists and is executable
438         if (command -v nvsetenv > /dev/null 2>&1) ; then
439             [ -x `command -v nvsetenv` ] || MISSING=1 ; else MISSING=1
440         fi
441
442         if [ "$nonvram" = 0 ] ; then
443             ## if nvsetenv exists see if its the old broken version
444             if [ "$MISSING" != 1 ] ; then
445                 nvsetenv --version > /dev/null 2>&1 || OLD=1
446             else
447                 nonvram=1
448                 echo 1>&2 "$PRG: Warning: \`nvsetenv' could not be found, nvram will not be updated"
449             fi
450
451             if [ "$OLD" = 1 ] ; then
452                 ## i check this myself to avoid misleading error
453                 ## messages. nvsetenv should REALLY support --version.
454                 if [ ! -e /dev/nvram ] ; then
455                     echo 1>&2 "$PRG: /dev/nvram: No such file or directory"
456                     echo 1>&2 "$PRG: Warning: nvram will not be updated"
457                     nonvram=1
458                 elif [ ! -c /dev/nvram ] ; then
459                     echo 1>&2 "$PRG: /dev/nvram: Not a character device"
460                     echo 1>&2 "$PRG: Warning: nvram will not be updated"
461                     nonvram=1
462                 elif [ ! -w /dev/nvram -o ! -r /dev/nvram ] ; then
463                     echo 1>&2 "$PRG: /dev/nvram: Permission denied"
464                     echo 1>&2 "$PRG: Warning: nvram will not be updated"
465                     nonvram=1
466                 elif ! (dd if=/dev/nvram of=/dev/null bs=1 count=10 > /dev/null 2>&1) ; then
467                     echo 1>&2 "$PRG: /dev/nvram: No such device"
468                     echo 1>&2 "$PRG: Warning: nvram will not be updated"
469                     nonvram=1
470                 else
471                     nonvram=1
472                     echo 1>&2 "$PRG: Warning: Incompatible version of \`nvsetenv', nvram will not be updated"
473                 fi
474             fi
475         fi
476
477         if [ -f "$boot" ] ; then
478             echo 1>&2 "$PRG: $boot is a regular file, disabling nvram updating"
479             nonvram=1
480         fi
481     fi
482
483     ## check for newworld mac. use cat hack due to /proc wierdness.
484     ## do not bail if we are on an OldWorld only warn (very loudly).
485     if [ "$(v=`cat /proc/cpuinfo 2>/dev/null | grep pmac-generation` ; echo ${v##*:})" = NewWorld ] ; then
486         true
487     elif [ "$(v=`cat /proc/cpuinfo 2>/dev/null | grep pmac-generation` ; echo ${v##*:})" = OldWorld ] ; then
488         echo 1>&2
489         echo 1>&2 '@@@@@@@@@@@@@@ WARNING!! WARNING!! WARNING!! @@@@@@@@@@@@@@'
490         echo 1>&2 "$PRG: Warning: This is an OldWorld PowerMac, $boot will **NOT** be bootable on this machine"
491         echo 1>&2 "$PRG: Oldworld PowerMacs need to use the quik bootloader, not yaboot"
492         echo 1>&2 '@@@@@@@@@@@@@@ WARNING!! WARNING!! WARNING!! @@@@@@@@@@@@@@'
493         echo 1>&2
494         [ "$nonvram" = 0 ] && echo 1>&2 "$PRG: OldWorld PowerMac, nvram will not be updated"
495         nonvram=1
496     elif (cat /proc/cpuinfo 2>/dev/null | grep ^motherboard | grep -q AAPL) ; then
497         echo 1>&2
498         echo 1>&2 '@@@@@@@@@@@@@@ WARNING!! WARNING!! WARNING!! @@@@@@@@@@@@@@'
499         echo 1>&2 "$PRG: Warning: This is an OldWorld PowerMac, $boot will **NOT** be bootable on this machine"
500         echo 1>&2 "$PRG: Oldworld PowerMacs need to use the quik bootloader, not yaboot"
501         echo 1>&2 '@@@@@@@@@@@@@@ WARNING!! WARNING!! WARNING!! @@@@@@@@@@@@@@'
502         echo 1>&2
503         [ "$nonvram" = 0 ] && echo 1>&2 "$PRG: OldWorld PowerMac, nvram will not be updated"
504         nonvram=1
505     elif (cat /proc/cpuinfo 2> /dev/null | grep ^machine | grep -q 'CHRP IBM') ; then
506         ## IBM hardware does not need nvram update AFAICT
507         nonvram=1
508         ADDNOTE=yes
509     else
510         #echo 1>&2 "$PRG: Warning: Unknown archetecture, $boot may not be bootable on this machine"
511         [ "$nonvram" = 0 ] && echo 1>&2 "$PRG: Warning: Unknown architecture, nvram will not be updated"
512         nonvram=1
513     fi
514
515     ## convert human readable color values from config to proper color
516     ## codes
517     case "$fgcolor" in
518         black) fgc=0 ;; blue) fgc=1 ;; green) fgc=2 ;; cyan) fgc=3 ;;
519         red) fgc=4 ;; purple) fgc=5 ;; brown) fgc=6 ;; light-gray) fgc=7 ;;
520         dark-gray) fgc=8 ;; light-blue) fgc=9 ;; light-green) fgc=a ;;
521         light-cyan) fgc=b ;; light-red) fgc=c ;; light-purple) fgc=d ;;
522         yellow) fgc=e ;; white) fgc=f ;;
523         *)
524         echo 1>&2 "$PRG:$ERR Invalid fgcolor: \`$fgcolor'"
525         local CONFERR=1
526         ;;
527     esac
528     case "$bgcolor" in
529         black) bgc=0 ;; blue) bgc=1 ;; green) bgc=2 ;; cyan) bgc=3 ;;
530         red) bgc=4 ;; purple) bgc=5 ;; brown) bgc=6 ;; light-gray) bgc=7 ;;
531         dark-gray) bgc=8 ;; light-blue) bgc=9 ;; light-green) bgc=a ;;
532         light-cyan) bgc=b ;; light-red) bgc=c ;; light-purple) bgc=d ;;
533         yellow) bgc=e ;; white) bgc=f ;;
534         *)
535         echo 1>&2 "$PRG:$ERR Invalid bgcolor: \`$bgcolor'"
536         local CONFERR=1
537         ;;
538     esac
539
540     ## if delay is not set use yaboot's timeout
541     if [ -z "$delay" ] ; then
542         delay="$(($timeout / 10))"
543     fi
544
545     if [ "$CONFERR" = 1 ] ; then
546         return 1
547     else
548         return 0
549     fi
550 }
551
552
553 ## if readlink is missing use a kludge
554 if (command -v readlink > /dev/null 2>&1) ; then
555     true
556 else
557     readlink()
558     {
559         local SYMTARGET="$(v=`ls -l "$2" 2>/dev/null` ; echo ${v##*> })"
560         if [ -n "$SYMTARGET" ] ; then
561             echo "$SYMTARGET"
562             return 0
563         else
564             return 1
565         fi
566     }
567 fi
568
569 ## /etc/yaboot.conf with password should not be world readable.
570 permcheck()
571 {
572 if [ -L "$bootconf" ] ; then
573     local realfile="$(readlink -f "$bootconf")" || return 0
574 else
575     local realfile="$bootconf"
576 fi
577
578 ## don't bother if we could not read the symlink
579 [ -z "$realfile" ] && return 0
580 [ ! -f "$realfile" ] && return 0
581
582 ## get permissions, and don't bother checking if we can't
583 local PERM=`v=$(ls -l "$realfile" 2>/dev/null) ; echo ${v%% *}`
584 [ -z "$PERM" ] && return 0
585 [ `echo ${#PERM}` != 10 ] && return 0
586
587 case "$PERM" in
588     -rw-------|-r--------)
589       if [ ! -O "$realfile" -a `id -u` = 0 ] ; then
590          echo 1>&2 "$PRG: Warning: $bootconf is not owned by root"
591       fi
592       ;;
593     -rw-r-----|-r--r-----)
594       if [ ! -O "$realfile" -a `id -u` = 0 ] ; then
595          echo 1>&2 "$PRG: Warning: $bootconf is not owned by root"
596       fi
597       if [ ! -G "$realfile" -a `id -g` = 0 ] ; then
598          echo 1>&2 "$PRG: Warning: $bootconf is not owned by group root"
599       fi
600       ;;
601     -r--r--r--|-rw-r--r--|-rw-rw-r--|-rw-rw-rw-|-rw-rw----)
602       echo 1>&2 "$PRG: Warning: Insecure permissions on $bootconf: $PERM should be -rw-------"
603       ;;
604     *)
605       echo 1>&2 "$PRG: Warning: Incorrect permissions on $bootconf: $PERM should be -rw-------"
606       ;;
607 esac
608 }
609
610 convertpath()
611 {
612     ## figure out bootstrap device OF pathname if user did not supply it.
613     if [ -z "$ofboot" ] ; then
614         [ "$VERBOSE" = 1 ] && echo "$PRG: Finding OpenFirmware device path to \`$boot'..."
615         ofboot="$($OFPATH $boot)"
616         if [ $? != 0 ] ; then
617             echo 1>&2 "$PRG: Unable to find OpenFirmware path for boot=$boot"
618             echo 1>&2 "$PRG: Please add ofboot=<path> where <path> is the OpenFirmware path to $boot to $CONF"
619             local CONVERR=1
620         fi
621         [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: ofboot set to \`$ofboot'"
622     fi
623
624     ## figure out OF device path for macos/macosx if user supplied a unix device node.
625     if [ -n "$bsd" ] ; then
626         case "$bsd" in
627             /dev/*)
628                 [ "$VERBOSE" = 1 ] && echo "$PRG: Finding OpenFirmware device path to \`$bsd'..."
629                 local sbsd="$bsd"
630                 bsd="$($OFPATH $bsd)"
631                 if [ $? != 0 ] ; then
632                     echo 1>&2 "$PRG: Unable to determine OpenFirmware path for bsd=$sbsd"
633                     echo 1>&2 "$PRG: Try specifying the real OpenFirmware path for bsd=$sbsd in $CONF"
634                     local CONVERR=1
635                 fi
636                 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: bsd set to \`$bsd' from \`$sbsd'"
637                 ;;
638             *)
639                 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: bsd left alone: \`$bsd'"
640                 ;;
641         esac
642     fi
643
644     if [ -n "$macos" ] ; then
645         case "$macos" in
646             /dev/*)
647                 [ "$VERBOSE" = 1 ] && echo "$PRG: Finding OpenFirmware device path to \`$macos'..."
648                 local smacos="$macos"
649                 macos="$($OFPATH $macos)"
650                 if [ $? != 0 ] ; then
651                     echo 1>&2 "$PRG: Unable to determine OpenFirmware path for macos=$smacos"
652                     echo 1>&2 "$PRG: Try specifying the real OpenFirmware path for macos=$smacos in $CONF"
653                     local CONVERR=1
654                 fi
655                 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: macos set to \`$macos' from \`$smacos'"
656                 ;;
657             *)
658                 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: macos left alone: \`$macos'"
659                 ;;
660         esac
661     fi
662
663     if [ -n "$macosx" ] ; then
664         case "$macosx" in
665             /dev/*)
666                 [ "$VERBOSE" = 1 ] && echo "$PRG: Finding OpenFirmware device path to \`$macosx'..."
667                 local smacosx="$macosx"
668                 macosx="$($OFPATH $macosx)"
669                 if [ $? != 0 ] ; then
670                     echo 1>&2 "$PRG: Unable to determine OpenFirmware path for macosx=$smacosx"
671                     echo 1>&2 "$PRG: Try specifying the real OpenFirmware path for macosx=$smacosx in $CONF"
672                     local CONVERR=1
673                 fi
674                 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: macosx set to \`$macosx' from \`$smacosx'"
675                 ;;
676             *)
677                 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: macosx left alone: \`$macosx'"
678                 ;;
679         esac
680     fi
681
682     if [ -n "$darwin" ] ; then
683         case "$darwin" in
684             /dev/*)
685                 [ "$VERBOSE" = 1 ] && echo "$PRG: Finding OpenFirmware device path to \`$darwin'..."
686                 local sdarwin="$darwin"
687                 darwin="$($OFPATH $darwin)"
688                 if [ $? != 0 ] ; then
689                     echo 1>&2 "$PRG: Unable to determine OpenFirmware path for darwin=$sdarwin"
690                     echo 1>&2 "$PRG: Try specifying the real OpenFirmware path for darwin=$sdarwin in $CONF"
691                     local CONVERR=1
692                 fi
693                 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: darwin set to \`$darwin' from \`$sdarwin'"
694                 ;;
695             *)
696                 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: darwin left alone: \`$darwin'"
697                 ;;
698         esac
699     fi
700
701     if [ "$CONVERR" = 1 ] ; then
702         return 1
703     else
704         return 0
705     fi
706 }
707
708 ## make sure the hfsutils we need are installed and executable.
709 checkhfsutils()
710 {
711     if (command -v hmount > /dev/null 2>&1) ; then
712         [ -x `command -v hmount` ] || FAIL=1 ; else FAIL=1 ; fi
713     if (command -v humount > /dev/null 2>&1) ; then
714         [ -x `command -v humount` ] || FAIL=1 ; else FAIL=1 ; fi
715     if (command -v hcopy > /dev/null 2>&1) ; then
716         [ -x `command -v hcopy` ] || FAIL=1 ; else FAIL=1 ; fi
717     if (command -v hattrib > /dev/null 2>&1) ; then
718         [ -x `command -v hattrib` ] || FAIL=1 ; else FAIL=1 ; fi
719     if (command -v hformat > /dev/null 2>&1) ; then
720         [ -x `command -v hformat` ] || FAIL=1 ; else FAIL=1 ; fi
721
722     if [ "$FAIL" = 1 ] ; then
723         return 1
724     else
725         return 0
726     fi
727 }
728
729 ## This is gross, IBM CHRP OF needs a .note added to the yaboot
730 ## binary, nobody knows whether this note will affect PowerMac OF or
731 ## not (or could in the future).
732 hack_yaboot()
733 {
734     local YBDIR="${install%/*}"
735     if [ -x "$YBDIR/addnote" ] ; then
736         TMPYABOOT=`mktemp -q "$TMP/yaboot.XXXXXX"`
737         if [ $? != 0 ] ; then
738             echo 1>&2 "$PRG: Could not create temporary file, aborting."
739             return 1
740         else
741             if (cat "$install" > "$TMPYABOOT" 2> /dev/null) ; then
742                 install="$TMPYABOOT"
743             else
744                 echo 1>&2 "$PRG: Could not create temporary file, aborting."
745                 return 1
746             fi
747         fi
748         [ "$DEBUG" = 1 ] && echo "$PRG: Embedding CHRP note section in temp yaboot..."
749         "$YBDIR/addnote" "$install" > /dev/null 2>&1
750         if [ $? != 0 ] ; then
751             echo 1>&2 "$PRG: Could not install note section required by your architecture"
752             return 1
753         fi
754     else
755         echo 1>&2 "$PRG: Your architecture requires $YBDIR/addnote which cannot be found"
756         return 1
757     fi
758     return 0
759 }
760
761 ## install using userspace utilities rather then kernel filesytem
762 ## support.  hfsutils only, mtools not supported.
763 util_install()
764 {
765     ## catch signals, and humount, cleanup done by trap 0.
766     trap "humount $boot ; exit 129" 1
767     trap "echo 1>&2 $SIGINT ; humount $boot ; exit 130" 2
768     trap "humount $boot ; exit 131" 3
769     trap "humount $boot ; exit 143" 15
770
771     ## filenames on bootstrap partition. ofboot hard codes yaboot.
772     local BTFILE=yaboot
773     local CFFILE=yaboot.conf
774
775     ## if there is a magicboot script to install we will give it the
776     ## hfstype (should be "tbxi") and give yaboot type "boot".
777     if [ -n "$magicboot" ] ; then
778         local BTTYPE=boot
779     else
780         local BTTYPE="$hfstype"
781     fi
782
783     if [ -n "$magicboot" ] ; then
784         local WRAP="${magicboot##*/}"
785     fi
786
787     ## set verbose messages here so they don't show temporary file paths
788     local INSTALLFIRST="$PRG: Installing first stage bootstrap $magicboot onto $boot..."
789     local INSTALLPRIMARY="$PRG: Installing primary bootstrap $install onto $boot..."
790
791     ## repoint magicboot as the real first stage loader if using the
792     ## modern automatic generating ofboot.b.
793     if [ -n "$FIRST" ] ; then
794         magicboot="$FIRST"
795         [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: set magicboot to $FIRST"
796     fi
797
798     ## gross hack, add note section for IBM CHRP
799     if [ "$ADDNOTE" = yes ] ; then
800         hack_yaboot || return 1
801     fi
802
803     if [ "$fstype" = hfs ] ; then
804         if [ "$protect" = yes ] ; then
805             local LOCK="+l"
806         fi
807
808         if [ "$hide" = yes ] ; then
809             local INVISIBLE="+i"
810         fi
811
812         ## make sure the device is not mounted as a filesystem before
813         ## we start mucking with it directly.
814         mount | grep "^$boot\>" > /dev/null
815         if [ $? = 0 ] ; then
816             echo 1>&2 "$PRG: $boot appears to be mounted! aborting."
817             return 1
818         fi
819
820         ## hmount is really more of a way to make sure we have a valid HFS
821         ## filesystem before proceding, and hcopy requires it...
822         hmount "$boot" > /dev/null
823         if [ $? != 0 ] ; then
824             echo 1>&2 "$PRG: $boot appears to have never had a bootstrap installed, please run mkofboot"
825             return 1
826         fi
827
828         ## must be explicit with target filename to avoid hfsutils
829         ## braindamage ("_" -> " " filename mangling) also avoid
830         ## ambiguity in the bootstrap partition.
831         if [ -n "$magicboot" ] ; then
832             [ "$VERBOSE" = 1 ] && echo "$INSTALLFIRST"
833             hcopy -r "$magicboot" :ofboot.b
834             if [ $? != 0 ] ; then
835                echo 1>&2 "$PRG: An error occured while writing to $boot"
836                return 1
837             fi
838         fi
839
840         [ "$VERBOSE" = 1 ] && echo "$INSTALLPRIMARY"
841         hcopy -r "$install" :"$BTFILE"
842         if [ $? != 0 ] ; then
843             echo 1>&2 "$PRG: An error occured while writing to $boot"
844             return 1
845         fi
846
847         [ "$VERBOSE" = 1 ] && echo "$PRG: Installing $bootconf onto $boot..."
848         hcopy -r "$bootconf" :"$CFFILE"
849         if [ $? != 0 ] ; then
850             echo 1>&2 "$PRG: An error occured while writing to $boot"
851             return 1
852         fi
853
854         if [ -n "$BSDLOADER" ] ; then
855             [ "$VERBOSE" = 1 ] && echo "$PRG: Installing $BSDLOADER onto $boot..."
856             hcopy -r "$BSDLOADER" :ofwboot
857             if [ $? != 0 ] ; then
858                 echo 1>&2 "$PRG: An error occured while writing to $boot"
859                 return 1
860             fi
861         fi
862
863         ## set all file's attributes, if a magicboot script exists it
864         ## gets the configured hfstype instead of yaboot (should be
865         ## "tbxi") so it gets booted by OF.
866         if [ -n "$magicboot" ] ; then
867             [ "$VERBOSE" = 1 ] && echo "$PRG: Setting attributes on $WRAP..."
868             hattrib -t "$hfstype" -c "$hfscreator" $INVISIBLE $LOCK :ofboot.b
869             if [ $? != 0 ] ; then
870                 echo 1>&2 "$PRG: Warning: error setting attributes on $WRAP"
871                 echo 1>&2 "$PRG: This is probably bad but we'll ignore it."
872             fi
873         fi
874
875         [ "$VERBOSE" = 1 ] && echo "$PRG: Setting attributes on $BTFILE..."
876         hattrib -t "$BTTYPE" -c "$hfscreator" $INVISIBLE $LOCK :"$BTFILE"
877         if [ $? != 0 ] ; then
878             echo 1>&2 "$PRG: Warning: error setting attributes on $BTFILE"
879             echo 1>&2 "$PRG: This is probably bad but we'll ignore it"
880         fi
881
882         [ "$VERBOSE" = 1 ] && echo "$PRG: Setting attributes on $CFFILE..."
883         hattrib -t "conf" -c "$hfscreator" $INVISIBLE $LOCK :"$CFFILE"
884         if [ $? != 0 ] ; then
885             echo 1>&2 "$PRG: Warning: error setting attributes on $CFFILE"
886             echo 1>&2 "$PRG: This is probably unimportant so we'll ignore it"
887         fi
888
889         if [ -n "$BSDLOADER" ] ; then
890             [ "$VERBOSE" = 1 ] && echo "$PRG: Setting attributes on ofwboot..."
891             hattrib -t "bsdb" -c "$hfscreator" $INVISIBLE $LOCK :ofwboot
892             if [ $? != 0 ] ; then
893                 echo 1>&2 "$PRG: Warning: error setting attributes on ofwboot"
894                 echo 1>&2 "$PRG: This is probably unimportant so we'll ignore it"
895             fi
896         fi
897
898         ## bless the root directory so OF will find the boot file
899         if [ "$bless" = yes ] ; then
900             [ "$VERBOSE" = 1 ] && echo "$PRG: Blessing $boot with Holy Penguin Pee..."
901             hattrib -b :
902             if [ $? != 0 ] ; then
903                 echo 1>&2 "$PRG: Warning: error blessing $boot"
904                 echo 1>&2 "$PRG: This is probably bad but we'll ignore it"
905             fi
906         fi
907
908         ## clean up the ~/.hcwd file hmount creates
909         humount "$boot" > /dev/null
910         sync ; sync
911
912         ## use explicit filename if we don't bless.
913         if [ "$bless" = yes ] ; then
914             local OFFILE='\\:tbxi'
915         else
916             if [ -n "$magicboot" ] ; then
917                 local OFFILE=ofboot.b
918             else
919                 local OFFILE="$BTFILE"
920             fi
921         fi
922
923         ## update the boot-device variable in OF nvram.
924         if [ "$nonvram" = 0 ] ; then
925             [ "$VERBOSE" = 1 ] && echo "$PRG: Updating OpenFirmware boot-device variable in nvram..."
926             [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: boot-device=${ofboot},${OFFILE}"
927             nvsetenv boot-device "${ofboot},${OFFILE}"
928             if [ $? != 0 ] ; then
929                 echo 1>&2 "$PRG: An error occured while updating nvram, we'll ignore it"
930             fi
931         fi
932
933     else
934         echo 1>&2 "$PRG: mtools support is not implemented"
935         echo 1>&2 "$PRG: Use --mount or add \`usemount' to $CONF"
936         return 1
937     fi
938
939     return 0
940 }
941
942 ## used by mnt_install so mntpoint= can be supported in a cleaner way.
943 mnt()
944 {
945     ## we can even create bootstrap filesystem images directly if you
946     ## ever wanted too.
947     if [ -f "$boot" ] ; then
948         local loop=",loop"
949     fi
950
951     if [ -e "$TMP/bootstrap.$$" ] ; then
952         echo 1>&2 "$PRG: $TMP/bootstrap.$$ exists, aborting."
953         return 1
954     fi
955
956     mkdir -m 700 "$TMP/bootstrap.$$"
957     if [ $? != 0 ] ; then
958         echo 1>&2 "$PRG: Could not create mountpoint directory, aborting."
959         return 1
960     fi
961
962     mount | grep "^$boot\>" > /dev/null
963     if [ $? = 0 ] ; then
964         echo 1>&2 "$PRG: $boot appears to be mounted! aborting."
965         return 1
966     fi
967
968     [ "$VERBOSE" = 1 ] && echo "$PRG: Mounting $boot..."
969     mount -t "$fstype" -o rw,umask=077$loop "$boot" "$TMP/bootstrap.$$"
970     if [ $? != 0 ] ; then
971         echo 1>&2 "$PRG: An error occured mounting $boot"
972         return 1
973     fi
974
975     ## catch signals, set here to avoid umounting something we did not
976     ## mount. cleanup done by trap 0.
977     trap "umount $boot ; exit 129" 1
978     trap "echo 1>&2 $SIGINT ; umount $boot ; exit 130" 2
979     trap "umount $boot ; exit 131" 3
980     trap "umount $boot ; exit 143" 15
981
982     TARGET="$TMP/bootstrap.$$"
983     return 0
984 }
985
986 ## umnt funtion which checks whether we mounted anything or not, for
987 ## mntpoint= this makes the code below cleaner IMO.
988 umnt()
989 {
990     if [ -z "$mntpoint" ] ; then
991         [ "$1" = failure ] && echo 1>&2 "$PRG: Attempting to umount $boot..."
992         umount "$2"
993         if [ $? != 0 ] ; then
994             echo 1>&2 "$PRG: umount of $boot failed!"
995             return 1
996         else
997             [ "$1" = failure ] && echo 1>&2 "$PRG: umount successfull"
998             return 0
999         fi
1000     else
1001         return 0
1002     fi
1003 }
1004
1005 ## Use kernel filesytem drivers to mount the bootstrap partition like
1006 ## any other filesystem and copy the files there with standard un*x
1007 ## utilities.
1008 mnt_install()
1009 {
1010     local BTFILE=yaboot
1011
1012     ## msdosfs is broken, yaboot may not support this filename.
1013     if [ "$fstype" = msdos ] ; then
1014         local CFFILE=yaboot.cnf
1015     else
1016         local CFFILE=yaboot.conf
1017     fi
1018
1019     if [ -n "$magicboot" ] ; then
1020         local WRAP="${magicboot##*/}"
1021     fi
1022
1023     ## set verbose messages here so they don't show temporary file paths
1024     local INSTALLFIRST="$PRG: Installing first stage bootstrap $magicboot onto $boot..."
1025     local INSTALLPRIMARY="$PRG: Installing primary bootstrap $install onto $boot..."
1026
1027     ## repoint magicboot as the real first stage loader if using the
1028     ## modern automatic generating ofboot.b.
1029     if [ -n "$FIRST" ] ; then
1030         magicboot="$FIRST"
1031         [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: set magicboot to $FIRST"
1032     fi
1033
1034     ## gross hack, add note section for IBM CHRP
1035     if [ "$ADDNOTE" = yes ] ; then
1036         hack_yaboot || return 1
1037     fi
1038
1039     ## call mnt() function to take care of mounting filesystem if needed
1040     if [ -z "$mntpoint" ] ; then
1041         mnt || return 1
1042     else
1043         TARGET="$mntpoint"
1044     fi
1045
1046     ## this is probably insecure on modern filesystems, but i think
1047     ## safe on crippled hfs/dosfs. user should ensure mntpoint= is safe.
1048     if [ -n "$magicboot" ] ; then
1049         [ "$VERBOSE" = 1 ] && echo "$INSTALLFIRST"
1050         cp -f "$magicboot" "$TARGET/ofboot.b"
1051         if [ $? != 0 ] ; then
1052             echo 1>&2 "$PRG: An error occured while writing to $boot"
1053             umnt failure "$TARGET"
1054             return 1
1055         fi
1056     fi
1057
1058     [ "$VERBOSE" = 1 ] && echo "$INSTALLPRIMARY"
1059     cp -f "$install" "$TARGET/$BTFILE"
1060     if [ $? != 0 ] ; then
1061         echo 1>&2 "$PRG: An error occured while writing to $boot"
1062         umnt failure "$TARGET"
1063         return 1
1064     fi
1065
1066     [ "$VERBOSE" = 1 ] && echo "$PRG: Installing $bootconf onto $boot..."
1067     cp -f "$bootconf" "$TARGET/$CFFILE"
1068     if [ $? != 0 ] ; then
1069         echo 1>&2 "$PRG: An error occured while writing to $boot"
1070         umnt failure "$TARGET"
1071         return 1
1072     fi
1073
1074     if [ -n "$BSDLOADER" ] ; then
1075         [ "$VERBOSE" = 1 ] && echo "$PRG: Installing $BSDLOADER onto $boot..."
1076         cp -f "$BSDLOADER" "$TARGET/ofwboot"
1077         if [ $? != 0 ] ; then
1078             echo 1>&2 "$PRG: An error occured while writing to $boot"
1079             umnt failure "$TARGET"
1080             return 1
1081         fi
1082     fi
1083
1084     if [ "$protect" = yes ] ; then
1085         [ "$VERBOSE" = 1 ] && echo "$PRG: Setting read-only attributes..."
1086         chmod a-w "$TARGET/$BTFILE"
1087         chmod a-w "$TARGET/$CFFILE"
1088         if [ -n "$magicboot" ] ; then
1089             chmod a-w "$TARGET/ofboot.b"
1090         fi
1091         if [ -n "$BSDLOADER" ] ; then
1092             chmod a-w "$TARGET/ofwboot"
1093         fi
1094     fi
1095
1096     sync ; sync
1097     umnt success "$TARGET" || return 1
1098
1099     ## make variable with a \ to avoid shell fsckage.  ugly ugly ugly.
1100     local BS='\'
1101     if [ -n "$magicboot" ] ; then
1102         [ -n "$OFDIR" ] && OFDIR="${BS}${OFDIR}${BS}"
1103         local OFFILE="${OFDIR}ofboot.b"
1104     else
1105         [ -n "$OFDIR" ] && OFDIR="${BS}${OFDIR}${BS}"
1106         local OFFILE="${OFDIR}${BTFILE}"
1107     fi
1108
1109     ## update the boot-device variable in OF nvram.
1110     if [ "$nonvram" = 0 ] ; then
1111         [ "$VERBOSE" = 1 ] && echo "$PRG: Updating OpenFirmware boot-device variable in nvram..."
1112         [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: boot-device=${ofboot},${OFFILE}"
1113         nvsetenv boot-device "${ofboot},${OFFILE}"
1114         if [ $? != 0 ] ; then
1115             echo 1>&2 "$PRG: An error occured while updating nvram, we'll ignore it"
1116         fi
1117     else
1118         echo 1>&2 "$PRG: Warning: You must manually configure OpenFirmware to boot."
1119     fi
1120
1121     return 0
1122 }
1123
1124 ## raw installation, for IBM RS/6000 hardware, yaboot is dded to the
1125 ## bootstrap partition.
1126 raw_install()
1127 {
1128     ## make sure the device is not mounted as a filesystem before
1129     ## we start mucking with it directly.
1130     mount | grep "^$boot\>" > /dev/null
1131     if [ $? = 0 ] ; then
1132         echo 1>&2 "$PRG: $boot appears to be mounted! aborting."
1133         return 1
1134     fi
1135
1136     ## set verbosity message before munging the yaboot pathname
1137     local INSTALLPRIMARY="$PRG: Installing primary bootstrap $install onto $boot..."
1138
1139     ## gross hack, add note section for IBM CHRP
1140     if [ "$ADDNOTE" = yes ] ; then
1141         hack_yaboot || return 1
1142     fi
1143
1144     [ "$VERBOSE" = 1 ] && echo "$INSTALLPRIMARY"
1145     dd if=/dev/zero of="$boot" bs=512 count=1600 > /dev/null 2>&1
1146     dd if="$install" of="$boot" bs=512 > /dev/null 2>&1
1147     if [ $? != 0 ] ; then
1148         echo 1>&2 "$PRG: Installation failed."
1149         return 1
1150     fi
1151     sync ; sync
1152     [ "$VERBOSE" = 1 ] && echo "$PRG: Installation successful"
1153 }
1154
1155 ## make sure the first stage ofboot generator is compatible.
1156 checkfirststage()
1157 {
1158     grep -q "^#%ybinscript-" "$magicboot" 2> /dev/null
1159     if [ "$?" = 0 ] ; then
1160         local magic=`grep "^#%ybinscript-" "$magicboot"`
1161         local ver="${magic##*-}"
1162         if [ "$ver" = "1.1" ] ; then
1163             FIRSTSTG=compat
1164             return 0
1165         else
1166             echo 1>&2 "$PRG: Incompatible version of first stage loader $magicboot.  aborting..."
1167             return 1
1168         fi
1169     else
1170         FIRSTSTG=old
1171         return 0
1172     fi
1173 }
1174
1175 ## build the first stage loader.
1176 mkfirststage()
1177 {
1178     ## must have 7 backslashes to == \\ printf + shell = bizarre... or,
1179     ## make special variable to contain a \ (need \\ to make \) to work
1180     ## around echo -e -n brokeness.
1181     local BS='\\'
1182     local OS=1
1183
1184     ## deal with mntpoint=
1185     [ -n "$OFDIR" ] && local OFDIR="${BS}${OFDIR}${BS}"
1186
1187     ## some misguided people insist on installing OSX on
1188     ## HorribleFileSystem+ instead of UFS, as a result MacOS deblesses
1189     ## OSX, making it unbootable. if apple localizes the filesystem hierarchy again screw it.
1190     [ "$brokenosx" = yes ] && local OSXBOOT="${BS}System${BS}Library${BS}CoreServices${BS}BootX"
1191     [ "$brokenosx" = no ] && local OSXBOOT="${BS}${BS}:tbxi"
1192
1193     ## assign variables for configured menu options.
1194     [ "$usemount" = no -a "$bless" = yes ] && local YB="yaboot GNU l $ofboot ,${BS}${BS}yaboot"
1195     [ "$usemount" = yes -o "$bless" = no ] && local YB="yaboot GNU l $ofboot ,${OFDIR}yaboot"
1196     [ -n "$bsd" ] && OS="$(($OS + 1))" && local BSD="ybsd BSD b $ofboot ,${BS}${BS}ofwboot/$bsd"
1197     [ -n "$macos" ] && OS="$(($OS + 1))" && local MAC="macos MacOS m $macos ,${BS}${BS}:tbxi"
1198     [ -n "$macosx" ] && OS="$(($OS + 1))" && local MX="macosx MacOSX x $macosx ,${OSXBOOT}"
1199     [ -n "$darwin" ] && OS="$(($OS + 1))" && local DW="darwin Darwin d $darwin ,${BS}${BS}:tbxi"
1200     [ "$cdrom" = yes ] && OS="$(($OS + 1))" && local CD="cd CDROM c cd: ,${BS}${BS}:tbxi"
1201     [ "$network" = yes ] && OS="$(($OS + 1))" && local NET="net Network n enet: 0"
1202     [ "$of" = yes ] && OS="$(($OS + 1))" && local OF="of OpenFirmware o quit now"
1203     [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: OS=$OS"
1204
1205     ## call ofboot,
1206     ## Usage: OS-count defaultos timeout fgc bgc osname oslabel oskey osdev osfile ...
1207     [ "$DEBUG" = 1 ] && $PRINTF 1>&2 "$PRG: DEBUG: /bin/sh $magicboot $OS $defaultos $delay $fbc $bgc $YB $BSD $MAC $MX $DW $CD $NET $OF\n"
1208     FIRST="$(/bin/sh "$magicboot" "$OS" "$defaultos" "$delay" $fgc $bgc ${YB} ${BSD} ${MAC} ${MX} ${DW} ${CD} ${NET} ${OF})" || return 1
1209
1210     return 0
1211 }
1212
1213 ## mkofboot function.
1214 mkoffs()
1215 {
1216     mount | grep "^$boot\>" > /dev/null
1217     if [ $? = 0 ] ; then
1218         echo 1>&2 "$PRG: $boot appears to be mounted! aborting."
1219         return 1
1220     fi
1221
1222     case "$fstype" in
1223         hfs)
1224             [ "$VERBOSE" = 1 ] && echo "$PRG: Creating HFS filesystem on $boot..."
1225             if (command -v dd > /dev/null 2>&1) ; then
1226                 dd if=/dev/zero of="$boot" bs=512 count=1600 > /dev/null 2>&1
1227             fi
1228             hformat -l bootstrap "$boot" > /dev/null
1229             if [ $? != 0 ] ; then
1230                 echo 1>&2 "$PRG: HFS filesystem creation failed!"
1231                 return 1
1232             fi
1233             humount "$boot" ## otherwise we might get confused.
1234             return 0
1235             ;;
1236         msdos)
1237             if (command -v mkdosfs > /dev/null 2>&1) ; then
1238                 [ -x `command -v mkdosfs` ] || FAIL=1 ; else FAIL=1 ; fi
1239                 if [ "$FAIL" = 1 ] ; then
1240                     echo 1>&2 "$PRG: mkdosfs is not installed or cannot be found"
1241                     return 1
1242                 fi
1243
1244             [ "$VERBOSE" = 1 ] && echo "$PRG: Creating DOS filesystem on $boot..."
1245             if (command -v dd > /dev/null 2>&1) ; then
1246                 dd if=/dev/zero of="$boot" bs=512 count=1600 > /dev/null 2>&1
1247             fi
1248             mkdosfs -n bootstrap "$boot" > /dev/null
1249             if [ $? != 0 ] ; then
1250                 echo 1>&2 "$PRG: DOS filesystem creation failed!"
1251                 return 1
1252             fi
1253             return 0
1254             ;;
1255     esac
1256 }
1257
1258 confirm()
1259 {
1260     if [ "$FORCE" = yes ] ; then
1261         return 0
1262     else
1263         echo 1>&2
1264         [ "$fstype" = raw ] && $PRINTF 1>&2 "$PRG: Overwrite contents of $boot with $install? [y/N] "
1265         [ "$fstype" != raw ] && $PRINTF 1>&2 "$PRG: Create $fstype filesystem on $boot? [y/N] "
1266         read ans
1267         case "$ans" in
1268             y|Y)
1269                 return 0
1270                 ;;
1271             *)
1272                 echo 1>&2 "$PRG: Abort."
1273                 return 2
1274                 ;;
1275         esac
1276     fi
1277 }
1278
1279 ## for fstype=raw check if an ELF binary has already been dded.
1280 luserck()
1281 {
1282     if [ "$(dd if="$boot" bs=1 skip=1 count=3 2>/dev/null)" = ELF ] ; then
1283         return 0
1284     else
1285         echo 1>&2 "$PRG: This partition has never had yaboot installed before, please run mkofboot"
1286         return 1
1287     fi
1288 }
1289
1290 mkconf()
1291 {
1292 ## defaults for this are defined at the beginning of the script with
1293 ## other variables.
1294
1295 echo \
1296 "## yaboot configuration file generated by ybin $VERSION
1297
1298 device=$device
1299 timeout=$timeout
1300
1301 image=$image
1302         label=$label
1303         partition=$partition
1304         root=$root
1305         read-only
1306 " > "$TMPCONF" || return 1
1307
1308 [ "$DEBUG" = 1 ] && $PRINTF 1>&2 "\nDEBUG: autoconf:\n----\n" && cat "$TMPCONF" 1>&2 && echo 1>&2 "----"
1309 return 0
1310 }
1311
1312 ## take out the trash.
1313 cleanup()
1314 {
1315     if [ -n "$TMPCONF" ] ; then rm -f "$TMPCONF" ; fi
1316     if [ -n "$FIRST" ] ; then rm -f "$FIRST" ; fi
1317     if [ -n "$TMPYABOOT" ] ; then rm -f "$TMPYABOOT" ; fi
1318     if [ -d "$TMP/bootstrap.$$" -a "$usemount" = yes ] ; then rmdir "$TMP/bootstrap.$$" ; fi
1319     return 0
1320 }
1321
1322 ##########
1323 ## Main ##
1324 ##########
1325
1326 ## absurdly bloated case statement to parse command line options.
1327 if [ $# != 0 ] ; then
1328     while true ; do
1329         case "$1" in
1330             -V|--version)
1331                 version
1332                 exit 0
1333                 ;;
1334             -h|--help)
1335                 usage
1336                 exit 0
1337                 ;;
1338             --debug)
1339                 DEBUG=1
1340                 ARGS="$ARGS $1"
1341                 shift
1342                 ;;
1343             -v|--verbose)
1344                 VERBOSE=1
1345                 ARGS="$ARGS $1"
1346                 shift
1347                 ;;
1348             -f|--force)
1349                 FORCE=yes
1350                 ARGS="$ARGS $1"
1351                 shift
1352                 ;;
1353             -b|--boot)
1354                 if [ -n "$2" ] ; then
1355                     if [ "$boot" = "unconfigured" ]; then
1356                         boot="$2"
1357                     else
1358                         boot="$boot $2"
1359                     fi
1360                     ARGBT=1
1361                     shift 2
1362                 else
1363                     echo 1>&2 "$PRG: option requires an argument $1"
1364                     echo 1>&2 "Try \`$PRG --help' for more information."
1365                     exit 1
1366                 fi
1367                 ;;
1368             -o|--ofboot)
1369                 if [ -n "$2" ] ; then
1370                     ofboot="$2"
1371                     ARGOB=1
1372                     ARGS="$ARGS $1 $2"
1373                     shift 2
1374                 else
1375                     echo 1>&2 "$PRG: option requires an argument $1"
1376                     echo 1>&2 "Try \`$PRG --help' for more information."
1377                     exit 1
1378                 fi
1379                 ;;
1380             -i|--install)
1381                 if [ -n "$2" ] ; then
1382                     install="$2"
1383                     ARGBF=1
1384                     ARGS="$ARGS $1 $2"
1385                     shift 2
1386                 else
1387                     echo 1>&2 "$PRG: option requires an argument $1"
1388                     echo 1>&2 "Try \`$PRG --help' for more information."
1389                     exit 1
1390                 fi
1391                 ;;
1392             -C|--config)
1393                 if [ -n "$2" ] ; then
1394                     CONF="$2"
1395                     bootconf="$2"
1396                     ERR=" Error in $CONF:"
1397                     ARGS="$ARGS $1 $2"
1398                     shift 2
1399                 else
1400                     echo 1>&2 "$PRG: option requires an argument $1"
1401                     echo 1>&2 "Try \`$PRG --help' for more information."
1402                     exit 1
1403                 fi
1404                 ;;
1405             -m|--magicboot)
1406                 if [ -n "$2" ] ; then
1407                     magicboot="$2"
1408                     ARGWP=1
1409                     ARGS="$ARGS $1 $2"
1410                     shift 2
1411                 else
1412                     echo 1>&2 "$PRG: option requires an argument $1"
1413                     echo 1>&2 "Try \`$PRG --help' for more information."
1414                     exit 1
1415                 fi
1416                 ;;
1417             --filesystem)
1418                 if [ -n "$2" ] ; then
1419                     fstype="$2"
1420                     ARGFS=1
1421                     ARGS="$ARGS $1 $2"
1422                     shift 2
1423                 else
1424                     echo 1>&2 "$PRG: option requires an argument $1"
1425                     echo 1>&2 "Try \`$PRG --help' for more information."
1426                     exit 1
1427                 fi
1428                 ;;
1429             --nobless)
1430                 bless=no
1431                 ARGBS=1
1432                 ARGS="$ARGS $1"
1433                 shift
1434                 ;;
1435             -M|--mount)
1436                 usemount=yes
1437                 ARGMT=1
1438                 ARGS="$ARGS $1"
1439                 shift
1440                 ;;
1441             --protect)
1442                 protect=yes
1443                 ARGPT=1
1444                 ARGS="$ARGS $1"
1445                 shift
1446                 ;;
1447             --hide)
1448                 hide=yes
1449                 ARGHD=1
1450                 ARGS="$ARGS $1"
1451                 shift
1452                 ;;
1453             --nonvram)
1454                 nonvram=1
1455                 ARGNV=1
1456                 ARGS="$ARGS $1"
1457                 shift
1458                 ;;
1459             --device)
1460                 if [ -n "$2" ] ; then
1461                     device="$2"
1462                     bootconf=auto
1463                     echo 1>&2 "$PRG: WARNING: Deprecated option --device"
1464                     ARGS="$ARGS $1 $2"
1465                     shift 2
1466                 else
1467                     echo 1>&2 "$PRG: option requires an argument $1"
1468                     echo 1>&2 "Try \`$PRG --help' for more information."
1469                     exit 1
1470                 fi
1471                 ;;
1472             --timeout)
1473                 if [ -n "$2" ] ; then
1474                     timeout="$2"
1475                     bootconf=auto
1476                     echo 1>&2 "$PRG: WARNING: Deprecated option --device"
1477                     ARGS="$ARGS $1 $2"
1478                     shift 2
1479                 else
1480                     echo 1>&2 "$PRG: option requires an argument $1"
1481                     echo 1>&2 "Try \`$PRG --help' for more information."
1482                     exit 1
1483                 fi
1484                 ;;
1485             --image)
1486                 if [ -n "$2" ] ; then
1487                     image="$2"
1488                     bootconf=auto
1489                     echo 1>&2 "$PRG: WARNING: Deprecated option --device"
1490                     ARGS="$ARGS $1 $2"
1491                     shift 2
1492                 else
1493                     echo 1>&2 "$PRG: option requires an argument $1"
1494                     echo 1>&2 "Try \`$PRG --help' for more information."
1495                     exit 1
1496                 fi
1497                 ;;
1498             --label)
1499                 if [ -n "$2" ] ; then
1500                     label="$2"
1501                     bootconf=auto
1502                     echo 1>&2 "$PRG: WARNING: Deprecated option --device"
1503                     ARGS="$ARGS $1 $2"
1504                     shift 2
1505                 else
1506                     echo 1>&2 "$PRG: option requires an argument $1"
1507                     echo 1>&2 "Try \`$PRG --help' for more information."
1508                     exit 1
1509                 fi
1510                 ;;
1511             --partition)
1512                 if [ -n "$2" ] ; then
1513                     partition="$2"
1514                     bootconf=auto
1515                     echo 1>&2 "$PRG: WARNING: Deprecated option --device"
1516                     ARGS="$ARGS $1 $2"
1517                     shift 2
1518                 else
1519                     echo 1>&2 "$PRG: option requires an argument $1"
1520                     echo 1>&2 "Try \`$PRG --help' for more information."
1521                     exit 1
1522                 fi
1523                 ;;
1524             --root)
1525                 if [ -n "$2" ] ; then
1526                     root="$2"
1527                     bootconf=auto
1528                     echo 1>&2 "$PRG: WARNING: Deprecated option --device"
1529                     ARGS="$ARGS $1 $2"
1530                     shift 2
1531                 else
1532                     echo 1>&2 "$PRG: option requires an argument $1"
1533                     echo 1>&2 "Try \`$PRG --help' for more information."
1534                     exit 1
1535                 fi
1536                 ;;
1537             "")
1538                 break
1539                 ;;
1540             *)
1541                 echo 1>&2 "$PRG: unrecognized option \`$1'"
1542                 echo 1>&2 "Try \`$PRG --help' for more information."
1543                 exit 1
1544                 ;;
1545         esac
1546     done
1547 fi
1548
1549 ## check that specified config file exists, unless its /dev/null in
1550 ## which case we assume all options are done on the command line.
1551 if [ "$CONF" = /dev/null ] ; then
1552     true
1553 else
1554     confexist || exit 1
1555 fi
1556
1557 ## if there is no config file use the automatic generation to make a
1558 ## generic yaboot.conf. do this before the confcheck to avoid wierd errors.
1559 if [ "$bootconf" = /dev/null ] ; then
1560     if (command -v yabootconfig > /dev/null 2>&1) ; then
1561         echo 1>&2 "$PRG: Warning: no /etc/yaboot.conf, running yabootconfig to make one"
1562         yabootconfig --noinstall --quiet
1563         if [ $? != 0 ] ; then
1564             echo 1>&2 "$PRG: yabootconfig failed, please supply a valid /etc/yaboot.conf"
1565             echo 1>&2 "$PRG: You may also use $PRG's --boot, --image, --partition, and --device switches"
1566             echo 1>&2 "$PRG: These switches will cause $PRG to generate a basic yaboot.conf on the fly"
1567             exit 1
1568         else
1569             CONF=/etc/yaboot.conf
1570             bootconf=$CONF
1571             ERR=" Error in $CONF:"
1572             confexist || exit 1
1573         fi
1574     fi
1575 fi
1576
1577 ## Checks if each option was defined on the command line, and if so
1578 ## don't read it from the configuration file. this avoids
1579 ## configuration options from being set null, as well as command line
1580 ## options from being clobbered.
1581 [ "$ARGBT" != 1 -a $(parseconf ck boot) = 0 ] && boot=`parseconf str boot`
1582 [ "$ARGOB" != 1 -a $(parseconf ck ofboot) = 0 ] && ofboot=`parseconf str ofboot`
1583 [ "$ARGBF" != 1 -a $(parseconf ck install) = 0 ] && install=`parseconf str install`
1584 [ "$ARGWP" != 1 -a $(parseconf ck magicboot) = 0 ] && magicboot=`parseconf str magicboot`
1585 [ "$ARGMT" != 1 -a $(parseconf flag usemount) = 0 ] && usemount=yes
1586 [ "$ARGFS" != 1 -a $(parseconf ck fstype) = 0 ] && fstype=`parseconf str fstype`
1587 [ "$ARGBS" != 1 -a $(parseconf flag nobless) = 0 ] && bless=no
1588 [ "$ARGPT" != 1 -a $(parseconf flag protect) = 0 ] && protect=yes
1589 [ "$ARGHD" != 1 -a $(parseconf flag hide) = 0 ] && hide=yes
1590 [ "$ARGNV" != 1 -a $(parseconf flag nonvram) = 0 ] && nonvram=1
1591 [ $(parseconf ck hfstype) = 0 ] && hfstype=`parseconf str hfstype`
1592 [ $(parseconf ck hfscreator) = 0 ] && hfscreator=`parseconf str hfscreator`
1593 [ $(parseconf ck mntpoint) = 0 ] && mntpoint=`parseconf str mntpoint`
1594 [ $(parseconf ck delay) = 0 ] && delay=`parseconf str delay`
1595 [ $(parseconf ck timeout) = 0 ] && timeout=`parseconf str timeout`
1596 [ $(parseconf ck bsd) = 0 ] && bsd=`parseconf str bsd`
1597 [ $(parseconf ck macos) = 0 ] && macos=`parseconf str macos`
1598 [ $(parseconf ck macosx) = 0 ] && macosx=`parseconf str macosx`
1599 [ $(parseconf ck darwin) = 0 ] && darwin=`parseconf str darwin`
1600 [ $(parseconf ck defaultos) = 0 ] && defaultos=`parseconf str defaultos`
1601 [ $(parseconf ck fgcolor) = 0 ] && fgcolor=`parseconf str fgcolor`
1602 [ $(parseconf ck bgcolor) = 0 ] && bgcolor=`parseconf str bgcolor`
1603 [ $(parseconf ck icon) = 0 ] && export YBINOFICON=`parseconf str icon`
1604 [ $(parseconf flag enablecdboot) = 0 ] && cdrom=yes
1605 [ $(parseconf flag enablenetboot) = 0 ] && network=yes
1606 [ $(parseconf flag enableofboot) = 0 ] && of=yes
1607 [ $(parseconf flag brokenosx) = 0 ] && brokenosx=yes
1608
1609 bootparts=0
1610 for i in $boot; do
1611     bootparts=$(($bootparts + 1))
1612 done
1613 if [ "$bootparts" -gt 1 ]; then
1614     [ "$VERBOSE" = 1 ] && echo "$PRG: Iterating through list of boot partitions..."
1615     rc=0
1616     for i in $boot; do
1617         [ "$VERBOSE" = 1 ] && echo "$ABSPRG $ARGS -b $i"
1618         $ABSPRG $ARGS -b $i || rc=$?
1619     done
1620     exit $rc
1621 fi
1622
1623 ## ffs!! rtfm! foad!
1624 if [ "$boot" = unconfigured ] ; then
1625     echo 1>&2 "$PRG: You must specify the device for the bootstrap partition. (ie: boot=/dev/hdaX)"
1626     echo 1>&2 "$PRG: Try \`$PRG --help' for more information."
1627     exit 1
1628 fi
1629
1630 ## if there is still no config file use the automatic generation to make a
1631 ## generic yaboot.conf. do this before the confcheck to avoid wierd errors.
1632 if [ "$bootconf" = /dev/null ] ; then
1633     echo 1>&2 "$PRG: Warning: no yaboot.conf, using generic configuration."
1634     bootconf=auto
1635 fi
1636
1637 ## mntpoint is incompatible with mkofboot.
1638 if [ "$PRG" = mkofboot -a -n "$mntpoint" ] ; then
1639     echo 1>&2 "$PRG: Cannot be used with \`mntpoint='"
1640     exit 1
1641 fi
1642
1643 ## validate configuration for sanity.
1644 checkconf || exit 1
1645
1646 ## check that we can use ofpath, its only needed for magicboot script
1647 ## building and nvram updates.
1648 if [ -n "$magicboot" -o "$nonvram" = 0 ] ; then
1649     if [ -z "$ofboot" -o -n "$macos" -o -n "$macosx" -o -n "$darwin" ] ; then
1650         if (command -v ofpath > /dev/null 2>&1) ; then
1651             [ -x `command -v ofpath` ]
1652             if [ $? != 0 ] ; then
1653                 echo 1>&2 "$PRG: ofpath could not be found, aborting."
1654                 exit 1
1655             fi
1656         else
1657             echo 1>&2 "$PRG: ofpath could not be found, aborting."
1658             exit 1
1659         fi
1660     fi
1661 fi
1662
1663 ## if password is set in yaboot.conf make sure permissions on that
1664 ## file are safe, warn if not.
1665 if (grep -q '^[[:space:]]*password[[:space:]]*=' "$bootconf" > /dev/null 2>&1) ; then
1666     permcheck
1667 fi
1668
1669 ## check if we are root if needed.
1670 if [ "$usemount" = yes -a -z "$mntpoint" ] ; then
1671     if [ `id -u` != 0 ] ; then
1672         echo 1>&2 "$PRG: \`usemount' requires root privileges, go away."
1673         exit 1
1674     fi
1675 fi
1676
1677 if [ "$fstype" = hfs ] ; then
1678     checkhfsutils
1679     if [ $? != 0 ] ; then
1680         echo 1>&2 "$PRG: hfsutils is not installed or cannot be found"
1681         echo 1>&2 "$PRG: Try --mount if `uname -sr` supports HFS"
1682         exit 1
1683     fi
1684 fi
1685
1686 ## convert unix device nodes to OpenFirmware pathnames
1687 if [ -n "$magicboot" -o "$nonvram" = 0 ] ; then
1688     convertpath || exit 1
1689 fi
1690
1691 ## yaboot.conf autogeneration. MUST have secure mktemp to
1692 ## avoid race conditions. Debian's mktemp qualifies.
1693 if [ "$bootconf" = auto ] ; then
1694     TMPCONF=`mktemp -q "$TMP/$PRG.XXXXXX"`
1695     if [ $? != 0 ] ; then
1696         echo 1>&2 "$PRG: Could not create temporary file, aborting."
1697         exit 1
1698     fi
1699
1700     mkconf
1701     if [ $? != 0 ] ; then
1702         echo 1>&2 "$PRG: An error occured generating yaboot.conf, aborting."
1703         exit 1
1704     fi
1705
1706     bootconf="$TMPCONF"
1707 fi
1708
1709 if [ -n "$magicboot" ] ; then
1710     checkfirststage || exit 1
1711     if [ "$FIRSTSTG" = compat ] ; then
1712         mkfirststage
1713         if [ $? != 0 ] ; then
1714             echo 1>&2 "$PRG: An error occured while building first stage loader.  aborting..."
1715             exit 1
1716         fi
1717     fi
1718 fi
1719
1720 case "$PRG" in
1721     ybin)
1722         case "$usemount" in
1723             no)
1724                 if [ "$fstype" = raw ] ; then
1725                     luserck || exit 1
1726                     raw_install || exit 1
1727                 else
1728                     util_install || exit 1
1729                 fi
1730                 exit 0
1731                 ;;
1732             yes)
1733                 mnt_install || exit 1
1734                 exit 0
1735                 ;;
1736         esac
1737         ;;
1738     mkofboot)
1739         case "$usemount" in
1740             no)
1741                 ## its not nice to erase the partition and then bail!
1742                 if [ "$fstype" = msdos ] ; then
1743                     echo 1>&2 "$PRG: mtools support is not implemented"
1744                     echo 1>&2 "$PRG: Use --mount or add \`usemount' to $CONF"
1745                     exit 1
1746                 fi
1747                 confirm || exit 2
1748                 if [ "$fstype" = raw ] ; then
1749                     raw_install || exit 1
1750                 else
1751                     mkoffs || exit 1
1752                     util_install || exit 1
1753                 fi
1754                 [ "$VERBOSE" = 1 ] && echo "$PRG: Installation complete."
1755                 exit 0
1756                 ;;
1757             yes)
1758                 confirm || exit 2
1759                 mkoffs || exit 1
1760                 mnt_install || exit 1
1761                 [ "$VERBOSE" = 1 ] && echo "$PRG: Installation complete."
1762                 exit 0
1763                 ;;
1764         esac
1765         ;;
1766 esac
1767
1768 exit 0