3 ###############################################################################
5 ## ybin (YaBoot INstaller) installs/updates the yaboot bootloader.
6 ## Copyright (C) 2000, 2001 Ethan Benson
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.
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.
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.
22 ###############################################################################
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"
30 SIGINT="$PRG: Interrupt caught ... exiting"
37 ## catch signals, clean up junk in /tmp.
40 trap "echo 1>&2 $SIGINT ; exit 130" 2
44 ## allow for non-existent config file, in which case it will be
45 ## generated from command line arguments.
46 if [ -f /etc/yaboot.conf ] ; then
49 ERR=" Error in $CONF:"
55 ## define default configuration
58 ## allow default to work on packaged and non-packaged yaboot.
59 ## no default for magicboot since it is not required everywhere.
60 if [ -f /usr/local/lib/yaboot/yaboot ] ; then
61 install=/usr/local/lib/yaboot/yaboot
62 elif [ -f /usr/lib/yaboot/yaboot ] ; then
63 install=/usr/lib/yaboot/yaboot
83 ## yaboot autoconf defaults
91 ## this program behaves differently based on how its called, this
92 ## ensures that nothing nasty happens if someone makes a bogus
100 echo 1>&2 "This program must be called as either \`ybin' or \`mkofboot'"
105 ## check for printf, use it if possible otherwise fall back on
106 ## unreliable echo -e -n ("SUS" says echo shall support no switches)
107 if [ "$(printf printf_test 2>/dev/null)" = printf_test ] ; then
113 ## make fake `id' if its missing, outputs 0 since if its missing we
114 ## are probably running on boot floppies and thus are root.
115 if (command -v id > /dev/null 2>&1) ; then
129 Written by Ethan Benson
131 Copyright (C) 2000, 2001 Ethan Benson
132 This is free software; see the source for copying conditions. There is NO
133 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
140 "Usage: $PRG [OPTION]...
141 Update/install bootloader onto a bootstrap partition.
143 -b, --boot set bootstrap partition device [ -b /dev/hda2 ]
144 -o, --ofboot set bootstrap partition OpenFirmware device
145 default: automatically determined [ -o hd:2 ]
146 -i, --install pathname to the actual bootloader binary
147 default: /usr/{local/}lib/yaboot/yaboot same as
148 install= in config file [ -i bootloader_file ]
149 -C, --config use alternate configuration file (ybin and yaboot)
151 -m, --magicboot pathname to a OpenFirmware magicboot (CHRP) script
152 --filesystem set the filesystem type of the bootstrap partition
153 available options are hfs, msdos, and raw
154 [ --filesystem hfs ] default is hfs
155 --nobless don't bless the root directory, this should only
156 be used if you are using a MacOS boot partition
157 as the bootstrap partition (not recommended)
158 -M, --mount don't use userspace hfsutils to modify the
159 bootstrap instead try and mount the filesystem
160 directly. Note that attributes cannot be set
161 this way and you will have to manually modify
162 OpenFirmware to make your system bootable
163 --protect set the read-only (locked) bit on all bootstrap
165 --hide set the invisible bit on all bootstrap files
166 this is useful of you don't want them to be
168 --nonvram do not update the boot-device variable in nvram.
169 --device yaboot auto configuration: sets the OF boot device
171 --partition yaboot auto configuration: sets the partition
172 number of the root partition. default: 3
173 --timeout yaboot auto configuration: sets the time yaboot
174 will wait for user input before booting default
175 image default: 40 (4 seconds)
176 --image yaboot auto configuration: sets the path to the
177 kernel image. default: /vmlinux
178 --label yaboot auto configuration: sets the image label
180 --root yaboot auto configuration: sets the root device
182 --force don't ever ask for confirmation
183 -v, --verbose make $PRG more verbose
184 --debug print boring junk only useful for debugging
185 -h, --help display this help and exit
186 -V, --version output version information and exit"
189 ## configuration file parsing. FIXME: need a method which can parse
195 v=`grep "^$2[\ ,=]" "$CONF"` ; echo "${v#*=}"
198 grep "^$2\>" "$CONF" > /dev/null && echo 0 || echo 1
201 grep "^$2[\ ,=]" "$CONF" > /dev/null && echo 0 || echo 1
206 ## check for existence of a configuration file, and make sure we have
210 if [ ! -e "$CONF" ] ; then
211 echo 1>&2 "$PRG: $CONF: No such file or directory"
213 elif [ ! -f "$CONF" ] ; then
214 echo 1>&2 "$PRG: $CONF: Not a regular file"
216 elif [ ! -r "$CONF" ] ; then
217 echo 1>&2 "$PRG: $CONF: Permission denied"
224 ## check to make sure the configuration file is sane and correct.
225 ## maybe this is an insane ammount of error checking, but I want to
226 ## make sure (hopfully) nothing unexpected ever happens. and i just
227 ## like useful errors from programs. every error just marks an error
228 ## variable so we give the user as much info as possible before we
232 if [ ! -e "$boot" ] ; then
233 echo 1>&2 "$PRG: $boot: No such file or directory"
235 elif [ ! -b "$boot" -a ! -f "$boot" ] ; then
236 echo 1>&2 "$PRG: $boot: Not a regular file or block device"
238 elif [ ! -w "$boot" -o ! -r "$boot" ] ; then
239 [ -z "$mntpoint" ] && echo 1>&2 "$PRG: $boot: Permission denied"
240 [ -z "$mntpoint" ] && CONFERR=1
243 if [ ! -e "$install" ] ; then
244 echo 1>&2 "$PRG: $install: No such file or directory"
246 elif [ ! -f "$install" ] ; then
247 echo 1>&2 "$PRG: $bootconf: Not a regular file"
249 elif [ ! -r "$install" ] ; then
250 echo 1>&2 "$PRG: $install: Permission denied"
254 if [ "$bootconf" = auto ] ; then
256 elif [ ! -e "$bootconf" ] ; then
257 echo 1>&2 "$PRG: $bootconf: No such file or directory"
259 elif [ ! -f "$bootconf" ] ; then
260 echo 1>&2 "$PRG: $bootconf: Not a regular file"
262 elif [ ! -r "$bootconf" ] ; then
263 echo 1>&2 "$PRG: $bootconf: Permission denied"
267 if [ -n "$magicboot" ] ; then
268 if [ ! -e "$magicboot" ] ; then
269 echo 1>&2 "$PRG: $magicboot: No such file or directory"
271 elif [ ! -f "$magicboot" ] ; then
272 echo 1>&2 "$PRG: $magicboot: Not a regular file"
274 elif [ ! -r "$magicboot" ] ; then
275 echo 1>&2 "$PRG: $magicboot: Permission denied"
284 if [ "$ARGFS" = 1 ] ; then
285 echo 1>&2 "$PRG: --filesystem must be either \`hfs', \`msdos', or \`raw'"
287 echo 1>&2 "$PRG:$ERR \`fstype' must be either \`hfs', \`msdos', or \`raw'"
293 ## if we are not using HFS filesystems we don't care about HFS
295 if [ "$fstype" = hfs ] ; then
296 if [ `echo ${#hfstype}` != 4 ] ; then
297 if [ "$ARGTP" = 1 ] ; then
298 echo 1>&2 "$PRG: --type must be 4 characters"
300 echo 1>&2 "$PRG:$ERR \`hfstype' must be 4 characters"
305 if [ `echo ${#hfscreator}` != 4 ] ; then
306 if [ "$ARGCT" = 1 ] ; then
307 echo 1>&2 "$PRG: --creator must be 4 characters"
309 echo 1>&2 "$PRG:$ERR \`hfscreator' must be 4 characters"
315 ## some options are not compatible with fstype=raw
316 if [ "$fstype" = raw ] ; then
317 if [ -n "$mntpoint" ] ; then
318 echo 1>&2 "$PRG:$ERR \`mntpoint' is not compatible with fstype=raw"
321 if [ "$usemount" = yes ] ; then
322 echo 1>&2 "$PRG:$ERR \`usemount' is not compatible with fstype=raw"
325 if [ -n "$magicboot" ] ; then
326 echo 1>&2 "$PRG:$ERR \`magicboot' scripts cannot be used with fstype=raw"
331 if [ -n "$mntpoint" ] ; then
333 if [ ! -e "$mntpoint" ] ; then
334 echo 1>&2 "$PRG: $mntpoint: No such file or directory"
336 elif [ ! -d "$mntpoint" ] ; then
337 echo 1>&2 "$PRG: $mntpoint: Not a directory"
339 elif [ ! -w "$mntpoint" -o ! -r "$mntpoint" ] ; then
340 echo 1>&2 "$PRG: $mntpoint: Permission denied"
342 elif [ ! -O "$mntpoint" -a `id -u` != 0 ] ; then
343 echo 1>&2 "$PRG: $mntpoint: Permission denied (not owner)"
347 ## make sure no embedded spaces exist
348 echo "$mntpoint" | grep -q [[:space:]]
350 echo 1>&2 "$PRG:$ERR \`mntpoint=$mntpoint' contains embedded spaces, don't use lame filenames"
354 ## make sure $mntpoint is on $boot, this matters to nvram updating.
355 if [ "$(v=`df "$mntpoint" 2> /dev/null | grep ^/dev/` ; echo ${v%%[ ]*})" != "$boot" -a -d "$mntpoint" ] ; then
356 echo 1>&2 "$PRG: $mntpoint is not located on $boot"
358 ## more then one subdirectory deep is not supported. no sed available on boot floppies ( / -> \ )
359 elif [ "$mntpoint" != "$(v=`df "$mntpoint" 2> /dev/null | grep ^/dev/` ; echo ${v##*[ ]})" ] ; then
360 echo "$(v=`df "$mntpoint" 2>/dev/null | grep ^/dev/`; m=${v##*[ ]}; echo "${mntpoint##*$m/}")" | grep -q /
362 echo 1>&2 "$PRG:$ERR $mntpoint is more then one subdirectory deep from root of $boot"
365 OFDIR="$(v=`df "$mntpoint" 2>/dev/null | grep ^/dev/`; m=${v##*[ ]}; echo "${mntpoint##*$m/}")"
369 if [ "$usemount" = no ] ; then
370 echo 1>&2 "$PRG:$ERR \`mntpoint=' requires \`usemount' be set"
375 if [ -n "$magicboot" ] ; then
376 ## check for bsd loader
377 if [ -n "$bsd" ] ; then
378 if [ -f /usr/lib/yaboot/ofwboot -a -r /usr/lib/yaboot/ofwboot ] ; then
379 BSDLOADER="/usr/lib/yaboot/ofwboot"
380 elif [ -f /usr/local/lib/yaboot/ofwboot -a -r /usr/local/lib/yaboot/ofwboot ] ; then
381 BSDLOADER="/usr/local/lib/yaboot/ofwboot"
383 echo 1>&2 "$PRG: /usr/local/lib/yaboot/ofwboot: No such file or directory"
384 echo 1>&2 "$PRG: With the bsd= option set you must have the bsd boot loader ofwboot"
389 ## convert defaultos variable
391 linux|Linux|GNU|Gnu|gnu)
398 if [ -z "$bsd" ] ; then
399 echo 1>&2 "$PRG:$ERR no entry for \`bsd' found, but defaultos is set to \`bsd'"
405 if [ -z "$macos" ] ; then
406 echo 1>&2 "$PRG:$ERR no entry for \`macos' found, but defaultos is set to \`macos'"
412 if [ -z "$macosx" ] ; then
413 echo 1>&2 "$PRG:$ERR no entry for \`macosx' found, but defaultos is set to \`macosx'"
419 if [ -z "$darwin" ] ; then
420 echo 1>&2 "$PRG:$ERR no entry for \`darwin' found, but defaultos is set to \`darwin'"
425 echo 1>&2 "$PRG:$ERR \`defaultos' must be either \`linux', \`bsd', \`macos' or \`macosx'"
431 ## nvsetenv requires /proc
432 if [ ! -f /proc/uptime -a "$nonvram" = 0 ] ; then
433 echo 1>&2 "$PRG: /proc filesystem is not mounted, nvram will not be updated"
437 if [ "$nonvram" = 0 ] ; then
438 ## see if nvsetenv exists and is executable
439 if (command -v nvsetenv > /dev/null 2>&1) ; then
440 [ -x `command -v nvsetenv` ] || MISSING=1 ; else MISSING=1
443 if [ "$nonvram" = 0 ] ; then
444 ## if nvsetenv exists see if its the old broken version
445 if [ "$MISSING" != 1 ] ; then
446 nvsetenv --version > /dev/null 2>&1 || OLD=1
449 echo 1>&2 "$PRG: Warning: \`nvsetenv' could not be found, nvram will not be updated"
452 if [ "$OLD" = 1 ] ; then
453 ## i check this myself to avoid misleading error
454 ## messages. nvsetenv should REALLY support --version.
455 if [ ! -e /dev/nvram ] ; then
456 echo 1>&2 "$PRG: /dev/nvram: No such file or directory"
457 echo 1>&2 "$PRG: Warning: nvram will not be updated"
459 elif [ ! -c /dev/nvram ] ; then
460 echo 1>&2 "$PRG: /dev/nvram: Not a character device"
461 echo 1>&2 "$PRG: Warning: nvram will not be updated"
463 elif [ ! -w /dev/nvram -o ! -r /dev/nvram ] ; then
464 echo 1>&2 "$PRG: /dev/nvram: Permission denied"
465 echo 1>&2 "$PRG: Warning: nvram will not be updated"
469 echo 1>&2 "$PRG: Warning: Incompatible version of \`nvsetenv', nvram will not be updated"
474 if [ -f "$boot" ] ; then
475 echo 1>&2 "$PRG: $boot is a regular file, disabling nvram updating"
480 ## check for newworld mac. use cat hack due to /proc wierdness.
481 ## do not bail if we are on an OldWorld only warn (very loudly).
482 if [ "$(v=`cat /proc/cpuinfo 2>/dev/null | grep pmac-generation` ; echo ${v##*:})" = NewWorld ] ; then
484 elif [ "$(v=`cat /proc/cpuinfo 2>/dev/null | grep pmac-generation` ; echo ${v##*:})" = OldWorld ] ; then
486 echo 1>&2 '@@@@@@@@@@@@@@ WARNING!! WARNING!! WARNING!! @@@@@@@@@@@@@@'
487 echo 1>&2 "$PRG: Warning: This is an OldWorld PowerMac, $boot will **NOT** be bootable on this machine"
488 echo 1>&2 "$PRG: Oldworld PowerMacs need to use the quik bootloader, not yaboot"
489 echo 1>&2 '@@@@@@@@@@@@@@ WARNING!! WARNING!! WARNING!! @@@@@@@@@@@@@@'
491 [ "$nonvram" = 0 ] && echo 1>&2 "$PRG: OldWorld PowerMac, nvram will not be updated"
493 elif (cat /proc/cpuinfo 2>/dev/null | grep ^motherboard | grep -q AAPL) ; then
495 echo 1>&2 '@@@@@@@@@@@@@@ WARNING!! WARNING!! WARNING!! @@@@@@@@@@@@@@'
496 echo 1>&2 "$PRG: Warning: This is an OldWorld PowerMac, $boot will **NOT** be bootable on this machine"
497 echo 1>&2 "$PRG: Oldworld PowerMacs need to use the quik bootloader, not yaboot"
498 echo 1>&2 '@@@@@@@@@@@@@@ WARNING!! WARNING!! WARNING!! @@@@@@@@@@@@@@'
500 [ "$nonvram" = 0 ] && echo 1>&2 "$PRG: OldWorld PowerMac, nvram will not be updated"
502 elif (cat /proc/cpuinfo 2> /dev/null | grep ^machine | grep -q 'CHRP IBM') ; then
503 ## IBM hardware does not need nvram update AFAICT
507 #echo 1>&2 "$PRG: Warning: Unknown archetecture, $boot may not be bootable on this machine"
508 [ "$nonvram" = 0 ] && echo 1>&2 "$PRG: Warning: Unknown architecture, nvram will not be updated"
512 ## convert human readable color values from config to proper color
515 black) fgc=0 ;; blue) fgc=1 ;; green) fgc=2 ;; cyan) fgc=3 ;;
516 red) fgc=4 ;; purple) fgc=5 ;; brown) fgc=6 ;; light-gray) fgc=7 ;;
517 dark-gray) fgc=8 ;; light-blue) fgc=9 ;; light-green) fgc=a ;;
518 light-cyan) fgc=b ;; light-red) fgc=c ;; light-purple) fgc=d ;;
519 yellow) fgc=e ;; white) fgc=f ;;
521 echo 1>&2 "$PRG:$ERR Invalid fgcolor: \`$fgcolor'"
526 black) bgc=0 ;; blue) bgc=1 ;; green) bgc=2 ;; cyan) bgc=3 ;;
527 red) bgc=4 ;; purple) bgc=5 ;; brown) bgc=6 ;; light-gray) bgc=7 ;;
528 dark-gray) bgc=8 ;; light-blue) bgc=9 ;; light-green) bgc=a ;;
529 light-cyan) bgc=b ;; light-red) bgc=c ;; light-purple) bgc=d ;;
530 yellow) bgc=e ;; white) bgc=f ;;
532 echo 1>&2 "$PRG:$ERR Invalid bgcolor: \`$bgcolor'"
537 ## if delay is not set use yaboot's timeout
538 if [ -z "$delay" ] ; then
539 delay="$(($timeout / 10))"
542 if [ "$CONFERR" = 1 ] ; then
550 ## if readlink is missing use a kludge
551 if (command -v readlink > /dev/null 2>&1) ; then
556 SYMTARGET="$(v=`ls -l "$2" 2>/dev/null` ; echo ${v##*> })"
557 if [ -n "$SYMTARGET" ] ; then
566 ## /etc/yaboot.conf with password should not be world readable.
569 if [ -L "$bootconf" ] ; then
570 local realfile="$(readlink -f "$bootconf")" || return 0
572 local realfile="$bootconf"
575 ## don't bother if we could not read the symlink
576 [ -z "$realfile" ] && return 0
577 [ ! -f "$realfile" ] && return 0
579 ## get permissions, and don't bother checking if we can't
580 local PERM=`v=$(ls -l "$realfile" 2>/dev/null) ; echo ${v%% *}`
581 [ -z "$PERM" ] && return 0
582 [ `echo ${#PERM}` != 10 ] && return 0
585 -rw-------|-r--------)
586 if [ ! -O "$realfile" -a `id -u` = 0 ] ; then
587 echo 1>&2 "$PRG: Warning: $bootconf is not owned by root"
590 -rw-r-----|-r--r-----)
591 if [ ! -O "$realfile" -a `id -u` = 0 ] ; then
592 echo 1>&2 "$PRG: Warning: $bootconf is not owned by root"
594 if [ ! -G "$realfile" -a `id -g` = 0 ] ; then
595 echo 1>&2 "$PRG: Warning: $bootconf is not owned by group root"
598 -r--r--r--|-rw-r--r--|-rw-rw-r--|-rw-rw-rw-|-rw-rw----)
599 echo 1>&2 "$PRG: Warning: Insecure permissions on $bootconf: $PERM should be -rw-------"
602 echo 1>&2 "$PRG: Warning: Incorrect permissions on $bootconf: $PERM should be -rw-------"
609 ## figure out bootstrap device OF pathname if user did not supply it.
610 if [ -z "$ofboot" ] ; then
611 [ "$VERBOSE" = 1 ] && echo "$PRG: Finding OpenFirmware device path to \`$boot'..."
612 ofboot="$(ofpath $boot)"
613 if [ $? != 0 ] ; then
614 echo 1>&2 "$PRG: Unable to find OpenFirmware path for boot=$boot"
615 echo 1>&2 "$PRG: Please add ofboot=<path> where <path> is the OpenFirmware path to $boot to $CONF"
618 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: ofboot set to \`$ofboot'"
621 ## figure out OF device path for macos/macosx if user supplied a unix device node.
622 if [ -n "$bsd" ] ; then
625 [ "$VERBOSE" = 1 ] && echo "$PRG: Finding OpenFirmware device path to \`$bsd'..."
628 if [ $? != 0 ] ; then
629 echo 1>&2 "$PRG: Unable to determine OpenFirmware path for bsd=$sbsd"
630 echo 1>&2 "$PRG: Try specifying the real OpenFirmware path for bsd=$sbsd in $CONF"
633 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: bsd set to \`$bsd' from \`$sbsd'"
636 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: bsd left alone: \`$bsd'"
641 if [ -n "$macos" ] ; then
644 [ "$VERBOSE" = 1 ] && echo "$PRG: Finding OpenFirmware device path to \`$macos'..."
645 local smacos="$macos"
646 macos="$(ofpath $macos)"
647 if [ $? != 0 ] ; then
648 echo 1>&2 "$PRG: Unable to determine OpenFirmware path for macos=$smacos"
649 echo 1>&2 "$PRG: Try specifying the real OpenFirmware path for macos=$smacos in $CONF"
652 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: macos set to \`$macos' from \`$smacos'"
655 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: macos left alone: \`$macos'"
660 if [ -n "$macosx" ] ; then
663 [ "$VERBOSE" = 1 ] && echo "$PRG: Finding OpenFirmware device path to \`$macosx'..."
664 local smacosx="$macosx"
665 macosx="$(ofpath $macosx)"
666 if [ $? != 0 ] ; then
667 echo 1>&2 "$PRG: Unable to determine OpenFirmware path for macosx=$smacosx"
668 echo 1>&2 "$PRG: Try specifying the real OpenFirmware path for macosx=$smacosx in $CONF"
671 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: macosx set to \`$macosx' from \`$smacosx'"
674 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: macosx left alone: \`$macosx'"
679 if [ -n "$darwin" ] ; then
682 [ "$VERBOSE" = 1 ] && echo "$PRG: Finding OpenFirmware device path to \`$darwin'..."
683 local sdarwin="$darwin"
684 darwin="$(ofpath $darwin)"
685 if [ $? != 0 ] ; then
686 echo 1>&2 "$PRG: Unable to determine OpenFirmware path for darwin=$sdarwin"
687 echo 1>&2 "$PRG: Try specifying the real OpenFirmware path for darwin=$sdarwin in $CONF"
690 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: darwin set to \`$darwin' from \`$sdarwin'"
693 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: darwin left alone: \`$darwin'"
698 if [ "$CONVERR" = 1 ] ; then
705 ## make sure the hfsutils we need are installed and executable.
708 if (command -v hmount > /dev/null 2>&1) ; then
709 [ -x `command -v hmount` ] || FAIL=1 ; else FAIL=1 ; fi
710 if (command -v humount > /dev/null 2>&1) ; then
711 [ -x `command -v humount` ] || FAIL=1 ; else FAIL=1 ; fi
712 if (command -v hcopy > /dev/null 2>&1) ; then
713 [ -x `command -v hcopy` ] || FAIL=1 ; else FAIL=1 ; fi
714 if (command -v hattrib > /dev/null 2>&1) ; then
715 [ -x `command -v hattrib` ] || FAIL=1 ; else FAIL=1 ; fi
716 if (command -v hformat > /dev/null 2>&1) ; then
717 [ -x `command -v hformat` ] || FAIL=1 ; else FAIL=1 ; fi
719 if [ "$FAIL" = 1 ] ; then
726 ## This is gross, IBM CHRP OF needs a .note added to the yaboot
727 ## binary, nobody knows whether this note will affect PowerMac OF or
728 ## not (or could in the future).
731 local YBDIR="${install%/*}"
732 if [ -x "$YBDIR/addnote" ] ; then
733 TMPYABOOT=`mktemp -q "$TMP/yaboot.XXXXXX"`
734 if [ $? != 0 ] ; then
735 echo 1>&2 "$PRG: Could not create temporary file, aborting."
738 if (cat "$install" > "$TMPYABOOT" 2> /dev/null) ; then
741 echo 1>&2 "$PRG: Could not create temporary file, aborting."
745 [ "$DEBUG" = 1 ] && echo "$PRG: Embedding CHRP note section in temp yaboot..."
746 "$YBDIR/addnote" "$install" > /dev/null 2>&1
747 if [ $? != 0 ] ; then
748 echo 1>&2 "$PRG: Could not install note section required by your architecture"
752 echo 1>&2 "$PRG: Your architecture requires $YBDIR/addnote which cannot be found"
758 ## install using userspace utilities rather then kernel filesytem
759 ## support. hfsutils only, mtools not supported.
762 ## catch signals, and humount, cleanup done by trap 0.
763 trap "humount $boot ; exit 129" 1
764 trap "echo 1>&2 $SIGINT ; humount $boot ; exit 130" 2
765 trap "humount $boot ; exit 131" 3
766 trap "humount $boot ; exit 143" 15
768 ## filenames on bootstrap partition. ofboot hard codes yaboot.
770 local CFFILE=yaboot.conf
772 ## if there is a magicboot script to install we will give it the
773 ## hfstype (should be "tbxi") and give yaboot type "boot".
774 if [ -n "$magicboot" ] ; then
777 local BTTYPE="$hfstype"
780 if [ -n "$magicboot" ] ; then
781 local WRAP="${magicboot##*/}"
784 ## set verbose messages here so they don't show temporary file paths
785 local INSTALLFIRST="$PRG: Installing first stage bootstrap $magicboot onto $boot..."
786 local INSTALLPRIMARY="$PRG: Installing primary bootstrap $install onto $boot..."
788 ## repoint magicboot as the real first stage loader if using the
789 ## modern automatic generating ofboot.b.
790 if [ -n "$FIRST" ] ; then
792 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: set magicboot to $FIRST"
795 ## gross hack, add note section for IBM CHRP
796 if [ "$ADDNOTE" = yes ] ; then
797 hack_yaboot || return 1
800 if [ "$fstype" = hfs ] ; then
801 if [ "$protect" = yes ] ; then
805 if [ "$hide" = yes ] ; then
809 ## make sure the device is not mounted as a filesystem before
810 ## we start mucking with it directly.
811 mount | grep "^$boot\>" > /dev/null
813 echo 1>&2 "$PRG: $boot appears to be mounted! aborting."
817 ## hmount is really more of a way to make sure we have a valid HFS
818 ## filesystem before proceding, and hcopy requires it...
819 hmount "$boot" > /dev/null
820 if [ $? != 0 ] ; then
821 echo 1>&2 "$PRG: $boot appears to have never had a bootstrap installed, please run mkofboot"
825 ## must be explicit with target filename to avoid hfsutils
826 ## braindamage ("_" -> " " filename mangling) also avoid
827 ## ambiguity in the bootstrap partition.
828 if [ -n "$magicboot" ] ; then
829 [ "$VERBOSE" = 1 ] && echo "$INSTALLFIRST"
830 hcopy -r "$magicboot" :ofboot.b
831 if [ $? != 0 ] ; then
832 echo 1>&2 "$PRG: An error occured while writing to $boot"
837 [ "$VERBOSE" = 1 ] && echo "$INSTALLPRIMARY"
838 hcopy -r "$install" :"$BTFILE"
839 if [ $? != 0 ] ; then
840 echo 1>&2 "$PRG: An error occured while writing to $boot"
844 [ "$VERBOSE" = 1 ] && echo "$PRG: Installing $bootconf onto $boot..."
845 hcopy -r "$bootconf" :"$CFFILE"
846 if [ $? != 0 ] ; then
847 echo 1>&2 "$PRG: An error occured while writing to $boot"
851 if [ -n "$BSDLOADER" ] ; then
852 [ "$VERBOSE" = 1 ] && echo "$PRG: Installing $BSDLOADER onto $boot..."
853 hcopy -r "$BSDLOADER" :ofwboot
854 if [ $? != 0 ] ; then
855 echo 1>&2 "$PRG: An error occured while writing to $boot"
860 ## set all file's attributes, if a magicboot script exists it
861 ## gets the configured hfstype instead of yaboot (should be
862 ## "tbxi") so it gets booted by OF.
863 if [ -n "$magicboot" ] ; then
864 [ "$VERBOSE" = 1 ] && echo "$PRG: Setting attributes on $WRAP..."
865 hattrib -t "$hfstype" -c "$hfscreator" $INVISIBLE $LOCK :ofboot.b
866 if [ $? != 0 ] ; then
867 echo 1>&2 "$PRG: Warning: error setting attributes on $WRAP"
868 echo 1>&2 "$PRG: This is probably bad but we'll ignore it."
872 [ "$VERBOSE" = 1 ] && echo "$PRG: Setting attributes on $BTFILE..."
873 hattrib -t "$BTTYPE" -c "$hfscreator" $INVISIBLE $LOCK :"$BTFILE"
874 if [ $? != 0 ] ; then
875 echo 1>&2 "$PRG: Warning: error setting attributes on $BTFILE"
876 echo 1>&2 "$PRG: This is probably bad but we'll ignore it"
879 [ "$VERBOSE" = 1 ] && echo "$PRG: Setting attributes on $CFFILE..."
880 hattrib -t "conf" -c "$hfscreator" $INVISIBLE $LOCK :"$CFFILE"
881 if [ $? != 0 ] ; then
882 echo 1>&2 "$PRG: Warning: error setting attributes on $CFFILE"
883 echo 1>&2 "$PRG: This is probably unimportant so we'll ignore it"
886 if [ -n "$BSDLOADER" ] ; then
887 [ "$VERBOSE" = 1 ] && echo "$PRG: Setting attributes on ofwboot..."
888 hattrib -t "bsdb" -c "$hfscreator" $INVISIBLE $LOCK :ofwboot
889 if [ $? != 0 ] ; then
890 echo 1>&2 "$PRG: Warning: error setting attributes on ofwboot"
891 echo 1>&2 "$PRG: This is probably unimportant so we'll ignore it"
895 ## bless the root directory so OF will find the boot file
896 if [ "$bless" = yes ] ; then
897 [ "$VERBOSE" = 1 ] && echo "$PRG: Blessing $boot with Holy Penguin Pee..."
899 if [ $? != 0 ] ; then
900 echo 1>&2 "$PRG: Warning: error blessing $boot"
901 echo 1>&2 "$PRG: This is probably bad but we'll ignore it"
905 ## clean up the ~/.hcwd file hmount creates
906 humount "$boot" > /dev/null
909 ## use explicit filename if we don't bless.
910 if [ "$bless" = yes ] ; then
911 local OFFILE='\\:tbxi'
913 if [ -n "$magicboot" ] ; then
914 local OFFILE=ofboot.b
916 local OFFILE="$BTFILE"
920 ## update the boot-device variable in OF nvram.
921 if [ "$nonvram" = 0 ] ; then
922 [ "$VERBOSE" = 1 ] && echo "$PRG: Updating OpenFirmware boot-device variable in nvram..."
923 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: boot-device=${ofboot},${OFFILE}"
924 nvsetenv boot-device "${ofboot},${OFFILE}"
925 if [ $? != 0 ] ; then
926 echo 1>&2 "$PRG: An error occured while updating nvram, we'll ignore it"
931 echo 1>&2 "$PRG: mtools support is not implemented"
932 echo 1>&2 "$PRG: Use --mount or add \`usemount' to $CONF"
939 ## used by mnt_install so mntpoint= can be supported in a cleaner way.
942 ## we can even create bootstrap filesystem images directly if you
944 if [ -f "$boot" ] ; then
948 if [ -e "$TMP/bootstrap.$$" ] ; then
949 echo 1>&2 "$PRG: $TMP/bootstrap.$$ exists, aborting."
953 mkdir -m 700 "$TMP/bootstrap.$$"
954 if [ $? != 0 ] ; then
955 echo 1>&2 "$PRG: Could not create mountpoint directory, aborting."
959 mount | grep "^$boot\>" > /dev/null
961 echo 1>&2 "$PRG: $boot appears to be mounted! aborting."
965 [ "$VERBOSE" = 1 ] && echo "$PRG: Mounting $boot..."
966 mount -t "$fstype" -o rw,umask=077$loop "$boot" "$TMP/bootstrap.$$"
967 if [ $? != 0 ] ; then
968 echo 1>&2 "$PRG: An error occured mounting $boot"
972 ## catch signals, set here to avoid umounting something we did not
973 ## mount. cleanup done by trap 0.
974 trap "umount $boot ; exit 129" 1
975 trap "echo 1>&2 $SIGINT ; umount $boot ; exit 130" 2
976 trap "umount $boot ; exit 131" 3
977 trap "umount $boot ; exit 143" 15
979 TARGET="$TMP/bootstrap.$$"
983 ## umnt funtion which checks whether we mounted anything or not, for
984 ## mntpoint= this makes the code below cleaner IMO.
987 if [ -z "$mntpoint" ] ; then
988 [ "$1" = failure ] && echo 1>&2 "$PRG: Attempting to umount $boot..."
990 if [ $? != 0 ] ; then
991 echo 1>&2 "$PRG: umount of $boot failed!"
994 [ "$1" = failure ] && echo 1>&2 "$PRG: umount successfull"
1002 ## Use kernel filesytem drivers to mount the bootstrap partition like
1003 ## any other filesystem and copy the files there with standard un*x
1009 ## msdosfs is broken, yaboot may not support this filename.
1010 if [ "$fstype" = msdos ] ; then
1011 local CFFILE=yaboot.cnf
1013 local CFFILE=yaboot.conf
1016 if [ -n "$magicboot" ] ; then
1017 local WRAP="${magicboot##*/}"
1020 ## set verbose messages here so they don't show temporary file paths
1021 local INSTALLFIRST="$PRG: Installing first stage bootstrap $magicboot onto $boot..."
1022 local INSTALLPRIMARY="$PRG: Installing primary bootstrap $install onto $boot..."
1024 ## repoint magicboot as the real first stage loader if using the
1025 ## modern automatic generating ofboot.b.
1026 if [ -n "$FIRST" ] ; then
1028 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: set magicboot to $FIRST"
1031 ## gross hack, add note section for IBM CHRP
1032 if [ "$ADDNOTE" = yes ] ; then
1033 hack_yaboot || return 1
1036 ## call mnt() function to take care of mounting filesystem if needed
1037 if [ -z "$mntpoint" ] ; then
1043 ## this is probably insecure on modern filesystems, but i think
1044 ## safe on crippled hfs/dosfs. user should ensure mntpoint= is safe.
1045 if [ -n "$magicboot" ] ; then
1046 [ "$VERBOSE" = 1 ] && echo "$INSTALLFIRST"
1047 cp -f "$magicboot" "$TARGET/ofboot.b"
1048 if [ $? != 0 ] ; then
1049 echo 1>&2 "$PRG: An error occured while writing to $boot"
1050 umnt failure "$TARGET"
1055 [ "$VERBOSE" = 1 ] && echo "$INSTALLPRIMARY"
1056 cp -f "$install" "$TARGET/$BTFILE"
1057 if [ $? != 0 ] ; then
1058 echo 1>&2 "$PRG: An error occured while writing to $boot"
1059 umnt failure "$TARGET"
1063 [ "$VERBOSE" = 1 ] && echo "$PRG: Installing $bootconf onto $boot..."
1064 cp -f "$bootconf" "$TARGET/$CFFILE"
1065 if [ $? != 0 ] ; then
1066 echo 1>&2 "$PRG: An error occured while writing to $boot"
1067 umnt failure "$TARGET"
1071 if [ -n "$BSDLOADER" ] ; then
1072 [ "$VERBOSE" = 1 ] && echo "$PRG: Installing $BSDLOADER onto $boot..."
1073 cp -f "$BSDLOADER" "$TARGET/ofwboot"
1074 if [ $? != 0 ] ; then
1075 echo 1>&2 "$PRG: An error occured while writing to $boot"
1076 umnt failure "$TARGET"
1081 if [ "$protect" = yes ] ; then
1082 [ "$VERBOSE" = 1 ] && echo "$PRG: Setting read-only attributes..."
1083 chmod a-w "$TARGET/$BTFILE"
1084 chmod a-w "$TARGET/$CFFILE"
1085 if [ -n "$magicboot" ] ; then
1086 chmod a-w "$TARGET/ofboot.b"
1088 if [ -n "$BSDLOADER" ] ; then
1089 chmod a-w "$TARGET/ofwboot"
1094 umnt success "$TARGET" || return 1
1096 ## make variable with a \ to avoid shell fsckage. ugly ugly ugly.
1098 if [ -n "$magicboot" ] ; then
1099 [ -n "$OFDIR" ] && OFDIR="${BS}${OFDIR}${BS}"
1100 local OFFILE="${OFDIR}ofboot.b"
1102 [ -n "$OFDIR" ] && OFDIR="${BS}${OFDIR}${BS}"
1103 local OFFILE="${OFDIR}${BTFILE}"
1106 ## update the boot-device variable in OF nvram.
1107 if [ "$nonvram" = 0 ] ; then
1108 [ "$VERBOSE" = 1 ] && echo "$PRG: Updating OpenFirmware boot-device variable in nvram..."
1109 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: boot-device=${ofboot},${OFFILE}"
1110 nvsetenv boot-device "${ofboot},${OFFILE}"
1111 if [ $? != 0 ] ; then
1112 echo 1>&2 "$PRG: An error occured while updating nvram, we'll ignore it"
1115 echo 1>&2 "$PRG: Warning: You must manually configure OpenFirmware to boot."
1121 ## raw installation, for IBM RS/6000 hardware, yaboot is dded to the
1122 ## bootstrap partition.
1125 ## make sure the device is not mounted as a filesystem before
1126 ## we start mucking with it directly.
1127 mount | grep "^$boot\>" > /dev/null
1128 if [ $? = 0 ] ; then
1129 echo 1>&2 "$PRG: $boot appears to be mounted! aborting."
1133 ## set verbosity message before munging the yaboot pathname
1134 local INSTALLPRIMARY="$PRG: Installing primary bootstrap $install onto $boot..."
1136 ## gross hack, add note section for IBM CHRP
1137 if [ "$ADDNOTE" = yes ] ; then
1138 hack_yaboot || return 1
1141 [ "$VERBOSE" = 1 ] && echo "$INSTALLPRIMARY"
1142 dd if=/dev/zero of="$boot" bs=512 count=1600 > /dev/null 2>&1
1143 dd if="$install" of="$boot" bs=512 > /dev/null 2>&1
1144 if [ $? != 0 ] ; then
1145 echo 1>&2 "$PRG: Installation failed."
1149 [ "$VERBOSE" = 1 ] && echo "$PRG: Installation successful"
1152 ## make sure the first stage ofboot generator is compatible.
1155 grep -q "^#%ybinscript-" "$magicboot" 2> /dev/null
1156 if [ "$?" = 0 ] ; then
1157 local magic=`grep "^#%ybinscript-" "$magicboot"`
1158 local ver="${magic##*-}"
1159 if [ "$ver" = "1.1" ] ; then
1163 echo 1>&2 "$PRG: Incompatible version of first stage loader $magicboot. aborting..."
1172 ## build the first stage loader.
1175 ## must have 7 backslashes to == \\ printf + shell = bizarre... or,
1176 ## make special variable to contain a \ (need \\ to make \) to work
1177 ## around echo -e -n brokeness.
1181 ## deal with mntpoint=
1182 [ -n "$OFDIR" ] && local OFDIR="${BS}${OFDIR}${BS}"
1184 ## some misguided people insist on installing OSX on
1185 ## HorribleFileSystem+ instead of UFS, as a result MacOS deblesses
1186 ## OSX, making it unbootable. if apple localizes the filesystem hierarchy again screw it.
1187 [ "$brokenosx" = yes ] && local OSXBOOT="${BS}System${BS}Library${BS}CoreServices${BS}BootX"
1188 [ "$brokenosx" = no ] && local OSXBOOT="${BS}${BS}:tbxi"
1190 ## assign variables for configured menu options.
1191 [ "$usemount" = no -a "$bless" = yes ] && local YB="yaboot GNU l $ofboot ,${BS}${BS}yaboot"
1192 [ "$usemount" = yes -o "$bless" = no ] && local YB="yaboot GNU l $ofboot ,${OFDIR}yaboot"
1193 [ -n "$bsd" ] && OS="$(($OS + 1))" && local BSD="ybsd BSD b $ofboot ,${BS}${BS}ofwboot/$bsd"
1194 [ -n "$macos" ] && OS="$(($OS + 1))" && local MAC="macos MacOS m $macos ,${BS}${BS}:tbxi"
1195 [ -n "$macosx" ] && OS="$(($OS + 1))" && local MX="macosx MacOSX x $macosx ,${OSXBOOT}"
1196 [ -n "$darwin" ] && OS="$(($OS + 1))" && local DW="darwin Darwin d $darwin ,${BS}${BS}:tbxi"
1197 [ "$cdrom" = yes ] && OS="$(($OS + 1))" && local CD="cd CDROM c cd: ,${BS}${BS}:tbxi"
1198 [ "$network" = yes ] && OS="$(($OS + 1))" && local NET="net Network n enet: 0"
1199 [ "$of" = yes ] && OS="$(($OS + 1))" && local OF="of OpenFirmware o quit now"
1200 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: OS=$OS"
1203 ## Usage: OS-count defaultos timeout fgc bgc osname oslabel oskey osdev osfile ...
1204 [ "$DEBUG" = 1 ] && $PRINTF 1>&2 "$PRG: DEBUG: /bin/sh $magicboot $OS $defaultos $delay $fbc $bgc $YB $BSD $MAC $MX $DW $CD $NET $OF\n"
1205 FIRST="$(/bin/sh "$magicboot" "$OS" "$defaultos" "$delay" $fgc $bgc ${YB} ${BSD} ${MAC} ${MX} ${DW} ${CD} ${NET} ${OF})" || return 1
1210 ## mkofboot function.
1213 mount | grep "^$boot\>" > /dev/null
1214 if [ $? = 0 ] ; then
1215 echo 1>&2 "$PRG: $boot appears to be mounted! aborting."
1221 [ "$VERBOSE" = 1 ] && echo "$PRG: Creating HFS filesystem on $boot..."
1222 if (command -v dd > /dev/null 2>&1) ; then
1223 dd if=/dev/zero of="$boot" bs=512 count=1600 > /dev/null 2>&1
1225 hformat -l bootstrap "$boot" > /dev/null
1226 if [ $? != 0 ] ; then
1227 echo 1>&2 "$PRG: HFS filesystem creation failed!"
1230 humount "$boot" ## otherwise we might get confused.
1234 if (command -v mkdosfs > /dev/null 2>&1) ; then
1235 [ -x `command -v mkdosfs` ] || FAIL=1 ; else FAIL=1 ; fi
1236 if [ "$FAIL" = 1 ] ; then
1237 echo 1>&2 "$PRG: mkdosfs is not installed or cannot be found"
1241 [ "$VERBOSE" = 1 ] && echo "$PRG: Creating DOS filesystem on $boot..."
1242 if (command -v dd > /dev/null 2>&1) ; then
1243 dd if=/dev/zero of="$boot" bs=512 count=1600 > /dev/null 2>&1
1245 mkdosfs -n bootstrap "$boot" > /dev/null
1246 if [ $? != 0 ] ; then
1247 echo 1>&2 "$PRG: DOS filesystem creation failed!"
1257 if [ "$FORCE" = yes ] ; then
1261 [ "$fstype" = raw ] && $PRINTF 1>&2 "$PRG: Overwrite contents of $boot with $install? [y/N] "
1262 [ "$fstype" != raw ] && $PRINTF 1>&2 "$PRG: Create $fstype filesystem on $boot? [y/N] "
1269 echo 1>&2 "$PRG: Abort."
1276 ## for fstype=raw check if an ELF binary has already been dded.
1279 if [ "$(dd if="$boot" bs=1 skip=1 count=3 2>/dev/null)" = ELF ] ; then
1282 echo 1>&2 "$PRG: This partition has never had yaboot installed before, please run mkofboot"
1289 ## defaults for this are defined at the beginning of the script with
1293 "## yaboot configuration file generated by ybin $VERSION
1300 partition=$partition
1303 " > "$TMPCONF" || return 1
1305 [ "$DEBUG" = 1 ] && $PRINTF 1>&2 "\nDEBUG: autoconf:\n----\n" && cat "$TMPCONF" 1>&2 && echo 1>&2 "----"
1309 ## take out the trash.
1312 if [ -n "$TMPCONF" ] ; then rm -f "$TMPCONF" ; fi
1313 if [ -n "$FIRST" ] ; then rm -f "$FIRST" ; fi
1314 if [ -n "$TMPYABOOT" ] ; then rm -f "$TMPYABOOT" ; fi
1315 if [ -d "$TMP/bootstrap.$$" -a "$usemount" = yes ] ; then rmdir "$TMP/bootstrap.$$" ; fi
1323 ## absurdly bloated case statement to parse command line options.
1324 if [ $# != 0 ] ; then
1348 if [ -n "$2" ] ; then
1353 echo 1>&2 "$PRG: option requires an argument $1"
1354 echo 1>&2 "Try \`$PRG --help' for more information."
1359 if [ -n "$2" ] ; then
1364 echo 1>&2 "$PRG: option requires an argument $1"
1365 echo 1>&2 "Try \`$PRG --help' for more information."
1370 if [ -n "$2" ] ; then
1375 echo 1>&2 "$PRG: option requires an argument $1"
1376 echo 1>&2 "Try \`$PRG --help' for more information."
1381 if [ -n "$2" ] ; then
1384 ERR=" Error in $CONF:"
1387 echo 1>&2 "$PRG: option requires an argument $1"
1388 echo 1>&2 "Try \`$PRG --help' for more information."
1393 if [ -n "$2" ] ; then
1398 echo 1>&2 "$PRG: option requires an argument $1"
1399 echo 1>&2 "Try \`$PRG --help' for more information."
1404 if [ -n "$2" ] ; then
1409 echo 1>&2 "$PRG: option requires an argument $1"
1410 echo 1>&2 "Try \`$PRG --help' for more information."
1440 if [ -n "$2" ] ; then
1445 echo 1>&2 "$PRG: option requires an argument $1"
1446 echo 1>&2 "Try \`$PRG --help' for more information."
1451 if [ -n "$2" ] ; then
1456 echo 1>&2 "$PRG: option requires an argument $1"
1457 echo 1>&2 "Try \`$PRG --help' for more information."
1462 if [ -n "$2" ] ; then
1467 echo 1>&2 "$PRG: option requires an argument $1"
1468 echo 1>&2 "Try \`$PRG --help' for more information."
1473 if [ -n "$2" ] ; then
1478 echo 1>&2 "$PRG: option requires an argument $1"
1479 echo 1>&2 "Try \`$PRG --help' for more information."
1484 if [ -n "$2" ] ; then
1489 echo 1>&2 "$PRG: option requires an argument $1"
1490 echo 1>&2 "Try \`$PRG --help' for more information."
1495 if [ -n "$2" ] ; then
1500 echo 1>&2 "$PRG: option requires an argument $1"
1501 echo 1>&2 "Try \`$PRG --help' for more information."
1509 echo 1>&2 "$PRG: unrecognized option \`$1'"
1510 echo 1>&2 "Try \`$PRG --help' for more information."
1517 ## check that specified config file exists, unless its /dev/null in
1518 ## which case we assume all options are done on the command line.
1519 if [ "$CONF" = /dev/null ] ; then
1525 ## if there is no config file use the automatic generation to make a
1526 ## generic yaboot.conf. do this before the confcheck to avoid wierd errors.
1527 if [ "$bootconf" = /dev/null ] ; then
1528 if (command -v yabootconfig > /dev/null 2>&1) ; then
1529 echo 1>&2 "$PRG: Warning: no /etc/yaboot.conf, running yabootconfig to make one"
1530 yabootconfig --noinstall --quiet
1531 if [ $? != 0 ] ; then
1532 echo 1>&2 "$PRG: yabootconfig failed, please supply a valid /etc/yaboot.conf"
1533 echo 1>&2 "$PRG: You may also use $PRG's --boot, --image, --partition, and --device switches"
1534 echo 1>&2 "$PRG: These switches will cause $PRG to generate a basic yaboot.conf on the fly"
1537 CONF=/etc/yaboot.conf
1539 ERR=" Error in $CONF:"
1545 ## Checks if each option was defined on the command line, and if so
1546 ## don't read it from the configuration file. this avoids
1547 ## configuration options from being set null, as well as command line
1548 ## options from being clobbered.
1549 [ "$ARGBT" != 1 -a $(parseconf ck boot) = 0 ] && boot=`parseconf str boot`
1550 [ "$ARGOB" != 1 -a $(parseconf ck ofboot) = 0 ] && ofboot=`parseconf str ofboot`
1551 [ "$ARGBF" != 1 -a $(parseconf ck install) = 0 ] && install=`parseconf str install`
1552 [ "$ARGWP" != 1 -a $(parseconf ck magicboot) = 0 ] && magicboot=`parseconf str magicboot`
1553 [ "$ARGMT" != 1 -a $(parseconf flag usemount) = 0 ] && usemount=yes
1554 [ "$ARGFS" != 1 -a $(parseconf ck fstype) = 0 ] && fstype=`parseconf str fstype`
1555 [ "$ARGBS" != 1 -a $(parseconf flag nobless) = 0 ] && bless=no
1556 [ "$ARGPT" != 1 -a $(parseconf flag protect) = 0 ] && protect=yes
1557 [ "$ARGHD" != 1 -a $(parseconf flag hide) = 0 ] && hide=yes
1558 [ "$ARGNV" != 1 -a $(parseconf flag nonvram) = 0 ] && nonvram=1
1559 [ $(parseconf ck hfstype) = 0 ] && hfstype=`parseconf str hfstype`
1560 [ $(parseconf ck hfscreator) = 0 ] && hfscreator=`parseconf str hfscreator`
1561 [ $(parseconf ck mntpoint) = 0 ] && mntpoint=`parseconf str mntpoint`
1562 [ $(parseconf ck delay) = 0 ] && delay=`parseconf str delay`
1563 [ $(parseconf ck timeout) = 0 ] && timeout=`parseconf str timeout`
1564 [ $(parseconf ck bsd) = 0 ] && bsd=`parseconf str bsd`
1565 [ $(parseconf ck macos) = 0 ] && macos=`parseconf str macos`
1566 [ $(parseconf ck macosx) = 0 ] && macosx=`parseconf str macosx`
1567 [ $(parseconf ck darwin) = 0 ] && darwin=`parseconf str darwin`
1568 [ $(parseconf ck defaultos) = 0 ] && defaultos=`parseconf str defaultos`
1569 [ $(parseconf ck fgcolor) = 0 ] && fgcolor=`parseconf str fgcolor`
1570 [ $(parseconf ck bgcolor) = 0 ] && bgcolor=`parseconf str bgcolor`
1571 [ $(parseconf ck icon) = 0 ] && export YBINOFICON=`parseconf str icon`
1572 [ $(parseconf flag enablecdboot) = 0 ] && cdrom=yes
1573 [ $(parseconf flag enablenetboot) = 0 ] && network=yes
1574 [ $(parseconf flag enableofboot) = 0 ] && of=yes
1575 [ $(parseconf flag brokenosx) = 0 ] && brokenosx=yes
1577 ## ffs!! rtfm! foad!
1578 if [ "$boot" = unconfigured ] ; then
1579 echo 1>&2 "$PRG: You must specify the device for the bootstrap partition. (ie: boot=/dev/hdaX)"
1580 echo 1>&2 "$PRG: Try \`$PRG --help' for more information."
1584 ## if there is still no config file use the automatic generation to make a
1585 ## generic yaboot.conf. do this before the confcheck to avoid wierd errors.
1586 if [ "$bootconf" = /dev/null ] ; then
1587 echo 1>&2 "$PRG: Warning: no yaboot.conf, using generic configuration."
1591 ## mntpoint is incompatible with mkofboot.
1592 if [ "$PRG" = mkofboot -a -n "$mntpoint" ] ; then
1593 echo 1>&2 "$PRG: Cannot be used with \`mntpoint='"
1597 ## validate configuration for sanity.
1600 ## check that we can use ofpath, its only needed for magicboot script
1601 ## building and nvram updates.
1602 if [ -n "$magicboot" -o "$nonvram" = 0 ] ; then
1603 if [ -z "$ofboot" -o -n "$macos" -o -n "$macosx" -o -n "$darwin" ] ; then
1604 if (command -v ofpath > /dev/null 2>&1) ; then
1605 [ -x `command -v ofpath` ]
1606 if [ $? != 0 ] ; then
1607 echo 1>&2 "$PRG: ofpath could not be found, aborting."
1611 echo 1>&2 "$PRG: ofpath could not be found, aborting."
1617 ## if password is set in yaboot.conf make sure permissions on that
1618 ## file are safe, warn if not.
1619 if (grep -q '^[[:space:]]*password[[:space:]]*=' "$bootconf" > /dev/null 2>&1) ; then
1623 ## check if we are root if needed.
1624 if [ "$usemount" = yes -a -z "$mntpoint" ] ; then
1625 if [ `id -u` != 0 ] ; then
1626 echo 1>&2 "$PRG: \`usemount' requires root privileges, go away."
1631 if [ "$fstype" = hfs ] ; then
1633 if [ $? != 0 ] ; then
1634 echo 1>&2 "$PRG: hfsutils is not installed or cannot be found"
1635 echo 1>&2 "$PRG: Try --mount if `uname -sr` supports HFS"
1640 ## convert unix device nodes to OpenFirmware pathnames
1641 if [ -n "$magicboot" -o "$nonvram" = 0 ] ; then
1642 convertpath || exit 1
1645 ## yaboot.conf autogeneration. MUST have secure mktemp to
1646 ## avoid race conditions. Debian's mktemp qualifies.
1647 if [ "$bootconf" = auto ] ; then
1648 TMPCONF=`mktemp -q "$TMP/$PRG.XXXXXX"`
1649 if [ $? != 0 ] ; then
1650 echo 1>&2 "$PRG: Could not create temporary file, aborting."
1655 if [ $? != 0 ] ; then
1656 echo 1>&2 "$PRG: An error occured generating yaboot.conf, aborting."
1663 if [ -n "$magicboot" ] ; then
1664 checkfirststage || exit 1
1665 if [ "$FIRSTSTG" = compat ] ; then
1667 if [ $? != 0 ] ; then
1668 echo 1>&2 "$PRG: An error occured while building first stage loader. aborting..."
1678 if [ "$fstype" = raw ] ; then
1680 raw_install || exit 1
1682 util_install || exit 1
1687 mnt_install || exit 1
1695 ## its not nice to erase the partition and then bail!
1696 if [ "$fstype" = msdos ] ; then
1697 echo 1>&2 "$PRG: mtools support is not implemented"
1698 echo 1>&2 "$PRG: Use --mount or add \`usemount' to $CONF"
1702 if [ "$fstype" = raw ] ; then
1703 raw_install || exit 1
1706 util_install || exit 1
1708 [ "$VERBOSE" = 1 ] && echo "$PRG: Installation complete."
1714 mnt_install || exit 1
1715 [ "$VERBOSE" = 1 ] && echo "$PRG: Installation complete."