3 ###############################################################################
5 ## ybin (YaBoot INstaller) installs/updates the yaboot bootloader.
6 ## Copyright (C) 2000, 2001, 2002, 2003 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"
31 SIGINT="$PRG: Interrupt caught ... exiting"
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"
45 ## catch signals, clean up junk in /tmp.
48 trap "echo 1>&2 $SIGINT ; exit 130" 2
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
57 ERR=" Error in $CONF:"
63 ## define default configuration
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
76 if (cat /proc/cpuinfo 2> /dev/null | grep ^machine | grep -q 'CHRP IBM') ; then
95 ## yaboot autoconf defaults
103 ## this program behaves differently based on how its called, this
104 ## ensures that nothing nasty happens if someone makes a bogus
112 echo 1>&2 "This program must be called as either \`ybin' or \`mkofboot'"
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
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
141 Written by Ethan Benson
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."
152 "Usage: $PRG [OPTION]...
153 Update/install bootloader onto a bootstrap partition.
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 --bootonce override default boot label for ONLY next boot
159 eg: --bootonce linux-2.6.20-testing
160 -i, --install pathname to the actual bootloader binary
161 default: /usr/{local/}lib/yaboot/yaboot same as
162 install= in config file [ -i bootloader_file ]
163 -C, --config use alternate configuration file (ybin and yaboot)
165 -m, --magicboot pathname to a OpenFirmware magicboot (CHRP) script
166 --filesystem set the filesystem type of the bootstrap partition
167 available options are hfs, msdos, and raw
168 [ --filesystem hfs ] default is hfs
169 --nobless don't bless the root directory, this should only
170 be used if you are using a MacOS boot partition
171 as the bootstrap partition (not recommended)
172 -M, --mount don't use userspace hfsutils to modify the
173 bootstrap instead try and mount the filesystem
174 directly. Note that attributes cannot be set
175 this way and you will have to manually modify
176 OpenFirmware to make your system bootable
177 --protect set the read-only (locked) bit on all bootstrap
179 --hide set the invisible bit on all bootstrap files
180 this is useful of you don't want them to be
182 --nonvram do not update the boot-device variable in nvram.
183 --force don't ever ask for confirmation
184 -v, --verbose make $PRG more verbose
185 --debug print boring junk only useful for debugging
186 -h, --help display this help and exit
187 -V, --version output version information and exit"
190 ## configuration file parsing. FIXME: need a method which can parse
196 v=`grep "^$2[\ ,=]" "$CONF"` ; echo "${v#*=}"
199 grep "^$2\>" "$CONF" > /dev/null && echo 0 || echo 1
202 grep "^$2[\ ,=]" "$CONF" > /dev/null && echo 0 || echo 1
207 ## check for existence of a configuration file, and make sure we have
211 if [ ! -e "$CONF" ] ; then
212 echo 1>&2 "$PRG: $CONF: No such file or directory"
214 elif [ ! -f "$CONF" ] ; then
215 echo 1>&2 "$PRG: $CONF: Not a regular file"
217 elif [ ! -r "$CONF" ] ; then
218 echo 1>&2 "$PRG: $CONF: Permission denied"
225 ## check to make sure the configuration file is sane and correct.
226 ## maybe this is an insane ammount of error checking, but I want to
227 ## make sure (hopfully) nothing unexpected ever happens. and i just
228 ## like useful errors from programs. every error just marks an error
229 ## variable so we give the user as much info as possible before we
233 if [ ! -e "$boot" ] ; then
234 echo 1>&2 "$PRG: $boot: No such file or directory"
236 elif [ ! -b "$boot" -a ! -f "$boot" ] ; then
237 echo 1>&2 "$PRG: $boot: Not a regular file or block device"
239 elif [ ! -w "$boot" -o ! -r "$boot" ] ; then
240 [ -z "$mntpoint" ] && echo 1>&2 "$PRG: $boot: Permission denied"
241 [ -z "$mntpoint" ] && CONFERR=1
244 if [ ! -e "$install" ] ; then
245 echo 1>&2 "$PRG: $install: No such file or directory"
247 elif [ ! -f "$install" ] ; then
248 echo 1>&2 "$PRG: $bootconf: Not a regular file"
250 elif [ ! -r "$install" ] ; then
251 echo 1>&2 "$PRG: $install: Permission denied"
255 if [ "$bootconf" = auto ] ; then
257 elif [ ! -e "$bootconf" ] ; then
258 echo 1>&2 "$PRG: $bootconf: No such file or directory"
260 elif [ ! -f "$bootconf" ] ; then
261 echo 1>&2 "$PRG: $bootconf: Not a regular file"
263 elif [ ! -r "$bootconf" ] ; then
264 echo 1>&2 "$PRG: $bootconf: Permission denied"
268 if [ -n "$magicboot" ] ; then
269 if [ ! -e "$magicboot" ] ; then
270 echo 1>&2 "$PRG: $magicboot: No such file or directory"
272 elif [ ! -f "$magicboot" ] ; then
273 echo 1>&2 "$PRG: $magicboot: Not a regular file"
275 elif [ ! -r "$magicboot" ] ; then
276 echo 1>&2 "$PRG: $magicboot: Permission denied"
285 if [ "$ARGFS" = 1 ] ; then
286 echo 1>&2 "$PRG: --filesystem must be either \`hfs', \`msdos', or \`raw'"
288 echo 1>&2 "$PRG:$ERR \`fstype' must be either \`hfs', \`msdos', or \`raw'"
294 ## if we are not using HFS filesystems we don't care about HFS
296 if [ "$fstype" = hfs ] ; then
297 if [ `echo ${#hfstype}` != 4 ] ; then
298 if [ "$ARGTP" = 1 ] ; then
299 echo 1>&2 "$PRG: --type must be 4 characters"
301 echo 1>&2 "$PRG:$ERR \`hfstype' must be 4 characters"
306 if [ `echo ${#hfscreator}` != 4 ] ; then
307 if [ "$ARGCT" = 1 ] ; then
308 echo 1>&2 "$PRG: --creator must be 4 characters"
310 echo 1>&2 "$PRG:$ERR \`hfscreator' must be 4 characters"
316 ## some options are not compatible with fstype=raw
317 if [ "$fstype" = raw ] ; then
318 if [ -n "$mntpoint" ] ; then
319 echo 1>&2 "$PRG:$ERR \`mntpoint' is not compatible with fstype=raw"
322 if [ "$usemount" = yes ] ; then
323 echo 1>&2 "$PRG:$ERR \`usemount' is not compatible with fstype=raw"
326 if [ -n "$magicboot" ] ; then
327 echo 1>&2 "$PRG:$ERR \`magicboot' scripts cannot be used with fstype=raw"
332 if [ -n "$mntpoint" ] ; then
334 if [ ! -e "$mntpoint" ] ; then
335 echo 1>&2 "$PRG: $mntpoint: No such file or directory"
337 elif [ ! -d "$mntpoint" ] ; then
338 echo 1>&2 "$PRG: $mntpoint: Not a directory"
340 elif [ ! -w "$mntpoint" -o ! -r "$mntpoint" ] ; then
341 echo 1>&2 "$PRG: $mntpoint: Permission denied"
343 elif [ ! -O "$mntpoint" -a `id -u` != 0 ] ; then
344 echo 1>&2 "$PRG: $mntpoint: Permission denied (not owner)"
348 ## make sure no embedded spaces exist
349 echo "$mntpoint" | grep -q [[:space:]]
351 echo 1>&2 "$PRG:$ERR \`mntpoint=$mntpoint' contains embedded spaces, don't use lame filenames"
355 ## make sure $mntpoint is on $boot, this matters to nvram updating.
356 if [ "$(v=`df "$mntpoint" 2> /dev/null | grep ^/dev/` ; echo ${v%%[ ]*})" != "$boot" -a -d "$mntpoint" ] ; then
357 echo 1>&2 "$PRG: $mntpoint is not located on $boot"
359 ## more then one subdirectory deep is not supported. no sed available on boot floppies ( / -> \ )
360 elif [ "$mntpoint" != "$(v=`df "$mntpoint" 2> /dev/null | grep ^/dev/` ; echo ${v##*[ ]})" ] ; then
361 echo "$(v=`df "$mntpoint" 2>/dev/null | grep ^/dev/`; m=${v##*[ ]}; echo "${mntpoint##*$m/}")" | grep -q /
363 echo 1>&2 "$PRG:$ERR $mntpoint is more then one subdirectory deep from root of $boot"
366 OFDIR="$(v=`df "$mntpoint" 2>/dev/null | grep ^/dev/`; m=${v##*[ ]}; echo "${mntpoint##*$m/}")"
370 if [ "$usemount" = no ] ; then
371 echo 1>&2 "$PRG:$ERR \`mntpoint=' requires \`usemount' be set"
376 if [ -n "$magicboot" ] ; then
377 ## check for bsd loader
378 if [ -n "$bsd" ] ; then
379 if [ -f /usr/lib/yaboot/ofwboot -a -r /usr/lib/yaboot/ofwboot ] ; then
380 BSDLOADER="/usr/lib/yaboot/ofwboot"
381 elif [ -f /usr/local/lib/yaboot/ofwboot -a -r /usr/local/lib/yaboot/ofwboot ] ; then
382 BSDLOADER="/usr/local/lib/yaboot/ofwboot"
384 echo 1>&2 "$PRG: /usr/local/lib/yaboot/ofwboot: No such file or directory"
385 echo 1>&2 "$PRG: With the bsd= option set you must have the bsd boot loader ofwboot"
390 ## convert defaultos variable
392 linux|Linux|GNU|Gnu|gnu)
399 if [ -z "$bsd" ] ; then
400 echo 1>&2 "$PRG:$ERR no entry for \`bsd' found, but defaultos is set to \`bsd'"
406 if [ -z "$macos" ] ; then
407 echo 1>&2 "$PRG:$ERR no entry for \`macos' found, but defaultos is set to \`macos'"
413 if [ -z "$macosx" ] ; then
414 echo 1>&2 "$PRG:$ERR no entry for \`macosx' found, but defaultos is set to \`macosx'"
420 if [ -z "$darwin" ] ; then
421 echo 1>&2 "$PRG:$ERR no entry for \`darwin' found, but defaultos is set to \`darwin'"
426 echo 1>&2 "$PRG:$ERR \`defaultos' must be either \`linux', \`bsd', \`macos' or \`macosx'"
432 ## nvsetenv requires /proc
433 if [ ! -f /proc/uptime -a "$nonvram" = 0 ] ; then
434 echo 1>&2 "$PRG: /proc filesystem is not mounted, nvram will not be updated"
438 if [ "$nonvram" = 0 ] ; then
439 ## see if nvsetenv exists and is executable
440 if (command -v nvsetenv > /dev/null 2>&1) ; then
441 [ -x `command -v nvsetenv` ] || MISSING=1 ; else MISSING=1
444 if [ "$nonvram" = 0 ] ; then
445 ## if nvsetenv exists see if its the old broken version
446 if [ "$MISSING" != 1 ] ; then
447 nvsetenv --version > /dev/null 2>&1 || OLD=1
450 echo 1>&2 "$PRG: Warning: \`nvsetenv' could not be found, nvram will not be updated"
453 if [ "$OLD" = 1 ] ; then
454 ## i check this myself to avoid misleading error
455 ## messages. nvsetenv should REALLY support --version.
456 if [ ! -e /dev/nvram ] ; then
457 echo 1>&2 "$PRG: /dev/nvram: No such file or directory"
458 echo 1>&2 "$PRG: Warning: nvram will not be updated"
460 elif [ ! -c /dev/nvram ] ; then
461 echo 1>&2 "$PRG: /dev/nvram: Not a character device"
462 echo 1>&2 "$PRG: Warning: nvram will not be updated"
464 elif [ ! -w /dev/nvram -o ! -r /dev/nvram ] ; then
465 echo 1>&2 "$PRG: /dev/nvram: Permission denied"
466 echo 1>&2 "$PRG: Warning: nvram will not be updated"
468 elif ! (dd if=/dev/nvram of=/dev/null bs=1 count=10 > /dev/null 2>&1) ; then
469 echo 1>&2 "$PRG: /dev/nvram: No such device"
470 echo 1>&2 "$PRG: Warning: nvram will not be updated"
474 echo 1>&2 "$PRG: Warning: Incompatible version of \`nvsetenv', nvram will not be updated"
479 if [ -f "$boot" ] ; then
480 echo 1>&2 "$PRG: $boot is a regular file, disabling nvram updating"
485 ## check for newworld mac. use cat hack due to /proc wierdness.
486 ## do not bail if we are on an OldWorld only warn (very loudly).
487 if [ "$(v=`cat /proc/cpuinfo 2>/dev/null | grep pmac-generation` ; echo ${v##*:})" = NewWorld ] ; then
489 elif [ "$(v=`cat /proc/cpuinfo 2>/dev/null | grep pmac-generation` ; echo ${v##*:})" = OldWorld ] ; then
491 echo 1>&2 '@@@@@@@@@@@@@@ WARNING!! WARNING!! WARNING!! @@@@@@@@@@@@@@'
492 echo 1>&2 "$PRG: Warning: This is an OldWorld PowerMac, $boot will **NOT** be bootable on this machine"
493 echo 1>&2 "$PRG: Oldworld PowerMacs need to use the quik bootloader, not yaboot"
494 echo 1>&2 '@@@@@@@@@@@@@@ WARNING!! WARNING!! WARNING!! @@@@@@@@@@@@@@'
496 [ "$nonvram" = 0 ] && echo 1>&2 "$PRG: OldWorld PowerMac, nvram will not be updated"
498 elif (cat /proc/cpuinfo 2>/dev/null | grep ^motherboard | grep -q AAPL) ; then
500 echo 1>&2 '@@@@@@@@@@@@@@ WARNING!! WARNING!! WARNING!! @@@@@@@@@@@@@@'
501 echo 1>&2 "$PRG: Warning: This is an OldWorld PowerMac, $boot will **NOT** be bootable on this machine"
502 echo 1>&2 "$PRG: Oldworld PowerMacs need to use the quik bootloader, not yaboot"
503 echo 1>&2 '@@@@@@@@@@@@@@ WARNING!! WARNING!! WARNING!! @@@@@@@@@@@@@@'
505 [ "$nonvram" = 0 ] && echo 1>&2 "$PRG: OldWorld PowerMac, nvram will not be updated"
507 elif (cat /proc/cpuinfo 2> /dev/null | grep ^machine | grep -q 'CHRP IBM') ; then
508 ## IBM hardware does not need nvram update AFAICT
512 #echo 1>&2 "$PRG: Warning: Unknown archetecture, $boot may not be bootable on this machine"
513 [ "$nonvram" = 0 ] && echo 1>&2 "$PRG: Warning: Unknown architecture, nvram will not be updated"
517 ## convert human readable color values from config to proper color
520 black) fgc=0 ;; blue) fgc=1 ;; green) fgc=2 ;; cyan) fgc=3 ;;
521 red) fgc=4 ;; purple) fgc=5 ;; brown) fgc=6 ;; light-gray) fgc=7 ;;
522 dark-gray) fgc=8 ;; light-blue) fgc=9 ;; light-green) fgc=a ;;
523 light-cyan) fgc=b ;; light-red) fgc=c ;; light-purple) fgc=d ;;
524 yellow) fgc=e ;; white) fgc=f ;;
526 echo 1>&2 "$PRG:$ERR Invalid fgcolor: \`$fgcolor'"
531 black) bgc=0 ;; blue) bgc=1 ;; green) bgc=2 ;; cyan) bgc=3 ;;
532 red) bgc=4 ;; purple) bgc=5 ;; brown) bgc=6 ;; light-gray) bgc=7 ;;
533 dark-gray) bgc=8 ;; light-blue) bgc=9 ;; light-green) bgc=a ;;
534 light-cyan) bgc=b ;; light-red) bgc=c ;; light-purple) bgc=d ;;
535 yellow) bgc=e ;; white) bgc=f ;;
537 echo 1>&2 "$PRG:$ERR Invalid bgcolor: \`$bgcolor'"
542 ## if delay is not set use yaboot's timeout
543 if [ -z "$delay" ] ; then
544 delay="$(($timeout / 10))"
547 if [ "$CONFERR" = 1 ] ; then
555 ## if readlink is missing use a kludge
556 if (command -v readlink > /dev/null 2>&1) ; then
561 local SYMTARGET="$(v=`ls -l "$2" 2>/dev/null` ; echo ${v##*> })"
562 if [ -n "$SYMTARGET" ] ; then
571 ## /etc/yaboot.conf with password should not be world readable.
574 if [ -L "$bootconf" ] ; then
575 local realfile="$(readlink -f "$bootconf")" || return 0
577 local realfile="$bootconf"
580 ## don't bother if we could not read the symlink
581 [ -z "$realfile" ] && return 0
582 [ ! -f "$realfile" ] && return 0
584 ## get permissions, and don't bother checking if we can't
585 local PERM=`v=$(ls -l "$realfile" 2>/dev/null) ; echo ${v%% *}`
586 [ -z "$PERM" ] && return 0
587 [ `echo ${#PERM}` != 10 ] && return 0
590 -rw-------|-r--------)
591 if [ ! -O "$realfile" -a `id -u` = 0 ] ; then
592 echo 1>&2 "$PRG: Warning: $bootconf is not owned by root"
595 -rw-r-----|-r--r-----)
596 if [ ! -O "$realfile" -a `id -u` = 0 ] ; then
597 echo 1>&2 "$PRG: Warning: $bootconf is not owned by root"
599 if [ ! -G "$realfile" -a `id -g` = 0 ] ; then
600 echo 1>&2 "$PRG: Warning: $bootconf is not owned by group root"
603 -r--r--r--|-rw-r--r--|-rw-rw-r--|-rw-rw-rw-|-rw-rw----)
604 echo 1>&2 "$PRG: Warning: Insecure permissions on $bootconf: $PERM should be -rw-------"
607 echo 1>&2 "$PRG: Warning: Incorrect permissions on $bootconf: $PERM should be -rw-------"
614 ## figure out bootstrap device OF pathname if user did not supply it.
615 if [ -z "$ofboot" ] ; then
616 [ "$VERBOSE" = 1 ] && echo "$PRG: Finding OpenFirmware device path to \`$boot'..."
617 ofboot="$($OFPATH $boot)"
618 if [ $? != 0 ] ; then
619 echo 1>&2 "$PRG: Unable to find OpenFirmware path for boot=$boot"
620 echo 1>&2 "$PRG: Please add ofboot=<path> where <path> is the OpenFirmware path to $boot to $CONF"
623 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: ofboot set to \`$ofboot'"
626 ## figure out OF device path for macos/macosx if user supplied a unix device node.
627 if [ -n "$bsd" ] ; then
630 [ "$VERBOSE" = 1 ] && echo "$PRG: Finding OpenFirmware device path to \`$bsd'..."
632 bsd="$($OFPATH $bsd)"
633 if [ $? != 0 ] ; then
634 echo 1>&2 "$PRG: Unable to determine OpenFirmware path for bsd=$sbsd"
635 echo 1>&2 "$PRG: Try specifying the real OpenFirmware path for bsd=$sbsd in $CONF"
638 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: bsd set to \`$bsd' from \`$sbsd'"
641 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: bsd left alone: \`$bsd'"
646 if [ -n "$macos" ] ; then
649 [ "$VERBOSE" = 1 ] && echo "$PRG: Finding OpenFirmware device path to \`$macos'..."
650 local smacos="$macos"
651 macos="$($OFPATH $macos)"
652 if [ $? != 0 ] ; then
653 echo 1>&2 "$PRG: Unable to determine OpenFirmware path for macos=$smacos"
654 echo 1>&2 "$PRG: Try specifying the real OpenFirmware path for macos=$smacos in $CONF"
657 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: macos set to \`$macos' from \`$smacos'"
660 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: macos left alone: \`$macos'"
665 if [ -n "$macosx" ] ; then
668 [ "$VERBOSE" = 1 ] && echo "$PRG: Finding OpenFirmware device path to \`$macosx'..."
669 local smacosx="$macosx"
670 macosx="$($OFPATH $macosx)"
671 if [ $? != 0 ] ; then
672 echo 1>&2 "$PRG: Unable to determine OpenFirmware path for macosx=$smacosx"
673 echo 1>&2 "$PRG: Try specifying the real OpenFirmware path for macosx=$smacosx in $CONF"
676 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: macosx set to \`$macosx' from \`$smacosx'"
679 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: macosx left alone: \`$macosx'"
684 if [ -n "$darwin" ] ; then
687 [ "$VERBOSE" = 1 ] && echo "$PRG: Finding OpenFirmware device path to \`$darwin'..."
688 local sdarwin="$darwin"
689 darwin="$($OFPATH $darwin)"
690 if [ $? != 0 ] ; then
691 echo 1>&2 "$PRG: Unable to determine OpenFirmware path for darwin=$sdarwin"
692 echo 1>&2 "$PRG: Try specifying the real OpenFirmware path for darwin=$sdarwin in $CONF"
695 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: darwin set to \`$darwin' from \`$sdarwin'"
698 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: darwin left alone: \`$darwin'"
703 if [ "$CONVERR" = 1 ] ; then
710 ## make sure the hfsutils we need are installed and executable.
713 if (command -v hmount > /dev/null 2>&1) ; then
714 [ -x `command -v hmount` ] || FAIL=1 ; else FAIL=1 ; fi
715 if (command -v humount > /dev/null 2>&1) ; then
716 [ -x `command -v humount` ] || FAIL=1 ; else FAIL=1 ; fi
717 if (command -v hcopy > /dev/null 2>&1) ; then
718 [ -x `command -v hcopy` ] || FAIL=1 ; else FAIL=1 ; fi
719 if (command -v hattrib > /dev/null 2>&1) ; then
720 [ -x `command -v hattrib` ] || FAIL=1 ; else FAIL=1 ; fi
721 if (command -v hformat > /dev/null 2>&1) ; then
722 [ -x `command -v hformat` ] || FAIL=1 ; else FAIL=1 ; fi
724 if [ "$FAIL" = 1 ] ; then
731 ## This is gross, IBM CHRP OF needs a .note added to the yaboot
732 ## binary, nobody knows whether this note will affect PowerMac OF or
733 ## not (or could in the future).
736 local YBDIR="${install%/*}"
737 if [ -x "$YBDIR/addnote" ] ; then
738 TMPYABOOT=`mktemp -q "$TMP/yaboot.XXXXXX"`
739 if [ $? != 0 ] ; then
740 echo 1>&2 "$PRG: Could not create temporary file, aborting."
743 if (cat "$install" > "$TMPYABOOT" 2> /dev/null) ; then
746 echo 1>&2 "$PRG: Could not create temporary file, aborting."
750 [ "$DEBUG" = 1 ] && echo "$PRG: Embedding CHRP note section in temp yaboot..."
751 "$YBDIR/addnote" "$install" > /dev/null 2>&1
752 if [ $? != 0 ] ; then
753 echo 1>&2 "$PRG: Could not install note section required by your architecture"
757 echo 1>&2 "$PRG: Your architecture requires $YBDIR/addnote which cannot be found"
763 ## install using userspace utilities rather then kernel filesytem
764 ## support. hfsutils only, mtools not supported.
767 ## catch signals, and humount, cleanup done by trap 0.
768 trap "humount $boot ; exit 129" 1
769 trap "echo 1>&2 $SIGINT ; humount $boot ; exit 130" 2
770 trap "humount $boot ; exit 131" 3
771 trap "humount $boot ; exit 143" 15
773 ## filenames on bootstrap partition. ofboot hard codes yaboot.
775 local CFFILE=yaboot.conf
777 ## if there is a magicboot script to install we will give it the
778 ## hfstype (should be "tbxi") and give yaboot type "boot".
779 if [ -n "$magicboot" ] ; then
782 local BTTYPE="$hfstype"
785 if [ -n "$magicboot" ] ; then
786 local WRAP="${magicboot##*/}"
789 ## set verbose messages here so they don't show temporary file paths
790 local INSTALLFIRST="$PRG: Installing first stage bootstrap $magicboot onto $boot..."
791 local INSTALLPRIMARY="$PRG: Installing primary bootstrap $install onto $boot..."
793 ## repoint magicboot as the real first stage loader if using the
794 ## modern automatic generating ofboot.b.
795 if [ -n "$FIRST" ] ; then
797 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: set magicboot to $FIRST"
800 ## gross hack, add note section for IBM CHRP
801 if [ "$ADDNOTE" = yes ] ; then
802 hack_yaboot || return 1
805 if [ "$fstype" = hfs ] ; then
806 if [ "$protect" = yes ] ; then
810 if [ "$hide" = yes ] ; then
814 ## make sure the device is not mounted as a filesystem before
815 ## we start mucking with it directly.
816 mount | grep "^$boot\>" > /dev/null
818 echo 1>&2 "$PRG: $boot appears to be mounted! aborting."
822 ## hmount is really more of a way to make sure we have a valid HFS
823 ## filesystem before proceding, and hcopy requires it...
824 hmount "$boot" > /dev/null
825 if [ $? != 0 ] ; then
826 echo 1>&2 "$PRG: $boot appears to have never had a bootstrap installed, please run mkofboot"
830 ## must be explicit with target filename to avoid hfsutils
831 ## braindamage ("_" -> " " filename mangling) also avoid
832 ## ambiguity in the bootstrap partition.
833 if [ -n "$magicboot" ] ; then
834 [ "$VERBOSE" = 1 ] && echo "$INSTALLFIRST"
835 hcopy -r "$magicboot" :ofboot.b
836 if [ $? != 0 ] ; then
837 echo 1>&2 "$PRG: An error occured while writing to $boot"
842 [ "$VERBOSE" = 1 ] && echo "$INSTALLPRIMARY"
843 hcopy -r "$install" :"$BTFILE"
844 if [ $? != 0 ] ; then
845 echo 1>&2 "$PRG: An error occured while writing to $boot"
849 [ "$VERBOSE" = 1 ] && echo "$PRG: Installing $bootconf onto $boot..."
850 hcopy -r "$bootconf" :"$CFFILE"
851 if [ $? != 0 ] ; then
852 echo 1>&2 "$PRG: An error occured while writing to $boot"
856 if [ -n "$BSDLOADER" ] ; then
857 [ "$VERBOSE" = 1 ] && echo "$PRG: Installing $BSDLOADER onto $boot..."
858 hcopy -r "$BSDLOADER" :ofwboot
859 if [ $? != 0 ] ; then
860 echo 1>&2 "$PRG: An error occured while writing to $boot"
865 ## set all file's attributes, if a magicboot script exists it
866 ## gets the configured hfstype instead of yaboot (should be
867 ## "tbxi") so it gets booted by OF.
868 if [ -n "$magicboot" ] ; then
869 [ "$VERBOSE" = 1 ] && echo "$PRG: Setting attributes on $WRAP..."
870 hattrib -t "$hfstype" -c "$hfscreator" $INVISIBLE $LOCK :ofboot.b
871 if [ $? != 0 ] ; then
872 echo 1>&2 "$PRG: Warning: error setting attributes on $WRAP"
873 echo 1>&2 "$PRG: This is probably bad but we'll ignore it."
877 [ "$VERBOSE" = 1 ] && echo "$PRG: Setting attributes on $BTFILE..."
878 hattrib -t "$BTTYPE" -c "$hfscreator" $INVISIBLE $LOCK :"$BTFILE"
879 if [ $? != 0 ] ; then
880 echo 1>&2 "$PRG: Warning: error setting attributes on $BTFILE"
881 echo 1>&2 "$PRG: This is probably bad but we'll ignore it"
884 [ "$VERBOSE" = 1 ] && echo "$PRG: Setting attributes on $CFFILE..."
885 hattrib -t "conf" -c "$hfscreator" $INVISIBLE $LOCK :"$CFFILE"
886 if [ $? != 0 ] ; then
887 echo 1>&2 "$PRG: Warning: error setting attributes on $CFFILE"
888 echo 1>&2 "$PRG: This is probably unimportant so we'll ignore it"
891 if [ -n "$BSDLOADER" ] ; then
892 [ "$VERBOSE" = 1 ] && echo "$PRG: Setting attributes on ofwboot..."
893 hattrib -t "bsdb" -c "$hfscreator" $INVISIBLE $LOCK :ofwboot
894 if [ $? != 0 ] ; then
895 echo 1>&2 "$PRG: Warning: error setting attributes on ofwboot"
896 echo 1>&2 "$PRG: This is probably unimportant so we'll ignore it"
900 ## bless the root directory so OF will find the boot file
901 if [ "$bless" = yes ] ; then
902 [ "$VERBOSE" = 1 ] && echo "$PRG: Blessing $boot with Holy Penguin Pee..."
904 if [ $? != 0 ] ; then
905 echo 1>&2 "$PRG: Warning: error blessing $boot"
906 echo 1>&2 "$PRG: This is probably bad but we'll ignore it"
910 ## clean up the ~/.hcwd file hmount creates
911 humount "$boot" > /dev/null
914 ## use explicit filename if we don't bless.
915 if [ "$bless" = yes ] ; then
916 local OFFILE='\\:tbxi'
918 if [ -n "$magicboot" ] ; then
919 local OFFILE=ofboot.b
921 local OFFILE="$BTFILE"
925 ## update the boot-device variable in OF nvram.
926 if [ "$nonvram" = 0 ] ; then
927 [ "$VERBOSE" = 1 ] && echo "$PRG: Updating OpenFirmware boot-device variable in nvram..."
928 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: boot-device=${ofboot},${OFFILE}"
929 nvsetenv boot-device "${ofboot},${OFFILE}"
930 if [ $? != 0 ] ; then
931 echo 1>&2 "$PRG: An error occured while updating nvram, we'll ignore it"
936 echo 1>&2 "$PRG: mtools support is not implemented"
937 echo 1>&2 "$PRG: Use --mount or add \`usemount' to $CONF"
944 ## used by mnt_install so mntpoint= can be supported in a cleaner way.
947 ## we can even create bootstrap filesystem images directly if you
949 if [ -f "$boot" ] ; then
953 if [ -e "$TMP/bootstrap.$$" ] ; then
954 echo 1>&2 "$PRG: $TMP/bootstrap.$$ exists, aborting."
958 mkdir -m 700 "$TMP/bootstrap.$$"
959 if [ $? != 0 ] ; then
960 echo 1>&2 "$PRG: Could not create mountpoint directory, aborting."
964 mount | grep "^$boot\>" > /dev/null
966 echo 1>&2 "$PRG: $boot appears to be mounted! aborting."
970 [ "$VERBOSE" = 1 ] && echo "$PRG: Mounting $boot..."
971 mount -t "$fstype" -o rw,umask=077$loop "$boot" "$TMP/bootstrap.$$"
972 if [ $? != 0 ] ; then
973 echo 1>&2 "$PRG: An error occured mounting $boot"
977 ## catch signals, set here to avoid umounting something we did not
978 ## mount. cleanup done by trap 0.
979 trap "umount $boot ; exit 129" 1
980 trap "echo 1>&2 $SIGINT ; umount $boot ; exit 130" 2
981 trap "umount $boot ; exit 131" 3
982 trap "umount $boot ; exit 143" 15
984 TARGET="$TMP/bootstrap.$$"
988 ## umnt funtion which checks whether we mounted anything or not, for
989 ## mntpoint= this makes the code below cleaner IMO.
992 if [ -z "$mntpoint" ] ; then
993 [ "$1" = failure ] && echo 1>&2 "$PRG: Attempting to umount $boot..."
995 if [ $? != 0 ] ; then
996 echo 1>&2 "$PRG: umount of $boot failed!"
999 [ "$1" = failure ] && echo 1>&2 "$PRG: umount successfull"
1007 ## Use kernel filesytem drivers to mount the bootstrap partition like
1008 ## any other filesystem and copy the files there with standard un*x
1014 ## msdosfs is broken, yaboot may not support this filename.
1015 if [ "$fstype" = msdos ] ; then
1016 local CFFILE=yaboot.cnf
1018 local CFFILE=yaboot.conf
1021 if [ -n "$magicboot" ] ; then
1022 local WRAP="${magicboot##*/}"
1025 ## set verbose messages here so they don't show temporary file paths
1026 local INSTALLFIRST="$PRG: Installing first stage bootstrap $magicboot onto $boot..."
1027 local INSTALLPRIMARY="$PRG: Installing primary bootstrap $install onto $boot..."
1029 ## repoint magicboot as the real first stage loader if using the
1030 ## modern automatic generating ofboot.b.
1031 if [ -n "$FIRST" ] ; then
1033 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: set magicboot to $FIRST"
1036 ## gross hack, add note section for IBM CHRP
1037 if [ "$ADDNOTE" = yes ] ; then
1038 hack_yaboot || return 1
1041 ## call mnt() function to take care of mounting filesystem if needed
1042 if [ -z "$mntpoint" ] ; then
1048 ## this is probably insecure on modern filesystems, but i think
1049 ## safe on crippled hfs/dosfs. user should ensure mntpoint= is safe.
1050 if [ -n "$magicboot" ] ; then
1051 [ "$VERBOSE" = 1 ] && echo "$INSTALLFIRST"
1052 cp -f "$magicboot" "$TARGET/ofboot.b"
1053 if [ $? != 0 ] ; then
1054 echo 1>&2 "$PRG: An error occured while writing to $boot"
1055 umnt failure "$TARGET"
1060 [ "$VERBOSE" = 1 ] && echo "$INSTALLPRIMARY"
1061 cp -f "$install" "$TARGET/$BTFILE"
1062 if [ $? != 0 ] ; then
1063 echo 1>&2 "$PRG: An error occured while writing to $boot"
1064 umnt failure "$TARGET"
1068 [ "$VERBOSE" = 1 ] && echo "$PRG: Installing $bootconf onto $boot..."
1069 cp -f "$bootconf" "$TARGET/$CFFILE"
1070 if [ $? != 0 ] ; then
1071 echo 1>&2 "$PRG: An error occured while writing to $boot"
1072 umnt failure "$TARGET"
1076 if [ -n "$BSDLOADER" ] ; then
1077 [ "$VERBOSE" = 1 ] && echo "$PRG: Installing $BSDLOADER onto $boot..."
1078 cp -f "$BSDLOADER" "$TARGET/ofwboot"
1079 if [ $? != 0 ] ; then
1080 echo 1>&2 "$PRG: An error occured while writing to $boot"
1081 umnt failure "$TARGET"
1086 if [ "$protect" = yes ] ; then
1087 [ "$VERBOSE" = 1 ] && echo "$PRG: Setting read-only attributes..."
1088 chmod a-w "$TARGET/$BTFILE"
1089 chmod a-w "$TARGET/$CFFILE"
1090 if [ -n "$magicboot" ] ; then
1091 chmod a-w "$TARGET/ofboot.b"
1093 if [ -n "$BSDLOADER" ] ; then
1094 chmod a-w "$TARGET/ofwboot"
1099 umnt success "$TARGET" || return 1
1101 ## make variable with a \ to avoid shell fsckage. ugly ugly ugly.
1103 if [ -n "$magicboot" ] ; then
1104 [ -n "$OFDIR" ] && OFDIR="${BS}${OFDIR}${BS}"
1105 local OFFILE="${OFDIR}ofboot.b"
1107 [ -n "$OFDIR" ] && OFDIR="${BS}${OFDIR}${BS}"
1108 local OFFILE="${OFDIR}${BTFILE}"
1111 ## update the boot-device variable in OF nvram.
1112 if [ "$nonvram" = 0 ] ; then
1113 [ "$VERBOSE" = 1 ] && echo "$PRG: Updating OpenFirmware boot-device variable in nvram..."
1114 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: boot-device=${ofboot},${OFFILE}"
1115 nvsetenv boot-device "${ofboot},${OFFILE}"
1116 if [ $? != 0 ] ; then
1117 echo 1>&2 "$PRG: An error occured while updating nvram, we'll ignore it"
1120 echo 1>&2 "$PRG: Warning: You must manually configure OpenFirmware to boot."
1126 ## raw installation, for IBM RS/6000 hardware, yaboot is dded to the
1127 ## bootstrap partition.
1130 ## make sure the device is not mounted as a filesystem before
1131 ## we start mucking with it directly.
1132 mount | grep "^$boot\>" > /dev/null
1133 if [ $? = 0 ] ; then
1134 echo 1>&2 "$PRG: $boot appears to be mounted! aborting."
1138 ## set verbosity message before munging the yaboot pathname
1139 local INSTALLPRIMARY="$PRG: Installing primary bootstrap $install onto $boot..."
1141 ## gross hack, add note section for IBM CHRP
1142 if [ "$ADDNOTE" = yes ] ; then
1143 hack_yaboot || return 1
1146 [ "$VERBOSE" = 1 ] && echo "$INSTALLPRIMARY"
1147 dd if=/dev/zero of="$boot" bs=512 count=1600 > /dev/null 2>&1
1148 dd if="$install" of="$boot" bs=512 > /dev/null 2>&1
1149 if [ $? != 0 ] ; then
1150 echo 1>&2 "$PRG: Installation failed."
1154 [ "$VERBOSE" = 1 ] && echo "$PRG: Installation successful"
1158 ## make sure the first stage ofboot generator is compatible.
1161 grep -q "^#%ybinscript-" "$magicboot" 2> /dev/null
1162 if [ "$?" = 0 ] ; then
1163 local magic=`grep "^#%ybinscript-" "$magicboot"`
1164 local ver="${magic##*-}"
1165 if [ "$ver" = "1.1" ] ; then
1169 echo 1>&2 "$PRG: Incompatible version of first stage loader $magicboot. aborting..."
1178 ## build the first stage loader.
1181 ## must have 7 backslashes to == \\ printf + shell = bizarre... or,
1182 ## make special variable to contain a \ (need \\ to make \) to work
1183 ## around echo -e -n brokeness.
1187 ## deal with mntpoint=
1188 [ -n "$OFDIR" ] && local OFDIR="${BS}${OFDIR}${BS}"
1190 ## some misguided people insist on installing OSX on
1191 ## HorribleFileSystem+ instead of UFS, as a result MacOS deblesses
1192 ## OSX, making it unbootable. if apple localizes the filesystem hierarchy again screw it.
1193 [ "$brokenosx" = yes ] && local OSXBOOT="${BS}System${BS}Library${BS}CoreServices${BS}BootX"
1194 [ "$brokenosx" = no ] && local OSXBOOT="${BS}${BS}:tbxi"
1196 ## assign variables for configured menu options.
1197 [ "$usemount" = no -a "$bless" = yes ] && local YB="yaboot GNU l $ofboot ,${BS}${BS}yaboot"
1198 [ "$usemount" = yes -o "$bless" = no ] && local YB="yaboot GNU l $ofboot ,${OFDIR}yaboot"
1199 [ -n "$bsd" ] && OS="$(($OS + 1))" && local BSD="ybsd BSD b $ofboot ,${BS}${BS}ofwboot/$bsd"
1200 [ -n "$macos" ] && OS="$(($OS + 1))" && local MAC="macos MacOS m $macos ,${BS}${BS}:tbxi"
1201 [ -n "$macosx" ] && OS="$(($OS + 1))" && local MX="macosx MacOSX x $macosx ,${OSXBOOT}"
1202 [ -n "$darwin" ] && OS="$(($OS + 1))" && local DW="darwin Darwin d $darwin ,${BS}${BS}:tbxi"
1203 [ "$cdrom" = yes ] && OS="$(($OS + 1))" && local CD="cd CDROM c cd: ,${BS}${BS}:tbxi"
1204 [ "$network" = yes ] && OS="$(($OS + 1))" && local NET="net Network n enet: 0"
1205 [ "$of" = yes ] && OS="$(($OS + 1))" && local OF="of OpenFirmware o quit now"
1206 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: OS=$OS"
1209 ## Usage: OS-count defaultos timeout fgc bgc osname oslabel oskey osdev osfile ...
1210 [ "$DEBUG" = 1 ] && $PRINTF 1>&2 "$PRG: DEBUG: /bin/sh $magicboot $OS $defaultos $delay $fbc $bgc $YB $BSD $MAC $MX $DW $CD $NET $OF\n"
1211 FIRST="$(/bin/sh "$magicboot" "$OS" "$defaultos" "$delay" $fgc $bgc ${YB} ${BSD} ${MAC} ${MX} ${DW} ${CD} ${NET} ${OF})" || return 1
1216 ## mkofboot function.
1219 mount | grep "^$boot\>" > /dev/null
1220 if [ $? = 0 ] ; then
1221 echo 1>&2 "$PRG: $boot appears to be mounted! aborting."
1227 [ "$VERBOSE" = 1 ] && echo "$PRG: Creating HFS filesystem on $boot..."
1228 if (command -v dd > /dev/null 2>&1) ; then
1229 dd if=/dev/zero of="$boot" bs=512 count=1600 > /dev/null 2>&1
1231 hformat -l bootstrap "$boot" > /dev/null
1232 if [ $? != 0 ] ; then
1233 echo 1>&2 "$PRG: HFS filesystem creation failed!"
1236 humount "$boot" ## otherwise we might get confused.
1240 if (command -v mkdosfs > /dev/null 2>&1) ; then
1241 [ -x `command -v mkdosfs` ] || FAIL=1 ; else FAIL=1 ; fi
1242 if [ "$FAIL" = 1 ] ; then
1243 echo 1>&2 "$PRG: mkdosfs is not installed or cannot be found"
1247 [ "$VERBOSE" = 1 ] && echo "$PRG: Creating DOS filesystem on $boot..."
1248 if (command -v dd > /dev/null 2>&1) ; then
1249 dd if=/dev/zero of="$boot" bs=512 count=1600 > /dev/null 2>&1
1251 mkdosfs -n bootstrap "$boot" > /dev/null
1252 if [ $? != 0 ] ; then
1253 echo 1>&2 "$PRG: DOS filesystem creation failed!"
1263 if [ "$FORCE" = yes ] ; then
1267 [ "$fstype" = raw ] && $PRINTF 1>&2 "$PRG: Overwrite contents of $boot with $install? [y/N] "
1268 [ "$fstype" != raw ] && $PRINTF 1>&2 "$PRG: Create $fstype filesystem on $boot? [y/N] "
1275 echo 1>&2 "$PRG: Abort."
1282 ## for fstype=raw check if an ELF binary has already been dded.
1285 if [ "$(dd if="$boot" bs=1 skip=1 count=3 2>/dev/null)" = ELF ] ; then
1288 echo 1>&2 "$PRG: This partition has never had yaboot installed before, please run mkofboot"
1295 ## defaults for this are defined at the beginning of the script with
1299 "## yaboot configuration file generated by ybin $VERSION
1306 partition=$partition
1309 " > "$TMPCONF" || return 1
1311 [ "$DEBUG" = 1 ] && $PRINTF 1>&2 "\nDEBUG: autoconf:\n----\n" && cat "$TMPCONF" 1>&2 && echo 1>&2 "----"
1315 ## take out the trash.
1318 if [ -n "$TMPCONF" ] ; then rm -f "$TMPCONF" ; fi
1319 if [ -n "$FIRST" ] ; then rm -f "$FIRST" ; fi
1320 if [ -n "$TMPYABOOT" ] ; then rm -f "$TMPYABOOT" ; fi
1321 if [ -d "$TMP/bootstrap.$$" -a "$usemount" = yes ] ; then rmdir "$TMP/bootstrap.$$" ; fi
1329 ## absurdly bloated case statement to parse command line options.
1330 if [ $# != 0 ] ; then
1357 if [ -n "$2" ] ; then
1358 if [ "$boot" = "unconfigured" ]; then
1366 echo 1>&2 "$PRG: option requires an argument $1"
1367 echo 1>&2 "Try \`$PRG --help' for more information."
1372 if [ -n "$2" ] ; then
1378 echo 1>&2 "$PRG: option requires an argument $1"
1379 echo 1>&2 "Try \`$PRG --help' for more information."
1384 if [ -n "$2" ] ; then
1389 echo 1>&2 "$PRG: option requires an argument $1"
1390 echo 1>&2 "Try \`$PRG --help' for more information."
1395 if [ -n "$2" ] ; then
1401 echo 1>&2 "$PRG: option requires an argument $1"
1402 echo 1>&2 "Try \`$PRG --help' for more information."
1407 if [ -n "$2" ] ; then
1410 ERR=" Error in $CONF:"
1414 echo 1>&2 "$PRG: option requires an argument $1"
1415 echo 1>&2 "Try \`$PRG --help' for more information."
1420 if [ -n "$2" ] ; then
1426 echo 1>&2 "$PRG: option requires an argument $1"
1427 echo 1>&2 "Try \`$PRG --help' for more information."
1432 if [ -n "$2" ] ; then
1438 echo 1>&2 "$PRG: option requires an argument $1"
1439 echo 1>&2 "Try \`$PRG --help' for more information."
1474 if [ -n "$2" ] ; then
1477 echo 1>&2 "$PRG: WARNING: Deprecated option --device"
1481 echo 1>&2 "$PRG: option requires an argument $1"
1482 echo 1>&2 "Try \`$PRG --help' for more information."
1487 if [ -n "$2" ] ; then
1490 echo 1>&2 "$PRG: WARNING: Deprecated option --device"
1494 echo 1>&2 "$PRG: option requires an argument $1"
1495 echo 1>&2 "Try \`$PRG --help' for more information."
1500 if [ -n "$2" ] ; then
1503 echo 1>&2 "$PRG: WARNING: Deprecated option --device"
1507 echo 1>&2 "$PRG: option requires an argument $1"
1508 echo 1>&2 "Try \`$PRG --help' for more information."
1513 if [ -n "$2" ] ; then
1516 echo 1>&2 "$PRG: WARNING: Deprecated option --device"
1520 echo 1>&2 "$PRG: option requires an argument $1"
1521 echo 1>&2 "Try \`$PRG --help' for more information."
1526 if [ -n "$2" ] ; then
1529 echo 1>&2 "$PRG: WARNING: Deprecated option --device"
1533 echo 1>&2 "$PRG: option requires an argument $1"
1534 echo 1>&2 "Try \`$PRG --help' for more information."
1539 if [ -n "$2" ] ; then
1542 echo 1>&2 "$PRG: WARNING: Deprecated option --device"
1546 echo 1>&2 "$PRG: option requires an argument $1"
1547 echo 1>&2 "Try \`$PRG --help' for more information."
1555 echo 1>&2 "$PRG: unrecognized option \`$1'"
1556 echo 1>&2 "Try \`$PRG --help' for more information."
1563 ## check that specified config file exists, unless its /dev/null in
1564 ## which case we assume all options are done on the command line.
1565 if [ "$CONF" = /dev/null ] ; then
1571 ## if there is no config file use the automatic generation to make a
1572 ## generic yaboot.conf. do this before the confcheck to avoid wierd errors.
1573 if [ "$bootconf" = /dev/null ] ; then
1574 if (command -v yabootconfig > /dev/null 2>&1) ; then
1575 echo 1>&2 "$PRG: Warning: no /etc/yaboot.conf, running yabootconfig to make one"
1576 yabootconfig --noinstall --quiet
1577 if [ $? != 0 ] ; then
1578 echo 1>&2 "$PRG: yabootconfig failed, please supply a valid /etc/yaboot.conf"
1579 echo 1>&2 "$PRG: You may also use $PRG's --boot, --image, --partition, and --device switches"
1580 echo 1>&2 "$PRG: These switches will cause $PRG to generate a basic yaboot.conf on the fly"
1583 CONF=/etc/yaboot.conf
1585 ERR=" Error in $CONF:"
1591 ## Checks if each option was defined on the command line, and if so
1592 ## don't read it from the configuration file. this avoids
1593 ## configuration options from being set null, as well as command line
1594 ## options from being clobbered.
1595 [ "$ARGBT" != 1 -a $(parseconf ck boot) = 0 ] && boot=`parseconf str boot`
1596 [ "$ARGOB" != 1 -a $(parseconf ck ofboot) = 0 ] && ofboot=`parseconf str ofboot`
1597 [ "$ARGBF" != 1 -a $(parseconf ck install) = 0 ] && install=`parseconf str install`
1598 [ "$ARGWP" != 1 -a $(parseconf ck magicboot) = 0 ] && magicboot=`parseconf str magicboot`
1599 [ "$ARGMT" != 1 -a $(parseconf flag usemount) = 0 ] && usemount=yes
1600 [ "$ARGFS" != 1 -a $(parseconf ck fstype) = 0 ] && fstype=`parseconf str fstype`
1601 [ "$ARGBS" != 1 -a $(parseconf flag nobless) = 0 ] && bless=no
1602 [ "$ARGPT" != 1 -a $(parseconf flag protect) = 0 ] && protect=yes
1603 [ "$ARGHD" != 1 -a $(parseconf flag hide) = 0 ] && hide=yes
1604 [ "$ARGNV" != 1 -a $(parseconf flag nonvram) = 0 ] && nonvram=1
1605 [ $(parseconf ck hfstype) = 0 ] && hfstype=`parseconf str hfstype`
1606 [ $(parseconf ck hfscreator) = 0 ] && hfscreator=`parseconf str hfscreator`
1607 [ $(parseconf ck mntpoint) = 0 ] && mntpoint=`parseconf str mntpoint`
1608 [ $(parseconf ck delay) = 0 ] && delay=`parseconf str delay`
1609 [ $(parseconf ck timeout) = 0 ] && timeout=`parseconf str timeout`
1610 [ $(parseconf ck bsd) = 0 ] && bsd=`parseconf str bsd`
1611 [ $(parseconf ck macos) = 0 ] && macos=`parseconf str macos`
1612 [ $(parseconf ck macosx) = 0 ] && macosx=`parseconf str macosx`
1613 [ $(parseconf ck darwin) = 0 ] && darwin=`parseconf str darwin`
1614 [ $(parseconf ck defaultos) = 0 ] && defaultos=`parseconf str defaultos`
1615 [ $(parseconf ck fgcolor) = 0 ] && fgcolor=`parseconf str fgcolor`
1616 [ $(parseconf ck bgcolor) = 0 ] && bgcolor=`parseconf str bgcolor`
1617 [ $(parseconf ck icon) = 0 ] && export YBINOFICON=`parseconf str icon`
1618 [ $(parseconf flag enablecdboot) = 0 ] && cdrom=yes
1619 [ $(parseconf flag enablenetboot) = 0 ] && network=yes
1620 [ $(parseconf flag enableofboot) = 0 ] && of=yes
1621 [ $(parseconf flag brokenosx) = 0 ] && brokenosx=yes
1625 bootparts=$(($bootparts + 1))
1627 if [ "$bootparts" -gt 1 ]; then
1628 [ "$VERBOSE" = 1 ] && echo "$PRG: Iterating through list of boot partitions..."
1631 [ "$VERBOSE" = 1 ] && echo "$ABSPRG $ARGS -b $i"
1632 $ABSPRG $ARGS -b $i || rc=$?
1637 ## ffs!! rtfm! foad!
1638 if [ "$boot" = unconfigured ] ; then
1639 echo 1>&2 "$PRG: You must specify the device for the bootstrap partition. (ie: boot=/dev/hdaX)"
1640 echo 1>&2 "$PRG: Try \`$PRG --help' for more information."
1644 ## if there is still no config file use the automatic generation to make a
1645 ## generic yaboot.conf. do this before the confcheck to avoid wierd errors.
1646 if [ "$bootconf" = /dev/null ] ; then
1647 echo 1>&2 "$PRG: Warning: no yaboot.conf, using generic configuration."
1651 ## mntpoint is incompatible with mkofboot.
1652 if [ "$PRG" = mkofboot -a -n "$mntpoint" ] ; then
1653 echo 1>&2 "$PRG: Cannot be used with \`mntpoint='"
1657 ## validate configuration for sanity.
1660 if [ "x$bootonce" != "x" ]; then
1661 foundlabel=`sed s/\#.*// $bootconf | grep "label=$bootonce$" | wc -l`
1662 if [ "$nonvram" = 1 ]; then
1663 echo 1>&2 "$PRG: --bootonce specified, but nvsetenv not available."
1666 if [ "$foundlabel" = 1 ]; then
1667 nvsetenv boot-once "$bootonce"
1668 foundlabel=`nvsetenv boot-once`
1669 if [ "$foundlabel" != "boot-once=$bootonce" -a \
1670 "$foundlabel" != "$bootonce" ]; then
1671 echo 1>&2 "$PRG: Could not nvsetenv boot-once $bootonce"
1674 [ "$VERBOSE" = 1 ] && echo "$PRG: nvsetenv boot-once $bootonce"
1676 echo 1>&2 "$PRG: Could not find bootonce label [$bootonce] in $bootconf"
1683 ## check that we can use ofpath, its only needed for magicboot script
1684 ## building and nvram updates.
1685 if [ -n "$magicboot" -o "$nonvram" = 0 ] ; then
1686 if [ -z "$ofboot" -o -n "$macos" -o -n "$macosx" -o -n "$darwin" ] ; then
1687 if (command -v ofpath > /dev/null 2>&1) ; then
1688 [ -x `command -v ofpath` ]
1689 if [ $? != 0 ] ; then
1690 echo 1>&2 "$PRG: ofpath could not be found, aborting."
1694 echo 1>&2 "$PRG: ofpath could not be found, aborting."
1700 ## if password is set in yaboot.conf make sure permissions on that
1701 ## file are safe, warn if not.
1702 if (grep -q '^[[:space:]]*password[[:space:]]*=' "$bootconf" > /dev/null 2>&1) ; then
1706 ## check if we are root if needed.
1707 if [ "$usemount" = yes -a -z "$mntpoint" ] ; then
1708 if [ `id -u` != 0 ] ; then
1709 echo 1>&2 "$PRG: \`usemount' requires root privileges, go away."
1714 if [ "$fstype" = hfs ] ; then
1716 if [ $? != 0 ] ; then
1717 echo 1>&2 "$PRG: hfsutils is not installed or cannot be found"
1718 echo 1>&2 "$PRG: Try --mount if `uname -sr` supports HFS"
1723 ## convert unix device nodes to OpenFirmware pathnames
1724 if [ -n "$magicboot" -o "$nonvram" = 0 ] ; then
1725 convertpath || exit 1
1728 ## yaboot.conf autogeneration. MUST have secure mktemp to
1729 ## avoid race conditions. Debian's mktemp qualifies.
1730 if [ "$bootconf" = auto ] ; then
1731 TMPCONF=`mktemp -q "$TMP/$PRG.XXXXXX"`
1732 if [ $? != 0 ] ; then
1733 echo 1>&2 "$PRG: Could not create temporary file, aborting."
1738 if [ $? != 0 ] ; then
1739 echo 1>&2 "$PRG: An error occured generating yaboot.conf, aborting."
1746 if [ -n "$magicboot" ] ; then
1747 checkfirststage || exit 1
1748 if [ "$FIRSTSTG" = compat ] ; then
1750 if [ $? != 0 ] ; then
1751 echo 1>&2 "$PRG: An error occured while building first stage loader. aborting..."
1761 if [ "$fstype" = raw ] ; then
1763 raw_install || exit 1
1765 util_install || exit 1
1770 mnt_install || exit 1
1778 ## its not nice to erase the partition and then bail!
1779 if [ "$fstype" = msdos ] ; then
1780 echo 1>&2 "$PRG: mtools support is not implemented"
1781 echo 1>&2 "$PRG: Use --mount or add \`usemount' to $CONF"
1785 if [ "$fstype" = raw ] ; then
1786 raw_install || exit 1
1789 util_install || exit 1
1791 [ "$VERBOSE" = 1 ] && echo "$PRG: Installation complete."
1797 mnt_install || exit 1
1798 [ "$VERBOSE" = 1 ] && echo "$PRG: Installation complete."