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 or nvram exists and is executable
440 for program in nvsetenv nvram ; do
441 if (command -v $program > /dev/null 2>&1) && [ -x `command -v $program` ] ; then
446 if [ -z "$NVRAM_PROG" ] ; then
448 echo 1>&2 "$PRG: Warning: \`nvsetenv' and \`nvram' could not be found, nvram will not be updated"
452 if [ "$nonvram" = 0 ] ; then
453 ## if nvsetenv exists see if its the old broken version
454 if [ "$NVRAM_PROG" = "nvsetenv" ] && ! nvsetenv --version > /dev/null 2>&1 ; then
455 ## i check this myself to avoid misleading error
456 ## messages. nvsetenv should REALLY support --version.
457 if [ ! -e /dev/nvram ] ; then
458 echo 1>&2 "$PRG: /dev/nvram: No such file or directory"
459 echo 1>&2 "$PRG: Warning: nvram will not be updated"
461 elif [ ! -c /dev/nvram ] ; then
462 echo 1>&2 "$PRG: /dev/nvram: Not a character device"
463 echo 1>&2 "$PRG: Warning: nvram will not be updated"
465 elif [ ! -w /dev/nvram -o ! -r /dev/nvram ] ; then
466 echo 1>&2 "$PRG: /dev/nvram: Permission denied"
467 echo 1>&2 "$PRG: Warning: nvram will not be updated"
469 elif ! (dd if=/dev/nvram of=/dev/null bs=1 count=10 > /dev/null 2>&1) ; then
470 echo 1>&2 "$PRG: /dev/nvram: No such device"
471 echo 1>&2 "$PRG: Warning: nvram will not be updated"
475 echo 1>&2 "$PRG: Warning: Incompatible version of nvsetenv, nvram will not be updated"
480 if [ -f "$boot" ] ; then
481 echo 1>&2 "$PRG: $boot is a regular file, disabling nvram updating"
486 ## check for newworld mac. use cat hack due to /proc wierdness.
487 ## do not bail if we are on an OldWorld only warn (very loudly).
488 if [ "$(v=`cat /proc/cpuinfo 2>/dev/null | grep pmac-generation` ; echo ${v##*:})" = NewWorld ] ; then
490 elif [ "$(v=`cat /proc/cpuinfo 2>/dev/null | grep pmac-generation` ; echo ${v##*:})" = OldWorld ] ; then
492 echo 1>&2 '@@@@@@@@@@@@@@ WARNING!! WARNING!! WARNING!! @@@@@@@@@@@@@@'
493 echo 1>&2 "$PRG: Warning: This is an OldWorld PowerMac, $boot will **NOT** be bootable on this machine"
494 echo 1>&2 "$PRG: Oldworld PowerMacs need to use the quik bootloader, not yaboot"
495 echo 1>&2 '@@@@@@@@@@@@@@ WARNING!! WARNING!! WARNING!! @@@@@@@@@@@@@@'
497 [ "$nonvram" = 0 ] && echo 1>&2 "$PRG: OldWorld PowerMac, nvram will not be updated"
499 elif (cat /proc/cpuinfo 2>/dev/null | grep ^motherboard | grep -q AAPL) ; then
501 echo 1>&2 '@@@@@@@@@@@@@@ WARNING!! WARNING!! WARNING!! @@@@@@@@@@@@@@'
502 echo 1>&2 "$PRG: Warning: This is an OldWorld PowerMac, $boot will **NOT** be bootable on this machine"
503 echo 1>&2 "$PRG: Oldworld PowerMacs need to use the quik bootloader, not yaboot"
504 echo 1>&2 '@@@@@@@@@@@@@@ WARNING!! WARNING!! WARNING!! @@@@@@@@@@@@@@'
506 [ "$nonvram" = 0 ] && echo 1>&2 "$PRG: OldWorld PowerMac, nvram will not be updated"
508 elif (cat /proc/cpuinfo 2> /dev/null | grep ^machine | grep -q 'CHRP IBM') ; then
509 ## IBM hardware does not need nvram update AFAICT
513 #echo 1>&2 "$PRG: Warning: Unknown archetecture, $boot may not be bootable on this machine"
514 [ "$nonvram" = 0 ] && echo 1>&2 "$PRG: Warning: Unknown architecture, nvram will not be updated"
518 ## convert human readable color values from config to proper color
521 black) fgc=0 ;; blue) fgc=1 ;; green) fgc=2 ;; cyan) fgc=3 ;;
522 red) fgc=4 ;; purple) fgc=5 ;; brown) fgc=6 ;; light-gray) fgc=7 ;;
523 dark-gray) fgc=8 ;; light-blue) fgc=9 ;; light-green) fgc=a ;;
524 light-cyan) fgc=b ;; light-red) fgc=c ;; light-purple) fgc=d ;;
525 yellow) fgc=e ;; white) fgc=f ;;
527 echo 1>&2 "$PRG:$ERR Invalid fgcolor: \`$fgcolor'"
532 black) bgc=0 ;; blue) bgc=1 ;; green) bgc=2 ;; cyan) bgc=3 ;;
533 red) bgc=4 ;; purple) bgc=5 ;; brown) bgc=6 ;; light-gray) bgc=7 ;;
534 dark-gray) bgc=8 ;; light-blue) bgc=9 ;; light-green) bgc=a ;;
535 light-cyan) bgc=b ;; light-red) bgc=c ;; light-purple) bgc=d ;;
536 yellow) bgc=e ;; white) bgc=f ;;
538 echo 1>&2 "$PRG:$ERR Invalid bgcolor: \`$bgcolor'"
543 ## if delay is not set use yaboot's timeout
544 if [ -z "$delay" ] ; then
545 delay="$(($timeout / 10))"
548 if [ "$CONFERR" = 1 ] ; then
556 ## if readlink is missing use a kludge
557 if (command -v readlink > /dev/null 2>&1) ; then
562 local SYMTARGET="$(v=`ls -l "$2" 2>/dev/null` ; echo ${v##*> })"
563 if [ -n "$SYMTARGET" ] ; then
572 ## /etc/yaboot.conf with password should not be world readable.
575 if [ -L "$bootconf" ] ; then
576 local realfile="$(readlink -f "$bootconf")" || return 0
578 local realfile="$bootconf"
581 ## don't bother if we could not read the symlink
582 [ -z "$realfile" ] && return 0
583 [ ! -f "$realfile" ] && return 0
585 ## get permissions, and don't bother checking if we can't
586 local PERM=`v=$(ls -l "$realfile" 2>/dev/null) ; echo ${v%% *}`
587 [ -z "$PERM" ] && return 0
588 [ `echo ${#PERM}` != 10 ] && return 0
591 -rw-------|-r--------)
592 if [ ! -O "$realfile" -a `id -u` = 0 ] ; then
593 echo 1>&2 "$PRG: Warning: $bootconf is not owned by root"
596 -rw-r-----|-r--r-----)
597 if [ ! -O "$realfile" -a `id -u` = 0 ] ; then
598 echo 1>&2 "$PRG: Warning: $bootconf is not owned by root"
600 if [ ! -G "$realfile" -a `id -g` = 0 ] ; then
601 echo 1>&2 "$PRG: Warning: $bootconf is not owned by group root"
604 -r--r--r--|-rw-r--r--|-rw-rw-r--|-rw-rw-rw-|-rw-rw----)
605 echo 1>&2 "$PRG: Warning: Insecure permissions on $bootconf: $PERM should be -rw-------"
608 echo 1>&2 "$PRG: Warning: Incorrect permissions on $bootconf: $PERM should be -rw-------"
615 ## figure out bootstrap device OF pathname if user did not supply it.
616 if [ -z "$ofboot" ] ; then
617 [ "$VERBOSE" = 1 ] && echo "$PRG: Finding OpenFirmware device path to \`$boot'..."
618 ofboot="$($OFPATH $boot)"
619 if [ $? != 0 ] ; then
620 echo 1>&2 "$PRG: Unable to find OpenFirmware path for boot=$boot"
621 echo 1>&2 "$PRG: Please add ofboot=<path> where <path> is the OpenFirmware path to $boot to $CONF"
624 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: ofboot set to \`$ofboot'"
627 ## figure out OF device path for macos/macosx if user supplied a unix device node.
628 if [ -n "$bsd" ] ; then
631 [ "$VERBOSE" = 1 ] && echo "$PRG: Finding OpenFirmware device path to \`$bsd'..."
633 bsd="$($OFPATH $bsd)"
634 if [ $? != 0 ] ; then
635 echo 1>&2 "$PRG: Unable to determine OpenFirmware path for bsd=$sbsd"
636 echo 1>&2 "$PRG: Try specifying the real OpenFirmware path for bsd=$sbsd in $CONF"
639 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: bsd set to \`$bsd' from \`$sbsd'"
642 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: bsd left alone: \`$bsd'"
647 if [ -n "$macos" ] ; then
650 [ "$VERBOSE" = 1 ] && echo "$PRG: Finding OpenFirmware device path to \`$macos'..."
651 local smacos="$macos"
652 macos="$($OFPATH $macos)"
653 if [ $? != 0 ] ; then
654 echo 1>&2 "$PRG: Unable to determine OpenFirmware path for macos=$smacos"
655 echo 1>&2 "$PRG: Try specifying the real OpenFirmware path for macos=$smacos in $CONF"
658 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: macos set to \`$macos' from \`$smacos'"
661 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: macos left alone: \`$macos'"
666 if [ -n "$macosx" ] ; then
669 [ "$VERBOSE" = 1 ] && echo "$PRG: Finding OpenFirmware device path to \`$macosx'..."
670 local smacosx="$macosx"
671 macosx="$($OFPATH $macosx)"
672 if [ $? != 0 ] ; then
673 echo 1>&2 "$PRG: Unable to determine OpenFirmware path for macosx=$smacosx"
674 echo 1>&2 "$PRG: Try specifying the real OpenFirmware path for macosx=$smacosx in $CONF"
677 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: macosx set to \`$macosx' from \`$smacosx'"
680 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: macosx left alone: \`$macosx'"
685 if [ -n "$darwin" ] ; then
688 [ "$VERBOSE" = 1 ] && echo "$PRG: Finding OpenFirmware device path to \`$darwin'..."
689 local sdarwin="$darwin"
690 darwin="$($OFPATH $darwin)"
691 if [ $? != 0 ] ; then
692 echo 1>&2 "$PRG: Unable to determine OpenFirmware path for darwin=$sdarwin"
693 echo 1>&2 "$PRG: Try specifying the real OpenFirmware path for darwin=$sdarwin in $CONF"
696 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: darwin set to \`$darwin' from \`$sdarwin'"
699 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: darwin left alone: \`$darwin'"
704 if [ "$CONVERR" = 1 ] ; then
711 ## make sure the hfsutils we need are installed and executable.
714 if (command -v hmount > /dev/null 2>&1) ; then
715 [ -x `command -v hmount` ] || FAIL=1 ; else FAIL=1 ; fi
716 if (command -v humount > /dev/null 2>&1) ; then
717 [ -x `command -v humount` ] || FAIL=1 ; else FAIL=1 ; fi
718 if (command -v hcopy > /dev/null 2>&1) ; then
719 [ -x `command -v hcopy` ] || FAIL=1 ; else FAIL=1 ; fi
720 if (command -v hattrib > /dev/null 2>&1) ; then
721 [ -x `command -v hattrib` ] || FAIL=1 ; else FAIL=1 ; fi
722 if (command -v hformat > /dev/null 2>&1) ; then
723 [ -x `command -v hformat` ] || FAIL=1 ; else FAIL=1 ; fi
725 if [ "$FAIL" = 1 ] ; then
732 ## This is gross, IBM CHRP OF needs a .note added to the yaboot
733 ## binary, nobody knows whether this note will affect PowerMac OF or
734 ## not (or could in the future).
737 local YBDIR="${install%/*}"
738 if [ -x "$YBDIR/addnote" ] ; then
739 TMPYABOOT=`mktemp -q "$TMP/yaboot.XXXXXX"`
740 if [ $? != 0 ] ; then
741 echo 1>&2 "$PRG: Could not create temporary file, aborting."
744 if (cat "$install" > "$TMPYABOOT" 2> /dev/null) ; then
747 echo 1>&2 "$PRG: Could not create temporary file, aborting."
751 [ "$DEBUG" = 1 ] && echo "$PRG: Embedding CHRP note section in temp yaboot..."
752 "$YBDIR/addnote" "$install" > /dev/null 2>&1
753 if [ $? != 0 ] ; then
754 echo 1>&2 "$PRG: Could not install note section required by your architecture"
758 echo 1>&2 "$PRG: Your architecture requires $YBDIR/addnote which cannot be found"
764 ## install using userspace utilities rather then kernel filesytem
765 ## support. hfsutils only, mtools not supported.
768 ## catch signals, and humount, cleanup done by trap 0.
769 trap "humount $boot ; exit 129" 1
770 trap "echo 1>&2 $SIGINT ; humount $boot ; exit 130" 2
771 trap "humount $boot ; exit 131" 3
772 trap "humount $boot ; exit 143" 15
774 ## filenames on bootstrap partition. ofboot hard codes yaboot.
776 local CFFILE=yaboot.conf
778 ## if there is a magicboot script to install we will give it the
779 ## hfstype (should be "tbxi") and give yaboot type "boot".
780 if [ -n "$magicboot" ] ; then
783 local BTTYPE="$hfstype"
786 if [ -n "$magicboot" ] ; then
787 local WRAP="${magicboot##*/}"
790 ## set verbose messages here so they don't show temporary file paths
791 local INSTALLFIRST="$PRG: Installing first stage bootstrap $magicboot onto $boot..."
792 local INSTALLPRIMARY="$PRG: Installing primary bootstrap $install onto $boot..."
794 ## repoint magicboot as the real first stage loader if using the
795 ## modern automatic generating ofboot.b.
796 if [ -n "$FIRST" ] ; then
798 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: set magicboot to $FIRST"
801 ## gross hack, add note section for IBM CHRP
802 if [ "$ADDNOTE" = yes ] ; then
803 hack_yaboot || return 1
806 if [ "$fstype" = hfs ] ; then
807 if [ "$protect" = yes ] ; then
811 if [ "$hide" = yes ] ; then
815 ## make sure the device is not mounted as a filesystem before
816 ## we start mucking with it directly.
817 mount | grep "^$boot\>" > /dev/null
819 echo 1>&2 "$PRG: $boot appears to be mounted! aborting."
823 ## hmount is really more of a way to make sure we have a valid HFS
824 ## filesystem before proceding, and hcopy requires it...
825 hmount "$boot" > /dev/null
826 if [ $? != 0 ] ; then
827 echo 1>&2 "$PRG: $boot appears to have never had a bootstrap installed, please run mkofboot"
831 ## must be explicit with target filename to avoid hfsutils
832 ## braindamage ("_" -> " " filename mangling) also avoid
833 ## ambiguity in the bootstrap partition.
834 if [ -n "$magicboot" ] ; then
835 [ "$VERBOSE" = 1 ] && echo "$INSTALLFIRST"
836 hcopy -r "$magicboot" :ofboot.b
837 if [ $? != 0 ] ; then
838 echo 1>&2 "$PRG: An error occured while writing to $boot"
843 [ "$VERBOSE" = 1 ] && echo "$INSTALLPRIMARY"
844 hcopy -r "$install" :"$BTFILE"
845 if [ $? != 0 ] ; then
846 echo 1>&2 "$PRG: An error occured while writing to $boot"
850 [ "$VERBOSE" = 1 ] && echo "$PRG: Installing $bootconf onto $boot..."
851 hcopy -r "$bootconf" :"$CFFILE"
852 if [ $? != 0 ] ; then
853 echo 1>&2 "$PRG: An error occured while writing to $boot"
857 if [ -n "$BSDLOADER" ] ; then
858 [ "$VERBOSE" = 1 ] && echo "$PRG: Installing $BSDLOADER onto $boot..."
859 hcopy -r "$BSDLOADER" :ofwboot
860 if [ $? != 0 ] ; then
861 echo 1>&2 "$PRG: An error occured while writing to $boot"
866 ## set all file's attributes, if a magicboot script exists it
867 ## gets the configured hfstype instead of yaboot (should be
868 ## "tbxi") so it gets booted by OF.
869 if [ -n "$magicboot" ] ; then
870 [ "$VERBOSE" = 1 ] && echo "$PRG: Setting attributes on $WRAP..."
871 hattrib -t "$hfstype" -c "$hfscreator" $INVISIBLE $LOCK :ofboot.b
872 if [ $? != 0 ] ; then
873 echo 1>&2 "$PRG: Warning: error setting attributes on $WRAP"
874 echo 1>&2 "$PRG: This is probably bad but we'll ignore it."
878 [ "$VERBOSE" = 1 ] && echo "$PRG: Setting attributes on $BTFILE..."
879 hattrib -t "$BTTYPE" -c "$hfscreator" $INVISIBLE $LOCK :"$BTFILE"
880 if [ $? != 0 ] ; then
881 echo 1>&2 "$PRG: Warning: error setting attributes on $BTFILE"
882 echo 1>&2 "$PRG: This is probably bad but we'll ignore it"
885 [ "$VERBOSE" = 1 ] && echo "$PRG: Setting attributes on $CFFILE..."
886 hattrib -t "conf" -c "$hfscreator" $INVISIBLE $LOCK :"$CFFILE"
887 if [ $? != 0 ] ; then
888 echo 1>&2 "$PRG: Warning: error setting attributes on $CFFILE"
889 echo 1>&2 "$PRG: This is probably unimportant so we'll ignore it"
892 if [ -n "$BSDLOADER" ] ; then
893 [ "$VERBOSE" = 1 ] && echo "$PRG: Setting attributes on ofwboot..."
894 hattrib -t "bsdb" -c "$hfscreator" $INVISIBLE $LOCK :ofwboot
895 if [ $? != 0 ] ; then
896 echo 1>&2 "$PRG: Warning: error setting attributes on ofwboot"
897 echo 1>&2 "$PRG: This is probably unimportant so we'll ignore it"
901 ## bless the root directory so OF will find the boot file
902 if [ "$bless" = yes ] ; then
903 [ "$VERBOSE" = 1 ] && echo "$PRG: Blessing $boot with Holy Penguin Pee..."
905 if [ $? != 0 ] ; then
906 echo 1>&2 "$PRG: Warning: error blessing $boot"
907 echo 1>&2 "$PRG: This is probably bad but we'll ignore it"
911 ## clean up the ~/.hcwd file hmount creates
912 humount "$boot" > /dev/null
915 ## use explicit filename if we don't bless.
916 if [ "$bless" = yes ] ; then
917 local OFFILE='\\:tbxi'
919 if [ -n "$magicboot" ] ; then
920 local OFFILE=ofboot.b
922 local OFFILE="$BTFILE"
926 ## update the boot-device variable in OF nvram.
927 if [ "$nonvram" = 0 ] ; then
928 [ "$VERBOSE" = 1 ] && echo "$PRG: Updating OpenFirmware boot-device variable in nvram..."
929 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: boot-device=${ofboot},${OFFILE}"
930 if [ "$NVRAM_PROG" = "nvsetenv" ] ; then
931 nvsetenv boot-device "${ofboot},${OFFILE}"
933 nvram -p common --update-config boot-device="${ofboot},${OFFILE}"
935 if [ $? != 0 ] ; then
936 echo 1>&2 "$PRG: An error occured while updating nvram, we'll ignore it"
941 echo 1>&2 "$PRG: mtools support is not implemented"
942 echo 1>&2 "$PRG: Use --mount or add \`usemount' to $CONF"
949 ## used by mnt_install so mntpoint= can be supported in a cleaner way.
952 ## we can even create bootstrap filesystem images directly if you
954 if [ -f "$boot" ] ; then
958 if [ -e "$TMP/bootstrap.$$" ] ; then
959 echo 1>&2 "$PRG: $TMP/bootstrap.$$ exists, aborting."
963 mkdir -m 700 "$TMP/bootstrap.$$"
964 if [ $? != 0 ] ; then
965 echo 1>&2 "$PRG: Could not create mountpoint directory, aborting."
969 mount | grep "^$boot\>" > /dev/null
971 echo 1>&2 "$PRG: $boot appears to be mounted! aborting."
975 [ "$VERBOSE" = 1 ] && echo "$PRG: Mounting $boot..."
976 mount -t "$fstype" -o rw,umask=077$loop "$boot" "$TMP/bootstrap.$$"
977 if [ $? != 0 ] ; then
978 echo 1>&2 "$PRG: An error occured mounting $boot"
982 ## catch signals, set here to avoid umounting something we did not
983 ## mount. cleanup done by trap 0.
984 trap "umount $boot ; exit 129" 1
985 trap "echo 1>&2 $SIGINT ; umount $boot ; exit 130" 2
986 trap "umount $boot ; exit 131" 3
987 trap "umount $boot ; exit 143" 15
989 TARGET="$TMP/bootstrap.$$"
993 ## umnt funtion which checks whether we mounted anything or not, for
994 ## mntpoint= this makes the code below cleaner IMO.
997 if [ -z "$mntpoint" ] ; then
998 [ "$1" = failure ] && echo 1>&2 "$PRG: Attempting to umount $boot..."
1000 if [ $? != 0 ] ; then
1001 echo 1>&2 "$PRG: umount of $boot failed!"
1004 [ "$1" = failure ] && echo 1>&2 "$PRG: umount successfull"
1012 ## Use kernel filesytem drivers to mount the bootstrap partition like
1013 ## any other filesystem and copy the files there with standard un*x
1019 ## msdosfs is broken, yaboot may not support this filename.
1020 if [ "$fstype" = msdos ] ; then
1021 local CFFILE=yaboot.cnf
1023 local CFFILE=yaboot.conf
1026 if [ -n "$magicboot" ] ; then
1027 local WRAP="${magicboot##*/}"
1030 ## set verbose messages here so they don't show temporary file paths
1031 local INSTALLFIRST="$PRG: Installing first stage bootstrap $magicboot onto $boot..."
1032 local INSTALLPRIMARY="$PRG: Installing primary bootstrap $install onto $boot..."
1034 ## repoint magicboot as the real first stage loader if using the
1035 ## modern automatic generating ofboot.b.
1036 if [ -n "$FIRST" ] ; then
1038 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: set magicboot to $FIRST"
1041 ## gross hack, add note section for IBM CHRP
1042 if [ "$ADDNOTE" = yes ] ; then
1043 hack_yaboot || return 1
1046 ## call mnt() function to take care of mounting filesystem if needed
1047 if [ -z "$mntpoint" ] ; then
1053 ## this is probably insecure on modern filesystems, but i think
1054 ## safe on crippled hfs/dosfs. user should ensure mntpoint= is safe.
1055 if [ -n "$magicboot" ] ; then
1056 [ "$VERBOSE" = 1 ] && echo "$INSTALLFIRST"
1057 cp -f "$magicboot" "$TARGET/ofboot.b"
1058 if [ $? != 0 ] ; then
1059 echo 1>&2 "$PRG: An error occured while writing to $boot"
1060 umnt failure "$TARGET"
1065 [ "$VERBOSE" = 1 ] && echo "$INSTALLPRIMARY"
1066 cp -f "$install" "$TARGET/$BTFILE"
1067 if [ $? != 0 ] ; then
1068 echo 1>&2 "$PRG: An error occured while writing to $boot"
1069 umnt failure "$TARGET"
1073 [ "$VERBOSE" = 1 ] && echo "$PRG: Installing $bootconf onto $boot..."
1074 cp -f "$bootconf" "$TARGET/$CFFILE"
1075 if [ $? != 0 ] ; then
1076 echo 1>&2 "$PRG: An error occured while writing to $boot"
1077 umnt failure "$TARGET"
1081 if [ -n "$BSDLOADER" ] ; then
1082 [ "$VERBOSE" = 1 ] && echo "$PRG: Installing $BSDLOADER onto $boot..."
1083 cp -f "$BSDLOADER" "$TARGET/ofwboot"
1084 if [ $? != 0 ] ; then
1085 echo 1>&2 "$PRG: An error occured while writing to $boot"
1086 umnt failure "$TARGET"
1091 if [ "$protect" = yes ] ; then
1092 [ "$VERBOSE" = 1 ] && echo "$PRG: Setting read-only attributes..."
1093 chmod a-w "$TARGET/$BTFILE"
1094 chmod a-w "$TARGET/$CFFILE"
1095 if [ -n "$magicboot" ] ; then
1096 chmod a-w "$TARGET/ofboot.b"
1098 if [ -n "$BSDLOADER" ] ; then
1099 chmod a-w "$TARGET/ofwboot"
1104 umnt success "$TARGET" || return 1
1106 ## make variable with a \ to avoid shell fsckage. ugly ugly ugly.
1108 if [ -n "$magicboot" ] ; then
1109 [ -n "$OFDIR" ] && OFDIR="${BS}${OFDIR}${BS}"
1110 local OFFILE="${OFDIR}ofboot.b"
1112 [ -n "$OFDIR" ] && OFDIR="${BS}${OFDIR}${BS}"
1113 local OFFILE="${OFDIR}${BTFILE}"
1116 ## update the boot-device variable in OF nvram.
1117 if [ "$nonvram" = 0 ] ; then
1118 [ "$VERBOSE" = 1 ] && echo "$PRG: Updating OpenFirmware boot-device variable in nvram..."
1119 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: boot-device=${ofboot},${OFFILE}"
1120 if [ "$NVRAM_PROG" = "nvsetenv" ] ; then
1121 nvsetenv boot-device "${ofboot},${OFFILE}"
1123 nvram -p common --update-config boot-device="${ofboot},${OFFILE}"
1125 if [ $? != 0 ] ; then
1126 echo 1>&2 "$PRG: An error occured while updating nvram, we'll ignore it"
1129 echo 1>&2 "$PRG: Warning: You must manually configure OpenFirmware to boot."
1135 ## raw installation, for IBM RS/6000 hardware, yaboot is dded to the
1136 ## bootstrap partition.
1139 ## make sure the device is not mounted as a filesystem before
1140 ## we start mucking with it directly.
1141 mount | grep "^$boot\>" > /dev/null
1142 if [ $? = 0 ] ; then
1143 echo 1>&2 "$PRG: $boot appears to be mounted! aborting."
1147 ## set verbosity message before munging the yaboot pathname
1148 local INSTALLPRIMARY="$PRG: Installing primary bootstrap $install onto $boot..."
1150 ## gross hack, add note section for IBM CHRP
1151 if [ "$ADDNOTE" = yes ] ; then
1152 hack_yaboot || return 1
1155 [ "$VERBOSE" = 1 ] && echo "$INSTALLPRIMARY"
1156 dd if=/dev/zero of="$boot" bs=512 count=1600 > /dev/null 2>&1
1157 dd if="$install" of="$boot" bs=512 > /dev/null 2>&1
1158 if [ $? != 0 ] ; then
1159 echo 1>&2 "$PRG: Installation failed."
1163 [ "$VERBOSE" = 1 ] && echo "$PRG: Installation successful"
1166 ## make sure the first stage ofboot generator is compatible.
1169 grep -q "^#%ybinscript-" "$magicboot" 2> /dev/null
1170 if [ "$?" = 0 ] ; then
1171 local magic=`grep "^#%ybinscript-" "$magicboot"`
1172 local ver="${magic##*-}"
1173 if [ "$ver" = "1.1" ] ; then
1177 echo 1>&2 "$PRG: Incompatible version of first stage loader $magicboot. aborting..."
1186 ## build the first stage loader.
1189 ## must have 7 backslashes to == \\ printf + shell = bizarre... or,
1190 ## make special variable to contain a \ (need \\ to make \) to work
1191 ## around echo -e -n brokeness.
1195 ## deal with mntpoint=
1196 [ -n "$OFDIR" ] && local OFDIR="${BS}${OFDIR}${BS}"
1198 ## some misguided people insist on installing OSX on
1199 ## HorribleFileSystem+ instead of UFS, as a result MacOS deblesses
1200 ## OSX, making it unbootable. if apple localizes the filesystem hierarchy again screw it.
1201 [ "$brokenosx" = yes ] && local OSXBOOT="${BS}System${BS}Library${BS}CoreServices${BS}BootX"
1202 [ "$brokenosx" = no ] && local OSXBOOT="${BS}${BS}:tbxi"
1204 ## assign variables for configured menu options.
1205 [ "$usemount" = no -a "$bless" = yes ] && local YB="yaboot GNU l $ofboot ,${BS}${BS}yaboot"
1206 [ "$usemount" = yes -o "$bless" = no ] && local YB="yaboot GNU l $ofboot ,${OFDIR}yaboot"
1207 [ -n "$bsd" ] && OS="$(($OS + 1))" && local BSD="ybsd BSD b $ofboot ,${BS}${BS}ofwboot/$bsd"
1208 [ -n "$macos" ] && OS="$(($OS + 1))" && local MAC="macos MacOS m $macos ,${BS}${BS}:tbxi"
1209 [ -n "$macosx" ] && OS="$(($OS + 1))" && local MX="macosx MacOSX x $macosx ,${OSXBOOT}"
1210 [ -n "$darwin" ] && OS="$(($OS + 1))" && local DW="darwin Darwin d $darwin ,${BS}${BS}:tbxi"
1211 [ "$cdrom" = yes ] && OS="$(($OS + 1))" && local CD="cd CDROM c cd: ,${BS}${BS}:tbxi"
1212 [ "$network" = yes ] && OS="$(($OS + 1))" && local NET="net Network n enet: 0"
1213 [ "$of" = yes ] && OS="$(($OS + 1))" && local OF="of OpenFirmware o quit now"
1214 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: OS=$OS"
1217 ## Usage: OS-count defaultos timeout fgc bgc osname oslabel oskey osdev osfile ...
1218 [ "$DEBUG" = 1 ] && $PRINTF 1>&2 "$PRG: DEBUG: /bin/sh $magicboot $OS $defaultos $delay $fbc $bgc $YB $BSD $MAC $MX $DW $CD $NET $OF\n"
1219 FIRST="$(/bin/sh "$magicboot" "$OS" "$defaultos" "$delay" $fgc $bgc ${YB} ${BSD} ${MAC} ${MX} ${DW} ${CD} ${NET} ${OF})" || return 1
1224 ## mkofboot function.
1227 mount | grep "^$boot\>" > /dev/null
1228 if [ $? = 0 ] ; then
1229 echo 1>&2 "$PRG: $boot appears to be mounted! aborting."
1235 [ "$VERBOSE" = 1 ] && echo "$PRG: Creating HFS filesystem on $boot..."
1236 if (command -v dd > /dev/null 2>&1) ; then
1237 dd if=/dev/zero of="$boot" bs=512 count=1600 > /dev/null 2>&1
1239 hformat -l bootstrap "$boot" > /dev/null
1240 if [ $? != 0 ] ; then
1241 echo 1>&2 "$PRG: HFS filesystem creation failed!"
1244 humount "$boot" ## otherwise we might get confused.
1248 if (command -v mkdosfs > /dev/null 2>&1) ; then
1249 [ -x `command -v mkdosfs` ] || FAIL=1 ; else FAIL=1 ; fi
1250 if [ "$FAIL" = 1 ] ; then
1251 echo 1>&2 "$PRG: mkdosfs is not installed or cannot be found"
1255 [ "$VERBOSE" = 1 ] && echo "$PRG: Creating DOS filesystem on $boot..."
1256 if (command -v dd > /dev/null 2>&1) ; then
1257 dd if=/dev/zero of="$boot" bs=512 count=1600 > /dev/null 2>&1
1259 mkdosfs -n bootstrap "$boot" > /dev/null
1260 if [ $? != 0 ] ; then
1261 echo 1>&2 "$PRG: DOS filesystem creation failed!"
1271 if [ "$FORCE" = yes ] ; then
1275 [ "$fstype" = raw ] && $PRINTF 1>&2 "$PRG: Overwrite contents of $boot with $install? [y/N] "
1276 [ "$fstype" != raw ] && $PRINTF 1>&2 "$PRG: Create $fstype filesystem on $boot? [y/N] "
1283 echo 1>&2 "$PRG: Abort."
1290 ## for fstype=raw check if an ELF binary has already been dded.
1293 if [ "$(dd if="$boot" bs=1 skip=1 count=3 2>/dev/null)" = ELF ] ; then
1296 echo 1>&2 "$PRG: This partition has never had yaboot installed before, please run mkofboot"
1303 ## defaults for this are defined at the beginning of the script with
1307 "## yaboot configuration file generated by ybin $VERSION
1314 partition=$partition
1317 " > "$TMPCONF" || return 1
1319 [ "$DEBUG" = 1 ] && $PRINTF 1>&2 "\nDEBUG: autoconf:\n----\n" && cat "$TMPCONF" 1>&2 && echo 1>&2 "----"
1323 ## take out the trash.
1326 if [ -n "$TMPCONF" ] ; then rm -f "$TMPCONF" ; fi
1327 if [ -n "$FIRST" ] ; then rm -f "$FIRST" ; fi
1328 if [ -n "$TMPYABOOT" ] ; then rm -f "$TMPYABOOT" ; fi
1329 if [ -d "$TMP/bootstrap.$$" -a "$usemount" = yes ] ; then rmdir "$TMP/bootstrap.$$" ; fi
1337 ## absurdly bloated case statement to parse command line options.
1338 if [ $# != 0 ] ; then
1365 if [ -n "$2" ] ; then
1366 if [ "$boot" = "unconfigured" ]; then
1374 echo 1>&2 "$PRG: option requires an argument $1"
1375 echo 1>&2 "Try \`$PRG --help' for more information."
1380 if [ -n "$2" ] ; then
1386 echo 1>&2 "$PRG: option requires an argument $1"
1387 echo 1>&2 "Try \`$PRG --help' for more information."
1392 if [ -n "$2" ] ; then
1397 echo 1>&2 "$PRG: option requires an argument $1"
1398 echo 1>&2 "Try \`$PRG --help' for more information."
1403 if [ -n "$2" ] ; then
1409 echo 1>&2 "$PRG: option requires an argument $1"
1410 echo 1>&2 "Try \`$PRG --help' for more information."
1415 if [ -n "$2" ] ; then
1418 ERR=" Error in $CONF:"
1422 echo 1>&2 "$PRG: option requires an argument $1"
1423 echo 1>&2 "Try \`$PRG --help' for more information."
1428 if [ -n "$2" ] ; then
1434 echo 1>&2 "$PRG: option requires an argument $1"
1435 echo 1>&2 "Try \`$PRG --help' for more information."
1440 if [ -n "$2" ] ; then
1446 echo 1>&2 "$PRG: option requires an argument $1"
1447 echo 1>&2 "Try \`$PRG --help' for more information."
1482 if [ -n "$2" ] ; then
1485 echo 1>&2 "$PRG: WARNING: Deprecated option --device"
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
1498 echo 1>&2 "$PRG: WARNING: Deprecated option --device"
1502 echo 1>&2 "$PRG: option requires an argument $1"
1503 echo 1>&2 "Try \`$PRG --help' for more information."
1508 if [ -n "$2" ] ; then
1511 echo 1>&2 "$PRG: WARNING: Deprecated option --device"
1515 echo 1>&2 "$PRG: option requires an argument $1"
1516 echo 1>&2 "Try \`$PRG --help' for more information."
1521 if [ -n "$2" ] ; then
1524 echo 1>&2 "$PRG: WARNING: Deprecated option --device"
1528 echo 1>&2 "$PRG: option requires an argument $1"
1529 echo 1>&2 "Try \`$PRG --help' for more information."
1534 if [ -n "$2" ] ; then
1537 echo 1>&2 "$PRG: WARNING: Deprecated option --device"
1541 echo 1>&2 "$PRG: option requires an argument $1"
1542 echo 1>&2 "Try \`$PRG --help' for more information."
1547 if [ -n "$2" ] ; then
1550 echo 1>&2 "$PRG: WARNING: Deprecated option --device"
1554 echo 1>&2 "$PRG: option requires an argument $1"
1555 echo 1>&2 "Try \`$PRG --help' for more information."
1563 echo 1>&2 "$PRG: unrecognized option \`$1'"
1564 echo 1>&2 "Try \`$PRG --help' for more information."
1571 ## check that specified config file exists, unless its /dev/null in
1572 ## which case we assume all options are done on the command line.
1573 if [ "$CONF" = /dev/null ] ; then
1579 ## if there is no config file use the automatic generation to make a
1580 ## generic yaboot.conf. do this before the confcheck to avoid wierd errors.
1581 if [ "$bootconf" = /dev/null ] ; then
1582 if (command -v yabootconfig > /dev/null 2>&1) ; then
1583 echo 1>&2 "$PRG: Warning: no /etc/yaboot.conf, running yabootconfig to make one"
1584 yabootconfig --noinstall --quiet
1585 if [ $? != 0 ] ; then
1586 echo 1>&2 "$PRG: yabootconfig failed, please supply a valid /etc/yaboot.conf"
1587 echo 1>&2 "$PRG: You may also use $PRG's --boot, --image, --partition, and --device switches"
1588 echo 1>&2 "$PRG: These switches will cause $PRG to generate a basic yaboot.conf on the fly"
1591 CONF=/etc/yaboot.conf
1593 ERR=" Error in $CONF:"
1599 ## Checks if each option was defined on the command line, and if so
1600 ## don't read it from the configuration file. this avoids
1601 ## configuration options from being set null, as well as command line
1602 ## options from being clobbered.
1603 [ "$ARGBT" != 1 -a $(parseconf ck boot) = 0 ] && boot=`parseconf str boot`
1604 [ "$ARGOB" != 1 -a $(parseconf ck ofboot) = 0 ] && ofboot=`parseconf str ofboot`
1605 [ "$ARGBF" != 1 -a $(parseconf ck install) = 0 ] && install=`parseconf str install`
1606 [ "$ARGWP" != 1 -a $(parseconf ck magicboot) = 0 ] && magicboot=`parseconf str magicboot`
1607 [ "$ARGMT" != 1 -a $(parseconf flag usemount) = 0 ] && usemount=yes
1608 [ "$ARGFS" != 1 -a $(parseconf ck fstype) = 0 ] && fstype=`parseconf str fstype`
1609 [ "$ARGBS" != 1 -a $(parseconf flag nobless) = 0 ] && bless=no
1610 [ "$ARGPT" != 1 -a $(parseconf flag protect) = 0 ] && protect=yes
1611 [ "$ARGHD" != 1 -a $(parseconf flag hide) = 0 ] && hide=yes
1612 [ "$ARGNV" != 1 -a $(parseconf flag nonvram) = 0 ] && nonvram=1
1613 [ $(parseconf ck hfstype) = 0 ] && hfstype=`parseconf str hfstype`
1614 [ $(parseconf ck hfscreator) = 0 ] && hfscreator=`parseconf str hfscreator`
1615 [ $(parseconf ck mntpoint) = 0 ] && mntpoint=`parseconf str mntpoint`
1616 [ $(parseconf ck delay) = 0 ] && delay=`parseconf str delay`
1617 [ $(parseconf ck timeout) = 0 ] && timeout=`parseconf str timeout`
1618 [ $(parseconf ck bsd) = 0 ] && bsd=`parseconf str bsd`
1619 [ $(parseconf ck macos) = 0 ] && macos=`parseconf str macos`
1620 [ $(parseconf ck macosx) = 0 ] && macosx=`parseconf str macosx`
1621 [ $(parseconf ck darwin) = 0 ] && darwin=`parseconf str darwin`
1622 [ $(parseconf ck defaultos) = 0 ] && defaultos=`parseconf str defaultos`
1623 [ $(parseconf ck fgcolor) = 0 ] && fgcolor=`parseconf str fgcolor`
1624 [ $(parseconf ck bgcolor) = 0 ] && bgcolor=`parseconf str bgcolor`
1625 [ $(parseconf ck icon) = 0 ] && export YBINOFICON=`parseconf str icon`
1626 [ $(parseconf flag enablecdboot) = 0 ] && cdrom=yes
1627 [ $(parseconf flag enablenetboot) = 0 ] && network=yes
1628 [ $(parseconf flag enableofboot) = 0 ] && of=yes
1629 [ $(parseconf flag brokenosx) = 0 ] && brokenosx=yes
1633 bootparts=$(($bootparts + 1))
1635 if [ "$bootparts" -gt 1 ]; then
1636 [ "$VERBOSE" = 1 ] && echo "$PRG: Iterating through list of boot partitions..."
1639 [ "$VERBOSE" = 1 ] && echo "$ABSPRG $ARGS -b $i"
1640 $ABSPRG $ARGS -b $i || rc=$?
1645 ## ffs!! rtfm! foad!
1646 if [ "$boot" = unconfigured ] ; then
1647 echo 1>&2 "$PRG: You must specify the device for the bootstrap partition. (ie: boot=/dev/hdaX)"
1648 echo 1>&2 "$PRG: Try \`$PRG --help' for more information."
1652 ## if there is still no config file use the automatic generation to make a
1653 ## generic yaboot.conf. do this before the confcheck to avoid wierd errors.
1654 if [ "$bootconf" = /dev/null ] ; then
1655 echo 1>&2 "$PRG: Warning: no yaboot.conf, using generic configuration."
1659 ## mntpoint is incompatible with mkofboot.
1660 if [ "$PRG" = mkofboot -a -n "$mntpoint" ] ; then
1661 echo 1>&2 "$PRG: Cannot be used with \`mntpoint='"
1665 ## validate configuration for sanity.
1668 if [ "x$bootonce" != "x" ]; then
1669 foundlabel=`sed s/\#.*// $bootconf | grep "label=$bootonce$" | wc -l`
1670 if [ "$nonvram" = 0 ]; then
1671 echo 1>&2 "$PRG: --bootonce specified, but nvsetenv not available."
1674 if [ "$foundlabel" = 1 ]; then
1675 nvsetenv boot-once "$bootonce"
1676 foundlabel=`nvsetenv boot-once`
1677 if [ "$foundlabel" != "boot-once=$bootonce" ]; then
1678 echo 1>&2 "$PRG: Could not nvsetenv boot-once $bootonce"
1681 [ "$VERBOSE" = 1 ] && echo "$PRG: nvsetenv boot-once $bootonce"
1683 echo 1>&2 "$PRG: Could not find bootonce label [$bootonce] in $bootconf"
1690 ## check that we can use ofpath, its only needed for magicboot script
1691 ## building and nvram updates.
1692 if [ -n "$magicboot" -o "$nonvram" = 0 ] ; then
1693 if [ -z "$ofboot" -o -n "$macos" -o -n "$macosx" -o -n "$darwin" ] ; then
1694 if (command -v ofpath > /dev/null 2>&1) ; then
1695 [ -x `command -v ofpath` ]
1696 if [ $? != 0 ] ; then
1697 echo 1>&2 "$PRG: ofpath could not be found, aborting."
1701 echo 1>&2 "$PRG: ofpath could not be found, aborting."
1707 ## if password is set in yaboot.conf make sure permissions on that
1708 ## file are safe, warn if not.
1709 if (grep -q '^[[:space:]]*password[[:space:]]*=' "$bootconf" > /dev/null 2>&1) ; then
1713 ## check if we are root if needed.
1714 if [ "$usemount" = yes -a -z "$mntpoint" ] ; then
1715 if [ `id -u` != 0 ] ; then
1716 echo 1>&2 "$PRG: \`usemount' requires root privileges, go away."
1721 if [ "$fstype" = hfs ] ; then
1723 if [ $? != 0 ] ; then
1724 echo 1>&2 "$PRG: hfsutils is not installed or cannot be found"
1725 echo 1>&2 "$PRG: Try --mount if `uname -sr` supports HFS"
1730 ## convert unix device nodes to OpenFirmware pathnames
1731 if [ -n "$magicboot" -o "$nonvram" = 0 ] ; then
1732 convertpath || exit 1
1735 ## yaboot.conf autogeneration. MUST have secure mktemp to
1736 ## avoid race conditions. Debian's mktemp qualifies.
1737 if [ "$bootconf" = auto ] ; then
1738 TMPCONF=`mktemp -q "$TMP/$PRG.XXXXXX"`
1739 if [ $? != 0 ] ; then
1740 echo 1>&2 "$PRG: Could not create temporary file, aborting."
1745 if [ $? != 0 ] ; then
1746 echo 1>&2 "$PRG: An error occured generating yaboot.conf, aborting."
1753 if [ -n "$magicboot" ] ; then
1754 checkfirststage || exit 1
1755 if [ "$FIRSTSTG" = compat ] ; then
1757 if [ $? != 0 ] ; then
1758 echo 1>&2 "$PRG: An error occured while building first stage loader. aborting..."
1768 if [ "$fstype" = raw ] ; then
1770 raw_install || exit 1
1772 util_install || exit 1
1777 mnt_install || exit 1
1785 ## its not nice to erase the partition and then bail!
1786 if [ "$fstype" = msdos ] ; then
1787 echo 1>&2 "$PRG: mtools support is not implemented"
1788 echo 1>&2 "$PRG: Use --mount or add \`usemount' to $CONF"
1792 if [ "$fstype" = raw ] ; then
1793 raw_install || exit 1
1796 util_install || exit 1
1798 [ "$VERBOSE" = 1 ] && echo "$PRG: Installation complete."
1804 mnt_install || exit 1
1805 [ "$VERBOSE" = 1 ] && echo "$PRG: Installation complete."