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"
30 SIGINT="$PRG: Interrupt caught ... exiting"
31 VERSION=1.3.11-UNRELEASED_UNSUPPORTED
37 ## avoid older versions of ofpath shipped in debian boot-floppies etc.
38 if [ -x "${PATH_PREFIX}/usr/sbin/ofpath" ] ; then
39 OFPATH="${PATH_PREFIX}/usr/sbin/ofpath"
44 ## catch signals, clean up junk in /tmp.
47 trap "echo 1>&2 $SIGINT ; exit 130" 2
51 ## allow for non-existent config file, in which case it will be
52 ## generated from command line arguments.
53 if [ -f /etc/yaboot.conf ] ; then
56 ERR=" Error in $CONF:"
62 ## define default configuration
65 ## allow default to work on packaged and non-packaged yaboot.
66 ## no default for magicboot since it is not required everywhere.
67 if [ -f /usr/local/lib/yaboot/yaboot ] ; then
68 install=/usr/local/lib/yaboot/yaboot
69 elif [ -f /usr/lib/yaboot/yaboot ] ; then
70 install=/usr/lib/yaboot/yaboot
75 if (cat /proc/cpuinfo 2> /dev/null | grep ^machine | grep -q 'CHRP IBM') ; then
94 ## yaboot autoconf defaults
102 ## this program behaves differently based on how its called, this
103 ## ensures that nothing nasty happens if someone makes a bogus
111 echo 1>&2 "This program must be called as either \`ybin' or \`mkofboot'"
116 ## check for printf, use it if possible otherwise fall back on
117 ## unreliable echo -e -n ("SUS" says echo shall support no switches)
118 if [ "$(printf printf_test 2>/dev/null)" = printf_test ] ; then
124 ## make fake `id' if its missing, outputs 0 since if its missing we
125 ## are probably running on boot floppies and thus are root.
126 if (command -v id > /dev/null 2>&1) ; then
140 Written by Ethan Benson
142 Copyright (C) 2000, 2001, 2002, 2003 Ethan Benson
143 This is free software; see the source for copying conditions. There is NO
144 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
151 "Usage: $PRG [OPTION]...
152 Update/install bootloader onto a bootstrap partition.
154 -b, --boot set bootstrap partition device [ -b /dev/hda2 ]
155 -o, --ofboot set bootstrap partition OpenFirmware device
156 default: automatically determined [ -o hd:2 ]
157 -i, --install pathname to the actual bootloader binary
158 default: /usr/{local/}lib/yaboot/yaboot same as
159 install= in config file [ -i bootloader_file ]
160 -C, --config use alternate configuration file (ybin and yaboot)
162 -m, --magicboot pathname to a OpenFirmware magicboot (CHRP) script
163 --filesystem set the filesystem type of the bootstrap partition
164 available options are hfs, msdos, and raw
165 [ --filesystem hfs ] default is hfs
166 --nobless don't bless the root directory, this should only
167 be used if you are using a MacOS boot partition
168 as the bootstrap partition (not recommended)
169 -M, --mount don't use userspace hfsutils to modify the
170 bootstrap instead try and mount the filesystem
171 directly. Note that attributes cannot be set
172 this way and you will have to manually modify
173 OpenFirmware to make your system bootable
174 --protect set the read-only (locked) bit on all bootstrap
176 --hide set the invisible bit on all bootstrap files
177 this is useful of you don't want them to be
179 --nonvram do not update the boot-device variable in nvram.
180 --force don't ever ask for confirmation
181 -v, --verbose make $PRG more verbose
182 --debug print boring junk only useful for debugging
183 -h, --help display this help and exit
184 -V, --version output version information and exit"
187 ## configuration file parsing. FIXME: need a method which can parse
193 v=`grep "^$2[\ ,=]" "$CONF"` ; echo "${v#*=}"
196 grep "^$2\>" "$CONF" > /dev/null && echo 0 || echo 1
199 grep "^$2[\ ,=]" "$CONF" > /dev/null && echo 0 || echo 1
204 ## check for existence of a configuration file, and make sure we have
208 if [ ! -e "$CONF" ] ; then
209 echo 1>&2 "$PRG: $CONF: No such file or directory"
211 elif [ ! -f "$CONF" ] ; then
212 echo 1>&2 "$PRG: $CONF: Not a regular file"
214 elif [ ! -r "$CONF" ] ; then
215 echo 1>&2 "$PRG: $CONF: Permission denied"
222 ## check to make sure the configuration file is sane and correct.
223 ## maybe this is an insane ammount of error checking, but I want to
224 ## make sure (hopfully) nothing unexpected ever happens. and i just
225 ## like useful errors from programs. every error just marks an error
226 ## variable so we give the user as much info as possible before we
230 if [ ! -e "$boot" ] ; then
231 echo 1>&2 "$PRG: $boot: No such file or directory"
233 elif [ ! -b "$boot" -a ! -f "$boot" ] ; then
234 echo 1>&2 "$PRG: $boot: Not a regular file or block device"
236 elif [ ! -w "$boot" -o ! -r "$boot" ] ; then
237 [ -z "$mntpoint" ] && echo 1>&2 "$PRG: $boot: Permission denied"
238 [ -z "$mntpoint" ] && CONFERR=1
241 if [ ! -e "$install" ] ; then
242 echo 1>&2 "$PRG: $install: No such file or directory"
244 elif [ ! -f "$install" ] ; then
245 echo 1>&2 "$PRG: $bootconf: Not a regular file"
247 elif [ ! -r "$install" ] ; then
248 echo 1>&2 "$PRG: $install: Permission denied"
252 if [ "$bootconf" = auto ] ; then
254 elif [ ! -e "$bootconf" ] ; then
255 echo 1>&2 "$PRG: $bootconf: No such file or directory"
257 elif [ ! -f "$bootconf" ] ; then
258 echo 1>&2 "$PRG: $bootconf: Not a regular file"
260 elif [ ! -r "$bootconf" ] ; then
261 echo 1>&2 "$PRG: $bootconf: Permission denied"
265 if [ -n "$magicboot" ] ; then
266 if [ ! -e "$magicboot" ] ; then
267 echo 1>&2 "$PRG: $magicboot: No such file or directory"
269 elif [ ! -f "$magicboot" ] ; then
270 echo 1>&2 "$PRG: $magicboot: Not a regular file"
272 elif [ ! -r "$magicboot" ] ; then
273 echo 1>&2 "$PRG: $magicboot: Permission denied"
282 if [ "$ARGFS" = 1 ] ; then
283 echo 1>&2 "$PRG: --filesystem must be either \`hfs', \`msdos', or \`raw'"
285 echo 1>&2 "$PRG:$ERR \`fstype' must be either \`hfs', \`msdos', or \`raw'"
291 ## if we are not using HFS filesystems we don't care about HFS
293 if [ "$fstype" = hfs ] ; then
294 if [ `echo ${#hfstype}` != 4 ] ; then
295 if [ "$ARGTP" = 1 ] ; then
296 echo 1>&2 "$PRG: --type must be 4 characters"
298 echo 1>&2 "$PRG:$ERR \`hfstype' must be 4 characters"
303 if [ `echo ${#hfscreator}` != 4 ] ; then
304 if [ "$ARGCT" = 1 ] ; then
305 echo 1>&2 "$PRG: --creator must be 4 characters"
307 echo 1>&2 "$PRG:$ERR \`hfscreator' must be 4 characters"
313 ## some options are not compatible with fstype=raw
314 if [ "$fstype" = raw ] ; then
315 if [ -n "$mntpoint" ] ; then
316 echo 1>&2 "$PRG:$ERR \`mntpoint' is not compatible with fstype=raw"
319 if [ "$usemount" = yes ] ; then
320 echo 1>&2 "$PRG:$ERR \`usemount' is not compatible with fstype=raw"
323 if [ -n "$magicboot" ] ; then
324 echo 1>&2 "$PRG:$ERR \`magicboot' scripts cannot be used with fstype=raw"
329 if [ -n "$mntpoint" ] ; then
331 if [ ! -e "$mntpoint" ] ; then
332 echo 1>&2 "$PRG: $mntpoint: No such file or directory"
334 elif [ ! -d "$mntpoint" ] ; then
335 echo 1>&2 "$PRG: $mntpoint: Not a directory"
337 elif [ ! -w "$mntpoint" -o ! -r "$mntpoint" ] ; then
338 echo 1>&2 "$PRG: $mntpoint: Permission denied"
340 elif [ ! -O "$mntpoint" -a `id -u` != 0 ] ; then
341 echo 1>&2 "$PRG: $mntpoint: Permission denied (not owner)"
345 ## make sure no embedded spaces exist
346 echo "$mntpoint" | grep -q [[:space:]]
348 echo 1>&2 "$PRG:$ERR \`mntpoint=$mntpoint' contains embedded spaces, don't use lame filenames"
352 ## make sure $mntpoint is on $boot, this matters to nvram updating.
353 if [ "$(v=`df "$mntpoint" 2> /dev/null | grep ^/dev/` ; echo ${v%%[ ]*})" != "$boot" -a -d "$mntpoint" ] ; then
354 echo 1>&2 "$PRG: $mntpoint is not located on $boot"
356 ## more then one subdirectory deep is not supported. no sed available on boot floppies ( / -> \ )
357 elif [ "$mntpoint" != "$(v=`df "$mntpoint" 2> /dev/null | grep ^/dev/` ; echo ${v##*[ ]})" ] ; then
358 echo "$(v=`df "$mntpoint" 2>/dev/null | grep ^/dev/`; m=${v##*[ ]}; echo "${mntpoint##*$m/}")" | grep -q /
360 echo 1>&2 "$PRG:$ERR $mntpoint is more then one subdirectory deep from root of $boot"
363 OFDIR="$(v=`df "$mntpoint" 2>/dev/null | grep ^/dev/`; m=${v##*[ ]}; echo "${mntpoint##*$m/}")"
367 if [ "$usemount" = no ] ; then
368 echo 1>&2 "$PRG:$ERR \`mntpoint=' requires \`usemount' be set"
373 if [ -n "$magicboot" ] ; then
374 ## check for bsd loader
375 if [ -n "$bsd" ] ; then
376 if [ -f /usr/lib/yaboot/ofwboot -a -r /usr/lib/yaboot/ofwboot ] ; then
377 BSDLOADER="/usr/lib/yaboot/ofwboot"
378 elif [ -f /usr/local/lib/yaboot/ofwboot -a -r /usr/local/lib/yaboot/ofwboot ] ; then
379 BSDLOADER="/usr/local/lib/yaboot/ofwboot"
381 echo 1>&2 "$PRG: /usr/local/lib/yaboot/ofwboot: No such file or directory"
382 echo 1>&2 "$PRG: With the bsd= option set you must have the bsd boot loader ofwboot"
387 ## convert defaultos variable
389 linux|Linux|GNU|Gnu|gnu)
396 if [ -z "$bsd" ] ; then
397 echo 1>&2 "$PRG:$ERR no entry for \`bsd' found, but defaultos is set to \`bsd'"
403 if [ -z "$macos" ] ; then
404 echo 1>&2 "$PRG:$ERR no entry for \`macos' found, but defaultos is set to \`macos'"
410 if [ -z "$macosx" ] ; then
411 echo 1>&2 "$PRG:$ERR no entry for \`macosx' found, but defaultos is set to \`macosx'"
417 if [ -z "$darwin" ] ; then
418 echo 1>&2 "$PRG:$ERR no entry for \`darwin' found, but defaultos is set to \`darwin'"
423 echo 1>&2 "$PRG:$ERR \`defaultos' must be either \`linux', \`bsd', \`macos' or \`macosx'"
429 ## nvsetenv requires /proc
430 if [ ! -f /proc/uptime -a "$nonvram" = 0 ] ; then
431 echo 1>&2 "$PRG: /proc filesystem is not mounted, nvram will not be updated"
435 if [ "$nonvram" = 0 ] ; then
436 ## see if nvsetenv exists and is executable
437 if (command -v nvsetenv > /dev/null 2>&1) ; then
438 [ -x `command -v nvsetenv` ] || MISSING=1 ; else MISSING=1
441 if [ "$nonvram" = 0 ] ; then
442 ## if nvsetenv exists see if its the old broken version
443 if [ "$MISSING" != 1 ] ; then
444 nvsetenv --version > /dev/null 2>&1 || OLD=1
447 echo 1>&2 "$PRG: Warning: \`nvsetenv' could not be found, nvram will not be updated"
450 if [ "$OLD" = 1 ] ; then
451 ## i check this myself to avoid misleading error
452 ## messages. nvsetenv should REALLY support --version.
453 if [ ! -e /dev/nvram ] ; then
454 echo 1>&2 "$PRG: /dev/nvram: No such file or directory"
455 echo 1>&2 "$PRG: Warning: nvram will not be updated"
457 elif [ ! -c /dev/nvram ] ; then
458 echo 1>&2 "$PRG: /dev/nvram: Not a character device"
459 echo 1>&2 "$PRG: Warning: nvram will not be updated"
461 elif [ ! -w /dev/nvram -o ! -r /dev/nvram ] ; then
462 echo 1>&2 "$PRG: /dev/nvram: Permission denied"
463 echo 1>&2 "$PRG: Warning: nvram will not be updated"
467 echo 1>&2 "$PRG: Warning: Incompatible version of \`nvsetenv', nvram will not be updated"
472 if [ -f "$boot" ] ; then
473 echo 1>&2 "$PRG: $boot is a regular file, disabling nvram updating"
478 ## check for newworld mac. use cat hack due to /proc wierdness.
479 ## do not bail if we are on an OldWorld only warn (very loudly).
480 if [ "$(v=`cat /proc/cpuinfo 2>/dev/null | grep pmac-generation` ; echo ${v##*:})" = NewWorld ] ; then
482 elif [ "$(v=`cat /proc/cpuinfo 2>/dev/null | grep pmac-generation` ; echo ${v##*:})" = OldWorld ] ; then
484 echo 1>&2 '@@@@@@@@@@@@@@ WARNING!! WARNING!! WARNING!! @@@@@@@@@@@@@@'
485 echo 1>&2 "$PRG: Warning: This is an OldWorld PowerMac, $boot will **NOT** be bootable on this machine"
486 echo 1>&2 "$PRG: Oldworld PowerMacs need to use the quik bootloader, not yaboot"
487 echo 1>&2 '@@@@@@@@@@@@@@ WARNING!! WARNING!! WARNING!! @@@@@@@@@@@@@@'
489 [ "$nonvram" = 0 ] && echo 1>&2 "$PRG: OldWorld PowerMac, nvram will not be updated"
491 elif (cat /proc/cpuinfo 2>/dev/null | grep ^motherboard | grep -q AAPL) ; then
493 echo 1>&2 '@@@@@@@@@@@@@@ WARNING!! WARNING!! WARNING!! @@@@@@@@@@@@@@'
494 echo 1>&2 "$PRG: Warning: This is an OldWorld PowerMac, $boot will **NOT** be bootable on this machine"
495 echo 1>&2 "$PRG: Oldworld PowerMacs need to use the quik bootloader, not yaboot"
496 echo 1>&2 '@@@@@@@@@@@@@@ WARNING!! WARNING!! WARNING!! @@@@@@@@@@@@@@'
498 [ "$nonvram" = 0 ] && echo 1>&2 "$PRG: OldWorld PowerMac, nvram will not be updated"
500 elif (cat /proc/cpuinfo 2> /dev/null | grep ^machine | grep -q 'CHRP IBM') ; then
501 ## IBM hardware does not need nvram update AFAICT
505 #echo 1>&2 "$PRG: Warning: Unknown archetecture, $boot may not be bootable on this machine"
506 [ "$nonvram" = 0 ] && echo 1>&2 "$PRG: Warning: Unknown architecture, nvram will not be updated"
510 ## convert human readable color values from config to proper color
513 black) fgc=0 ;; blue) fgc=1 ;; green) fgc=2 ;; cyan) fgc=3 ;;
514 red) fgc=4 ;; purple) fgc=5 ;; brown) fgc=6 ;; light-gray) fgc=7 ;;
515 dark-gray) fgc=8 ;; light-blue) fgc=9 ;; light-green) fgc=a ;;
516 light-cyan) fgc=b ;; light-red) fgc=c ;; light-purple) fgc=d ;;
517 yellow) fgc=e ;; white) fgc=f ;;
519 echo 1>&2 "$PRG:$ERR Invalid fgcolor: \`$fgcolor'"
524 black) bgc=0 ;; blue) bgc=1 ;; green) bgc=2 ;; cyan) bgc=3 ;;
525 red) bgc=4 ;; purple) bgc=5 ;; brown) bgc=6 ;; light-gray) bgc=7 ;;
526 dark-gray) bgc=8 ;; light-blue) bgc=9 ;; light-green) bgc=a ;;
527 light-cyan) bgc=b ;; light-red) bgc=c ;; light-purple) bgc=d ;;
528 yellow) bgc=e ;; white) bgc=f ;;
530 echo 1>&2 "$PRG:$ERR Invalid bgcolor: \`$bgcolor'"
535 ## if delay is not set use yaboot's timeout
536 if [ -z "$delay" ] ; then
537 delay="$(($timeout / 10))"
540 if [ "$CONFERR" = 1 ] ; then
548 ## if readlink is missing use a kludge
549 if (command -v readlink > /dev/null 2>&1) ; then
554 local SYMTARGET="$(v=`ls -l "$2" 2>/dev/null` ; echo ${v##*> })"
555 if [ -n "$SYMTARGET" ] ; then
564 ## /etc/yaboot.conf with password should not be world readable.
567 if [ -L "$bootconf" ] ; then
568 local realfile="$(readlink -f "$bootconf")" || return 0
570 local realfile="$bootconf"
573 ## don't bother if we could not read the symlink
574 [ -z "$realfile" ] && return 0
575 [ ! -f "$realfile" ] && return 0
577 ## get permissions, and don't bother checking if we can't
578 local PERM=`v=$(ls -l "$realfile" 2>/dev/null) ; echo ${v%% *}`
579 [ -z "$PERM" ] && return 0
580 [ `echo ${#PERM}` != 10 ] && return 0
583 -rw-------|-r--------)
584 if [ ! -O "$realfile" -a `id -u` = 0 ] ; then
585 echo 1>&2 "$PRG: Warning: $bootconf is not owned by root"
588 -rw-r-----|-r--r-----)
589 if [ ! -O "$realfile" -a `id -u` = 0 ] ; then
590 echo 1>&2 "$PRG: Warning: $bootconf is not owned by root"
592 if [ ! -G "$realfile" -a `id -g` = 0 ] ; then
593 echo 1>&2 "$PRG: Warning: $bootconf is not owned by group root"
596 -r--r--r--|-rw-r--r--|-rw-rw-r--|-rw-rw-rw-|-rw-rw----)
597 echo 1>&2 "$PRG: Warning: Insecure permissions on $bootconf: $PERM should be -rw-------"
600 echo 1>&2 "$PRG: Warning: Incorrect permissions on $bootconf: $PERM should be -rw-------"
607 ## figure out bootstrap device OF pathname if user did not supply it.
608 if [ -z "$ofboot" ] ; then
609 [ "$VERBOSE" = 1 ] && echo "$PRG: Finding OpenFirmware device path to \`$boot'..."
610 ofboot="$($OFPATH $boot)"
611 if [ $? != 0 ] ; then
612 echo 1>&2 "$PRG: Unable to find OpenFirmware path for boot=$boot"
613 echo 1>&2 "$PRG: Please add ofboot=<path> where <path> is the OpenFirmware path to $boot to $CONF"
616 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: ofboot set to \`$ofboot'"
619 ## figure out OF device path for macos/macosx if user supplied a unix device node.
620 if [ -n "$bsd" ] ; then
623 [ "$VERBOSE" = 1 ] && echo "$PRG: Finding OpenFirmware device path to \`$bsd'..."
625 bsd="$($OFPATH $bsd)"
626 if [ $? != 0 ] ; then
627 echo 1>&2 "$PRG: Unable to determine OpenFirmware path for bsd=$sbsd"
628 echo 1>&2 "$PRG: Try specifying the real OpenFirmware path for bsd=$sbsd in $CONF"
631 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: bsd set to \`$bsd' from \`$sbsd'"
634 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: bsd left alone: \`$bsd'"
639 if [ -n "$macos" ] ; then
642 [ "$VERBOSE" = 1 ] && echo "$PRG: Finding OpenFirmware device path to \`$macos'..."
643 local smacos="$macos"
644 macos="$($OFPATH $macos)"
645 if [ $? != 0 ] ; then
646 echo 1>&2 "$PRG: Unable to determine OpenFirmware path for macos=$smacos"
647 echo 1>&2 "$PRG: Try specifying the real OpenFirmware path for macos=$smacos in $CONF"
650 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: macos set to \`$macos' from \`$smacos'"
653 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: macos left alone: \`$macos'"
658 if [ -n "$macosx" ] ; then
661 [ "$VERBOSE" = 1 ] && echo "$PRG: Finding OpenFirmware device path to \`$macosx'..."
662 local smacosx="$macosx"
663 macosx="$($OFPATH $macosx)"
664 if [ $? != 0 ] ; then
665 echo 1>&2 "$PRG: Unable to determine OpenFirmware path for macosx=$smacosx"
666 echo 1>&2 "$PRG: Try specifying the real OpenFirmware path for macosx=$smacosx in $CONF"
669 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: macosx set to \`$macosx' from \`$smacosx'"
672 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: macosx left alone: \`$macosx'"
677 if [ -n "$darwin" ] ; then
680 [ "$VERBOSE" = 1 ] && echo "$PRG: Finding OpenFirmware device path to \`$darwin'..."
681 local sdarwin="$darwin"
682 darwin="$($OFPATH $darwin)"
683 if [ $? != 0 ] ; then
684 echo 1>&2 "$PRG: Unable to determine OpenFirmware path for darwin=$sdarwin"
685 echo 1>&2 "$PRG: Try specifying the real OpenFirmware path for darwin=$sdarwin in $CONF"
688 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: darwin set to \`$darwin' from \`$sdarwin'"
691 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: darwin left alone: \`$darwin'"
696 if [ "$CONVERR" = 1 ] ; then
703 ## make sure the hfsutils we need are installed and executable.
706 if (command -v hmount > /dev/null 2>&1) ; then
707 [ -x `command -v hmount` ] || FAIL=1 ; else FAIL=1 ; fi
708 if (command -v humount > /dev/null 2>&1) ; then
709 [ -x `command -v humount` ] || FAIL=1 ; else FAIL=1 ; fi
710 if (command -v hcopy > /dev/null 2>&1) ; then
711 [ -x `command -v hcopy` ] || FAIL=1 ; else FAIL=1 ; fi
712 if (command -v hattrib > /dev/null 2>&1) ; then
713 [ -x `command -v hattrib` ] || FAIL=1 ; else FAIL=1 ; fi
714 if (command -v hformat > /dev/null 2>&1) ; then
715 [ -x `command -v hformat` ] || FAIL=1 ; else FAIL=1 ; fi
717 if [ "$FAIL" = 1 ] ; then
724 ## This is gross, IBM CHRP OF needs a .note added to the yaboot
725 ## binary, nobody knows whether this note will affect PowerMac OF or
726 ## not (or could in the future).
729 local YBDIR="${install%/*}"
730 if [ -x "$YBDIR/addnote" ] ; then
731 TMPYABOOT=`mktemp -q "$TMP/yaboot.XXXXXX"`
732 if [ $? != 0 ] ; then
733 echo 1>&2 "$PRG: Could not create temporary file, aborting."
736 if (cat "$install" > "$TMPYABOOT" 2> /dev/null) ; then
739 echo 1>&2 "$PRG: Could not create temporary file, aborting."
743 [ "$DEBUG" = 1 ] && echo "$PRG: Embedding CHRP note section in temp yaboot..."
744 "$YBDIR/addnote" "$install" > /dev/null 2>&1
745 if [ $? != 0 ] ; then
746 echo 1>&2 "$PRG: Could not install note section required by your architecture"
750 echo 1>&2 "$PRG: Your architecture requires $YBDIR/addnote which cannot be found"
756 ## install using userspace utilities rather then kernel filesytem
757 ## support. hfsutils only, mtools not supported.
760 ## catch signals, and humount, cleanup done by trap 0.
761 trap "humount $boot ; exit 129" 1
762 trap "echo 1>&2 $SIGINT ; humount $boot ; exit 130" 2
763 trap "humount $boot ; exit 131" 3
764 trap "humount $boot ; exit 143" 15
766 ## filenames on bootstrap partition. ofboot hard codes yaboot.
768 local CFFILE=yaboot.conf
770 ## if there is a magicboot script to install we will give it the
771 ## hfstype (should be "tbxi") and give yaboot type "boot".
772 if [ -n "$magicboot" ] ; then
775 local BTTYPE="$hfstype"
778 if [ -n "$magicboot" ] ; then
779 local WRAP="${magicboot##*/}"
782 ## set verbose messages here so they don't show temporary file paths
783 local INSTALLFIRST="$PRG: Installing first stage bootstrap $magicboot onto $boot..."
784 local INSTALLPRIMARY="$PRG: Installing primary bootstrap $install onto $boot..."
786 ## repoint magicboot as the real first stage loader if using the
787 ## modern automatic generating ofboot.b.
788 if [ -n "$FIRST" ] ; then
790 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: set magicboot to $FIRST"
793 ## gross hack, add note section for IBM CHRP
794 if [ "$ADDNOTE" = yes ] ; then
795 hack_yaboot || return 1
798 if [ "$fstype" = hfs ] ; then
799 if [ "$protect" = yes ] ; then
803 if [ "$hide" = yes ] ; then
807 ## make sure the device is not mounted as a filesystem before
808 ## we start mucking with it directly.
809 mount | grep "^$boot\>" > /dev/null
811 echo 1>&2 "$PRG: $boot appears to be mounted! aborting."
815 ## hmount is really more of a way to make sure we have a valid HFS
816 ## filesystem before proceding, and hcopy requires it...
817 hmount "$boot" > /dev/null
818 if [ $? != 0 ] ; then
819 echo 1>&2 "$PRG: $boot appears to have never had a bootstrap installed, please run mkofboot"
823 ## must be explicit with target filename to avoid hfsutils
824 ## braindamage ("_" -> " " filename mangling) also avoid
825 ## ambiguity in the bootstrap partition.
826 if [ -n "$magicboot" ] ; then
827 [ "$VERBOSE" = 1 ] && echo "$INSTALLFIRST"
828 hcopy -r "$magicboot" :ofboot.b
829 if [ $? != 0 ] ; then
830 echo 1>&2 "$PRG: An error occured while writing to $boot"
835 [ "$VERBOSE" = 1 ] && echo "$INSTALLPRIMARY"
836 hcopy -r "$install" :"$BTFILE"
837 if [ $? != 0 ] ; then
838 echo 1>&2 "$PRG: An error occured while writing to $boot"
842 [ "$VERBOSE" = 1 ] && echo "$PRG: Installing $bootconf onto $boot..."
843 hcopy -r "$bootconf" :"$CFFILE"
844 if [ $? != 0 ] ; then
845 echo 1>&2 "$PRG: An error occured while writing to $boot"
849 if [ -n "$BSDLOADER" ] ; then
850 [ "$VERBOSE" = 1 ] && echo "$PRG: Installing $BSDLOADER onto $boot..."
851 hcopy -r "$BSDLOADER" :ofwboot
852 if [ $? != 0 ] ; then
853 echo 1>&2 "$PRG: An error occured while writing to $boot"
858 ## set all file's attributes, if a magicboot script exists it
859 ## gets the configured hfstype instead of yaboot (should be
860 ## "tbxi") so it gets booted by OF.
861 if [ -n "$magicboot" ] ; then
862 [ "$VERBOSE" = 1 ] && echo "$PRG: Setting attributes on $WRAP..."
863 hattrib -t "$hfstype" -c "$hfscreator" $INVISIBLE $LOCK :ofboot.b
864 if [ $? != 0 ] ; then
865 echo 1>&2 "$PRG: Warning: error setting attributes on $WRAP"
866 echo 1>&2 "$PRG: This is probably bad but we'll ignore it."
870 [ "$VERBOSE" = 1 ] && echo "$PRG: Setting attributes on $BTFILE..."
871 hattrib -t "$BTTYPE" -c "$hfscreator" $INVISIBLE $LOCK :"$BTFILE"
872 if [ $? != 0 ] ; then
873 echo 1>&2 "$PRG: Warning: error setting attributes on $BTFILE"
874 echo 1>&2 "$PRG: This is probably bad but we'll ignore it"
877 [ "$VERBOSE" = 1 ] && echo "$PRG: Setting attributes on $CFFILE..."
878 hattrib -t "conf" -c "$hfscreator" $INVISIBLE $LOCK :"$CFFILE"
879 if [ $? != 0 ] ; then
880 echo 1>&2 "$PRG: Warning: error setting attributes on $CFFILE"
881 echo 1>&2 "$PRG: This is probably unimportant so we'll ignore it"
884 if [ -n "$BSDLOADER" ] ; then
885 [ "$VERBOSE" = 1 ] && echo "$PRG: Setting attributes on ofwboot..."
886 hattrib -t "bsdb" -c "$hfscreator" $INVISIBLE $LOCK :ofwboot
887 if [ $? != 0 ] ; then
888 echo 1>&2 "$PRG: Warning: error setting attributes on ofwboot"
889 echo 1>&2 "$PRG: This is probably unimportant so we'll ignore it"
893 ## bless the root directory so OF will find the boot file
894 if [ "$bless" = yes ] ; then
895 [ "$VERBOSE" = 1 ] && echo "$PRG: Blessing $boot with Holy Penguin Pee..."
897 if [ $? != 0 ] ; then
898 echo 1>&2 "$PRG: Warning: error blessing $boot"
899 echo 1>&2 "$PRG: This is probably bad but we'll ignore it"
903 ## clean up the ~/.hcwd file hmount creates
904 humount "$boot" > /dev/null
907 ## use explicit filename if we don't bless.
908 if [ "$bless" = yes ] ; then
909 local OFFILE='\\:tbxi'
911 if [ -n "$magicboot" ] ; then
912 local OFFILE=ofboot.b
914 local OFFILE="$BTFILE"
918 ## update the boot-device variable in OF nvram.
919 if [ "$nonvram" = 0 ] ; then
920 [ "$VERBOSE" = 1 ] && echo "$PRG: Updating OpenFirmware boot-device variable in nvram..."
921 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: boot-device=${ofboot},${OFFILE}"
922 nvsetenv boot-device "${ofboot},${OFFILE}"
923 if [ $? != 0 ] ; then
924 echo 1>&2 "$PRG: An error occured while updating nvram, we'll ignore it"
929 echo 1>&2 "$PRG: mtools support is not implemented"
930 echo 1>&2 "$PRG: Use --mount or add \`usemount' to $CONF"
937 ## used by mnt_install so mntpoint= can be supported in a cleaner way.
940 ## we can even create bootstrap filesystem images directly if you
942 if [ -f "$boot" ] ; then
946 if [ -e "$TMP/bootstrap.$$" ] ; then
947 echo 1>&2 "$PRG: $TMP/bootstrap.$$ exists, aborting."
951 mkdir -m 700 "$TMP/bootstrap.$$"
952 if [ $? != 0 ] ; then
953 echo 1>&2 "$PRG: Could not create mountpoint directory, aborting."
957 mount | grep "^$boot\>" > /dev/null
959 echo 1>&2 "$PRG: $boot appears to be mounted! aborting."
963 [ "$VERBOSE" = 1 ] && echo "$PRG: Mounting $boot..."
964 mount -t "$fstype" -o rw,umask=077$loop "$boot" "$TMP/bootstrap.$$"
965 if [ $? != 0 ] ; then
966 echo 1>&2 "$PRG: An error occured mounting $boot"
970 ## catch signals, set here to avoid umounting something we did not
971 ## mount. cleanup done by trap 0.
972 trap "umount $boot ; exit 129" 1
973 trap "echo 1>&2 $SIGINT ; umount $boot ; exit 130" 2
974 trap "umount $boot ; exit 131" 3
975 trap "umount $boot ; exit 143" 15
977 TARGET="$TMP/bootstrap.$$"
981 ## umnt funtion which checks whether we mounted anything or not, for
982 ## mntpoint= this makes the code below cleaner IMO.
985 if [ -z "$mntpoint" ] ; then
986 [ "$1" = failure ] && echo 1>&2 "$PRG: Attempting to umount $boot..."
988 if [ $? != 0 ] ; then
989 echo 1>&2 "$PRG: umount of $boot failed!"
992 [ "$1" = failure ] && echo 1>&2 "$PRG: umount successfull"
1000 ## Use kernel filesytem drivers to mount the bootstrap partition like
1001 ## any other filesystem and copy the files there with standard un*x
1007 ## msdosfs is broken, yaboot may not support this filename.
1008 if [ "$fstype" = msdos ] ; then
1009 local CFFILE=yaboot.cnf
1011 local CFFILE=yaboot.conf
1014 if [ -n "$magicboot" ] ; then
1015 local WRAP="${magicboot##*/}"
1018 ## set verbose messages here so they don't show temporary file paths
1019 local INSTALLFIRST="$PRG: Installing first stage bootstrap $magicboot onto $boot..."
1020 local INSTALLPRIMARY="$PRG: Installing primary bootstrap $install onto $boot..."
1022 ## repoint magicboot as the real first stage loader if using the
1023 ## modern automatic generating ofboot.b.
1024 if [ -n "$FIRST" ] ; then
1026 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: set magicboot to $FIRST"
1029 ## gross hack, add note section for IBM CHRP
1030 if [ "$ADDNOTE" = yes ] ; then
1031 hack_yaboot || return 1
1034 ## call mnt() function to take care of mounting filesystem if needed
1035 if [ -z "$mntpoint" ] ; then
1041 ## this is probably insecure on modern filesystems, but i think
1042 ## safe on crippled hfs/dosfs. user should ensure mntpoint= is safe.
1043 if [ -n "$magicboot" ] ; then
1044 [ "$VERBOSE" = 1 ] && echo "$INSTALLFIRST"
1045 cp -f "$magicboot" "$TARGET/ofboot.b"
1046 if [ $? != 0 ] ; then
1047 echo 1>&2 "$PRG: An error occured while writing to $boot"
1048 umnt failure "$TARGET"
1053 [ "$VERBOSE" = 1 ] && echo "$INSTALLPRIMARY"
1054 cp -f "$install" "$TARGET/$BTFILE"
1055 if [ $? != 0 ] ; then
1056 echo 1>&2 "$PRG: An error occured while writing to $boot"
1057 umnt failure "$TARGET"
1061 [ "$VERBOSE" = 1 ] && echo "$PRG: Installing $bootconf onto $boot..."
1062 cp -f "$bootconf" "$TARGET/$CFFILE"
1063 if [ $? != 0 ] ; then
1064 echo 1>&2 "$PRG: An error occured while writing to $boot"
1065 umnt failure "$TARGET"
1069 if [ -n "$BSDLOADER" ] ; then
1070 [ "$VERBOSE" = 1 ] && echo "$PRG: Installing $BSDLOADER onto $boot..."
1071 cp -f "$BSDLOADER" "$TARGET/ofwboot"
1072 if [ $? != 0 ] ; then
1073 echo 1>&2 "$PRG: An error occured while writing to $boot"
1074 umnt failure "$TARGET"
1079 if [ "$protect" = yes ] ; then
1080 [ "$VERBOSE" = 1 ] && echo "$PRG: Setting read-only attributes..."
1081 chmod a-w "$TARGET/$BTFILE"
1082 chmod a-w "$TARGET/$CFFILE"
1083 if [ -n "$magicboot" ] ; then
1084 chmod a-w "$TARGET/ofboot.b"
1086 if [ -n "$BSDLOADER" ] ; then
1087 chmod a-w "$TARGET/ofwboot"
1092 umnt success "$TARGET" || return 1
1094 ## make variable with a \ to avoid shell fsckage. ugly ugly ugly.
1096 if [ -n "$magicboot" ] ; then
1097 [ -n "$OFDIR" ] && OFDIR="${BS}${OFDIR}${BS}"
1098 local OFFILE="${OFDIR}ofboot.b"
1100 [ -n "$OFDIR" ] && OFDIR="${BS}${OFDIR}${BS}"
1101 local OFFILE="${OFDIR}${BTFILE}"
1104 ## update the boot-device variable in OF nvram.
1105 if [ "$nonvram" = 0 ] ; then
1106 [ "$VERBOSE" = 1 ] && echo "$PRG: Updating OpenFirmware boot-device variable in nvram..."
1107 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: boot-device=${ofboot},${OFFILE}"
1108 nvsetenv boot-device "${ofboot},${OFFILE}"
1109 if [ $? != 0 ] ; then
1110 echo 1>&2 "$PRG: An error occured while updating nvram, we'll ignore it"
1113 echo 1>&2 "$PRG: Warning: You must manually configure OpenFirmware to boot."
1119 ## raw installation, for IBM RS/6000 hardware, yaboot is dded to the
1120 ## bootstrap partition.
1123 ## make sure the device is not mounted as a filesystem before
1124 ## we start mucking with it directly.
1125 mount | grep "^$boot\>" > /dev/null
1126 if [ $? = 0 ] ; then
1127 echo 1>&2 "$PRG: $boot appears to be mounted! aborting."
1131 ## set verbosity message before munging the yaboot pathname
1132 local INSTALLPRIMARY="$PRG: Installing primary bootstrap $install onto $boot..."
1134 ## gross hack, add note section for IBM CHRP
1135 if [ "$ADDNOTE" = yes ] ; then
1136 hack_yaboot || return 1
1139 [ "$VERBOSE" = 1 ] && echo "$INSTALLPRIMARY"
1140 dd if=/dev/zero of="$boot" bs=512 count=1600 > /dev/null 2>&1
1141 dd if="$install" of="$boot" bs=512 > /dev/null 2>&1
1142 if [ $? != 0 ] ; then
1143 echo 1>&2 "$PRG: Installation failed."
1147 [ "$VERBOSE" = 1 ] && echo "$PRG: Installation successful"
1150 ## make sure the first stage ofboot generator is compatible.
1153 grep -q "^#%ybinscript-" "$magicboot" 2> /dev/null
1154 if [ "$?" = 0 ] ; then
1155 local magic=`grep "^#%ybinscript-" "$magicboot"`
1156 local ver="${magic##*-}"
1157 if [ "$ver" = "1.1" ] ; then
1161 echo 1>&2 "$PRG: Incompatible version of first stage loader $magicboot. aborting..."
1170 ## build the first stage loader.
1173 ## must have 7 backslashes to == \\ printf + shell = bizarre... or,
1174 ## make special variable to contain a \ (need \\ to make \) to work
1175 ## around echo -e -n brokeness.
1179 ## deal with mntpoint=
1180 [ -n "$OFDIR" ] && local OFDIR="${BS}${OFDIR}${BS}"
1182 ## some misguided people insist on installing OSX on
1183 ## HorribleFileSystem+ instead of UFS, as a result MacOS deblesses
1184 ## OSX, making it unbootable. if apple localizes the filesystem hierarchy again screw it.
1185 [ "$brokenosx" = yes ] && local OSXBOOT="${BS}System${BS}Library${BS}CoreServices${BS}BootX"
1186 [ "$brokenosx" = no ] && local OSXBOOT="${BS}${BS}:tbxi"
1188 ## assign variables for configured menu options.
1189 [ "$usemount" = no -a "$bless" = yes ] && local YB="yaboot GNU l $ofboot ,${BS}${BS}yaboot"
1190 [ "$usemount" = yes -o "$bless" = no ] && local YB="yaboot GNU l $ofboot ,${OFDIR}yaboot"
1191 [ -n "$bsd" ] && OS="$(($OS + 1))" && local BSD="ybsd BSD b $ofboot ,${BS}${BS}ofwboot/$bsd"
1192 [ -n "$macos" ] && OS="$(($OS + 1))" && local MAC="macos MacOS m $macos ,${BS}${BS}:tbxi"
1193 [ -n "$macosx" ] && OS="$(($OS + 1))" && local MX="macosx MacOSX x $macosx ,${OSXBOOT}"
1194 [ -n "$darwin" ] && OS="$(($OS + 1))" && local DW="darwin Darwin d $darwin ,${BS}${BS}:tbxi"
1195 [ "$cdrom" = yes ] && OS="$(($OS + 1))" && local CD="cd CDROM c cd: ,${BS}${BS}:tbxi"
1196 [ "$network" = yes ] && OS="$(($OS + 1))" && local NET="net Network n enet: 0"
1197 [ "$of" = yes ] && OS="$(($OS + 1))" && local OF="of OpenFirmware o quit now"
1198 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: OS=$OS"
1201 ## Usage: OS-count defaultos timeout fgc bgc osname oslabel oskey osdev osfile ...
1202 [ "$DEBUG" = 1 ] && $PRINTF 1>&2 "$PRG: DEBUG: /bin/sh $magicboot $OS $defaultos $delay $fbc $bgc $YB $BSD $MAC $MX $DW $CD $NET $OF\n"
1203 FIRST="$(/bin/sh "$magicboot" "$OS" "$defaultos" "$delay" $fgc $bgc ${YB} ${BSD} ${MAC} ${MX} ${DW} ${CD} ${NET} ${OF})" || return 1
1208 ## mkofboot function.
1211 mount | grep "^$boot\>" > /dev/null
1212 if [ $? = 0 ] ; then
1213 echo 1>&2 "$PRG: $boot appears to be mounted! aborting."
1219 [ "$VERBOSE" = 1 ] && echo "$PRG: Creating HFS filesystem on $boot..."
1220 if (command -v dd > /dev/null 2>&1) ; then
1221 dd if=/dev/zero of="$boot" bs=512 count=1600 > /dev/null 2>&1
1223 hformat -l bootstrap "$boot" > /dev/null
1224 if [ $? != 0 ] ; then
1225 echo 1>&2 "$PRG: HFS filesystem creation failed!"
1228 humount "$boot" ## otherwise we might get confused.
1232 if (command -v mkdosfs > /dev/null 2>&1) ; then
1233 [ -x `command -v mkdosfs` ] || FAIL=1 ; else FAIL=1 ; fi
1234 if [ "$FAIL" = 1 ] ; then
1235 echo 1>&2 "$PRG: mkdosfs is not installed or cannot be found"
1239 [ "$VERBOSE" = 1 ] && echo "$PRG: Creating DOS filesystem on $boot..."
1240 if (command -v dd > /dev/null 2>&1) ; then
1241 dd if=/dev/zero of="$boot" bs=512 count=1600 > /dev/null 2>&1
1243 mkdosfs -n bootstrap "$boot" > /dev/null
1244 if [ $? != 0 ] ; then
1245 echo 1>&2 "$PRG: DOS filesystem creation failed!"
1255 if [ "$FORCE" = yes ] ; then
1259 [ "$fstype" = raw ] && $PRINTF 1>&2 "$PRG: Overwrite contents of $boot with $install? [y/N] "
1260 [ "$fstype" != raw ] && $PRINTF 1>&2 "$PRG: Create $fstype filesystem on $boot? [y/N] "
1267 echo 1>&2 "$PRG: Abort."
1274 ## for fstype=raw check if an ELF binary has already been dded.
1277 if [ "$(dd if="$boot" bs=1 skip=1 count=3 2>/dev/null)" = ELF ] ; then
1280 echo 1>&2 "$PRG: This partition has never had yaboot installed before, please run mkofboot"
1287 ## defaults for this are defined at the beginning of the script with
1291 "## yaboot configuration file generated by ybin $VERSION
1298 partition=$partition
1301 " > "$TMPCONF" || return 1
1303 [ "$DEBUG" = 1 ] && $PRINTF 1>&2 "\nDEBUG: autoconf:\n----\n" && cat "$TMPCONF" 1>&2 && echo 1>&2 "----"
1307 ## take out the trash.
1310 if [ -n "$TMPCONF" ] ; then rm -f "$TMPCONF" ; fi
1311 if [ -n "$FIRST" ] ; then rm -f "$FIRST" ; fi
1312 if [ -n "$TMPYABOOT" ] ; then rm -f "$TMPYABOOT" ; fi
1313 if [ -d "$TMP/bootstrap.$$" -a "$usemount" = yes ] ; then rmdir "$TMP/bootstrap.$$" ; fi
1321 ## absurdly bloated case statement to parse command line options.
1322 if [ $# != 0 ] ; then
1346 if [ -n "$2" ] ; then
1351 echo 1>&2 "$PRG: option requires an argument $1"
1352 echo 1>&2 "Try \`$PRG --help' for more information."
1357 if [ -n "$2" ] ; then
1362 echo 1>&2 "$PRG: option requires an argument $1"
1363 echo 1>&2 "Try \`$PRG --help' for more information."
1368 if [ -n "$2" ] ; then
1373 echo 1>&2 "$PRG: option requires an argument $1"
1374 echo 1>&2 "Try \`$PRG --help' for more information."
1379 if [ -n "$2" ] ; then
1382 ERR=" Error in $CONF:"
1385 echo 1>&2 "$PRG: option requires an argument $1"
1386 echo 1>&2 "Try \`$PRG --help' for more information."
1391 if [ -n "$2" ] ; then
1396 echo 1>&2 "$PRG: option requires an argument $1"
1397 echo 1>&2 "Try \`$PRG --help' for more information."
1402 if [ -n "$2" ] ; then
1407 echo 1>&2 "$PRG: option requires an argument $1"
1408 echo 1>&2 "Try \`$PRG --help' for more information."
1438 if [ -n "$2" ] ; then
1441 echo 1>&2 "$PRG: WARNING: Deprecated option --device"
1444 echo 1>&2 "$PRG: option requires an argument $1"
1445 echo 1>&2 "Try \`$PRG --help' for more information."
1450 if [ -n "$2" ] ; then
1453 echo 1>&2 "$PRG: WARNING: Deprecated option --device"
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
1465 echo 1>&2 "$PRG: WARNING: Deprecated option --device"
1468 echo 1>&2 "$PRG: option requires an argument $1"
1469 echo 1>&2 "Try \`$PRG --help' for more information."
1474 if [ -n "$2" ] ; then
1477 echo 1>&2 "$PRG: WARNING: Deprecated option --device"
1480 echo 1>&2 "$PRG: option requires an argument $1"
1481 echo 1>&2 "Try \`$PRG --help' for more information."
1486 if [ -n "$2" ] ; then
1489 echo 1>&2 "$PRG: WARNING: Deprecated option --device"
1492 echo 1>&2 "$PRG: option requires an argument $1"
1493 echo 1>&2 "Try \`$PRG --help' for more information."
1498 if [ -n "$2" ] ; then
1501 echo 1>&2 "$PRG: WARNING: Deprecated option --device"
1504 echo 1>&2 "$PRG: option requires an argument $1"
1505 echo 1>&2 "Try \`$PRG --help' for more information."
1513 echo 1>&2 "$PRG: unrecognized option \`$1'"
1514 echo 1>&2 "Try \`$PRG --help' for more information."
1521 ## check that specified config file exists, unless its /dev/null in
1522 ## which case we assume all options are done on the command line.
1523 if [ "$CONF" = /dev/null ] ; then
1529 ## if there is no config file use the automatic generation to make a
1530 ## generic yaboot.conf. do this before the confcheck to avoid wierd errors.
1531 if [ "$bootconf" = /dev/null ] ; then
1532 if (command -v yabootconfig > /dev/null 2>&1) ; then
1533 echo 1>&2 "$PRG: Warning: no /etc/yaboot.conf, running yabootconfig to make one"
1534 yabootconfig --noinstall --quiet
1535 if [ $? != 0 ] ; then
1536 echo 1>&2 "$PRG: yabootconfig failed, please supply a valid /etc/yaboot.conf"
1537 echo 1>&2 "$PRG: You may also use $PRG's --boot, --image, --partition, and --device switches"
1538 echo 1>&2 "$PRG: These switches will cause $PRG to generate a basic yaboot.conf on the fly"
1541 CONF=/etc/yaboot.conf
1543 ERR=" Error in $CONF:"
1549 ## Checks if each option was defined on the command line, and if so
1550 ## don't read it from the configuration file. this avoids
1551 ## configuration options from being set null, as well as command line
1552 ## options from being clobbered.
1553 [ "$ARGBT" != 1 -a $(parseconf ck boot) = 0 ] && boot=`parseconf str boot`
1554 [ "$ARGOB" != 1 -a $(parseconf ck ofboot) = 0 ] && ofboot=`parseconf str ofboot`
1555 [ "$ARGBF" != 1 -a $(parseconf ck install) = 0 ] && install=`parseconf str install`
1556 [ "$ARGWP" != 1 -a $(parseconf ck magicboot) = 0 ] && magicboot=`parseconf str magicboot`
1557 [ "$ARGMT" != 1 -a $(parseconf flag usemount) = 0 ] && usemount=yes
1558 [ "$ARGFS" != 1 -a $(parseconf ck fstype) = 0 ] && fstype=`parseconf str fstype`
1559 [ "$ARGBS" != 1 -a $(parseconf flag nobless) = 0 ] && bless=no
1560 [ "$ARGPT" != 1 -a $(parseconf flag protect) = 0 ] && protect=yes
1561 [ "$ARGHD" != 1 -a $(parseconf flag hide) = 0 ] && hide=yes
1562 [ "$ARGNV" != 1 -a $(parseconf flag nonvram) = 0 ] && nonvram=1
1563 [ $(parseconf ck hfstype) = 0 ] && hfstype=`parseconf str hfstype`
1564 [ $(parseconf ck hfscreator) = 0 ] && hfscreator=`parseconf str hfscreator`
1565 [ $(parseconf ck mntpoint) = 0 ] && mntpoint=`parseconf str mntpoint`
1566 [ $(parseconf ck delay) = 0 ] && delay=`parseconf str delay`
1567 [ $(parseconf ck timeout) = 0 ] && timeout=`parseconf str timeout`
1568 [ $(parseconf ck bsd) = 0 ] && bsd=`parseconf str bsd`
1569 [ $(parseconf ck macos) = 0 ] && macos=`parseconf str macos`
1570 [ $(parseconf ck macosx) = 0 ] && macosx=`parseconf str macosx`
1571 [ $(parseconf ck darwin) = 0 ] && darwin=`parseconf str darwin`
1572 [ $(parseconf ck defaultos) = 0 ] && defaultos=`parseconf str defaultos`
1573 [ $(parseconf ck fgcolor) = 0 ] && fgcolor=`parseconf str fgcolor`
1574 [ $(parseconf ck bgcolor) = 0 ] && bgcolor=`parseconf str bgcolor`
1575 [ $(parseconf ck icon) = 0 ] && export YBINOFICON=`parseconf str icon`
1576 [ $(parseconf flag enablecdboot) = 0 ] && cdrom=yes
1577 [ $(parseconf flag enablenetboot) = 0 ] && network=yes
1578 [ $(parseconf flag enableofboot) = 0 ] && of=yes
1579 [ $(parseconf flag brokenosx) = 0 ] && brokenosx=yes
1581 ## ffs!! rtfm! foad!
1582 if [ "$boot" = unconfigured ] ; then
1583 echo 1>&2 "$PRG: You must specify the device for the bootstrap partition. (ie: boot=/dev/hdaX)"
1584 echo 1>&2 "$PRG: Try \`$PRG --help' for more information."
1588 ## if there is still no config file use the automatic generation to make a
1589 ## generic yaboot.conf. do this before the confcheck to avoid wierd errors.
1590 if [ "$bootconf" = /dev/null ] ; then
1591 echo 1>&2 "$PRG: Warning: no yaboot.conf, using generic configuration."
1595 ## mntpoint is incompatible with mkofboot.
1596 if [ "$PRG" = mkofboot -a -n "$mntpoint" ] ; then
1597 echo 1>&2 "$PRG: Cannot be used with \`mntpoint='"
1601 ## validate configuration for sanity.
1604 ## check that we can use ofpath, its only needed for magicboot script
1605 ## building and nvram updates.
1606 if [ -n "$magicboot" -o "$nonvram" = 0 ] ; then
1607 if [ -z "$ofboot" -o -n "$macos" -o -n "$macosx" -o -n "$darwin" ] ; then
1608 if (command -v ofpath > /dev/null 2>&1) ; then
1609 [ -x `command -v ofpath` ]
1610 if [ $? != 0 ] ; then
1611 echo 1>&2 "$PRG: ofpath could not be found, aborting."
1615 echo 1>&2 "$PRG: ofpath could not be found, aborting."
1621 ## if password is set in yaboot.conf make sure permissions on that
1622 ## file are safe, warn if not.
1623 if (grep -q '^[[:space:]]*password[[:space:]]*=' "$bootconf" > /dev/null 2>&1) ; then
1627 ## check if we are root if needed.
1628 if [ "$usemount" = yes -a -z "$mntpoint" ] ; then
1629 if [ `id -u` != 0 ] ; then
1630 echo 1>&2 "$PRG: \`usemount' requires root privileges, go away."
1635 if [ "$fstype" = hfs ] ; then
1637 if [ $? != 0 ] ; then
1638 echo 1>&2 "$PRG: hfsutils is not installed or cannot be found"
1639 echo 1>&2 "$PRG: Try --mount if `uname -sr` supports HFS"
1644 ## convert unix device nodes to OpenFirmware pathnames
1645 if [ -n "$magicboot" -o "$nonvram" = 0 ] ; then
1646 convertpath || exit 1
1649 ## yaboot.conf autogeneration. MUST have secure mktemp to
1650 ## avoid race conditions. Debian's mktemp qualifies.
1651 if [ "$bootconf" = auto ] ; then
1652 TMPCONF=`mktemp -q "$TMP/$PRG.XXXXXX"`
1653 if [ $? != 0 ] ; then
1654 echo 1>&2 "$PRG: Could not create temporary file, aborting."
1659 if [ $? != 0 ] ; then
1660 echo 1>&2 "$PRG: An error occured generating yaboot.conf, aborting."
1667 if [ -n "$magicboot" ] ; then
1668 checkfirststage || exit 1
1669 if [ "$FIRSTSTG" = compat ] ; then
1671 if [ $? != 0 ] ; then
1672 echo 1>&2 "$PRG: An error occured while building first stage loader. aborting..."
1682 if [ "$fstype" = raw ] ; then
1684 raw_install || exit 1
1686 util_install || exit 1
1691 mnt_install || exit 1
1699 ## its not nice to erase the partition and then bail!
1700 if [ "$fstype" = msdos ] ; then
1701 echo 1>&2 "$PRG: mtools support is not implemented"
1702 echo 1>&2 "$PRG: Use --mount or add \`usemount' to $CONF"
1706 if [ "$fstype" = raw ] ; then
1707 raw_install || exit 1
1710 util_install || exit 1
1712 [ "$VERBOSE" = 1 ] && echo "$PRG: Installation complete."
1718 mnt_install || exit 1
1719 [ "$VERBOSE" = 1 ] && echo "$PRG: Installation complete."