3 ###############################################################################
5 ## ybin (YaBoot INstaller) installs/updates the yaboot bootloader.
6 ## Copyright (C) 2000, 2001 Ethan Benson
8 ## This program is free software; you can redistribute it and/or
9 ## modify it under the terms of the GNU General Public License
10 ## as published by the Free Software Foundation; either version 2
11 ## of the License, or (at your option) any later version.
13 ## This program is distributed in the hope that it will be useful,
14 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ## GNU General Public License for more details.
18 ## You should have received a copy of the GNU General Public License
19 ## along with this program; if not, write to the Free Software
20 ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 ###############################################################################
24 PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin"
25 ## allow to run out of /target in boot-floppies
26 if [ -n "$PATH_PREFIX" ] ; then
27 PATH="${PATH}:${PATH_PREFIX}/sbin:${PATH_PREFIX}/bin:${PATH_PREFIX}/usr/sbin:${PATH_PREFIX}/usr/bin:${PATH_PREFIX}/usr/local/sbin:${PATH_PREFIX}/usr/local/bin"
30 SIGINT="$PRG: Interrupt caught ... exiting"
31 VERSION=1.3.7-UNSUPPORTED_DEVEL_BRANCH
37 ## catch signals, clean up junk in /tmp.
40 trap "echo 1>&2 $SIGINT ; exit 130" 2
44 ## allow for non-existent config file, in which case it will be
45 ## generated from command line arguments.
46 if [ -f /etc/yaboot.conf ] ; then
49 ERR=" Error in $CONF:"
55 ## define default configuration
58 ## allow default to work on packaged and non-packaged yaboot.
59 ## no default for magicboot since it is not required everywhere.
60 if [ -f /usr/local/lib/yaboot/yaboot ] ; then
61 install=/usr/local/lib/yaboot/yaboot
62 elif [ -f /usr/lib/yaboot/yaboot ] ; then
63 install=/usr/lib/yaboot/yaboot
68 if (cat /proc/cpuinfo 2> /dev/null | grep ^machine | grep -q 'CHRP IBM') ; then
87 ## yaboot autoconf defaults
95 ## this program behaves differently based on how its called, this
96 ## ensures that nothing nasty happens if someone makes a bogus
104 echo 1>&2 "This program must be called as either \`ybin' or \`mkofboot'"
109 ## check for printf, use it if possible otherwise fall back on
110 ## unreliable echo -e -n ("SUS" says echo shall support no switches)
111 if [ "$(printf printf_test 2>/dev/null)" = printf_test ] ; then
117 ## make fake `id' if its missing, outputs 0 since if its missing we
118 ## are probably running on boot floppies and thus are root.
119 if (command -v id > /dev/null 2>&1) ; then
133 Written by Ethan Benson
135 Copyright (C) 2000, 2001 Ethan Benson
136 This is free software; see the source for copying conditions. There is NO
137 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
144 "Usage: $PRG [OPTION]...
145 Update/install bootloader onto a bootstrap partition.
147 -b, --boot set bootstrap partition device [ -b /dev/hda2 ]
148 -o, --ofboot set bootstrap partition OpenFirmware device
149 default: automatically determined [ -o hd:2 ]
150 -i, --install pathname to the actual bootloader binary
151 default: /usr/{local/}lib/yaboot/yaboot same as
152 install= in config file [ -i bootloader_file ]
153 -C, --config use alternate configuration file (ybin and yaboot)
155 -m, --magicboot pathname to a OpenFirmware magicboot (CHRP) script
156 --filesystem set the filesystem type of the bootstrap partition
157 available options are hfs, msdos, and raw
158 [ --filesystem hfs ] default is hfs
159 --nobless don't bless the root directory, this should only
160 be used if you are using a MacOS boot partition
161 as the bootstrap partition (not recommended)
162 -M, --mount don't use userspace hfsutils to modify the
163 bootstrap instead try and mount the filesystem
164 directly. Note that attributes cannot be set
165 this way and you will have to manually modify
166 OpenFirmware to make your system bootable
167 --protect set the read-only (locked) bit on all bootstrap
169 --hide set the invisible bit on all bootstrap files
170 this is useful of you don't want them to be
172 --nonvram do not update the boot-device variable in nvram.
173 --force don't ever ask for confirmation
174 -v, --verbose make $PRG more verbose
175 --debug print boring junk only useful for debugging
176 -h, --help display this help and exit
177 -V, --version output version information and exit"
180 ## configuration file parsing. FIXME: need a method which can parse
186 v=`grep "^$2[\ ,=]" "$CONF"` ; echo "${v#*=}"
189 grep "^$2\>" "$CONF" > /dev/null && echo 0 || echo 1
192 grep "^$2[\ ,=]" "$CONF" > /dev/null && echo 0 || echo 1
197 ## check for existence of a configuration file, and make sure we have
201 if [ ! -e "$CONF" ] ; then
202 echo 1>&2 "$PRG: $CONF: No such file or directory"
204 elif [ ! -f "$CONF" ] ; then
205 echo 1>&2 "$PRG: $CONF: Not a regular file"
207 elif [ ! -r "$CONF" ] ; then
208 echo 1>&2 "$PRG: $CONF: Permission denied"
215 ## check to make sure the configuration file is sane and correct.
216 ## maybe this is an insane ammount of error checking, but I want to
217 ## make sure (hopfully) nothing unexpected ever happens. and i just
218 ## like useful errors from programs. every error just marks an error
219 ## variable so we give the user as much info as possible before we
223 if [ ! -e "$boot" ] ; then
224 echo 1>&2 "$PRG: $boot: No such file or directory"
226 elif [ ! -b "$boot" -a ! -f "$boot" ] ; then
227 echo 1>&2 "$PRG: $boot: Not a regular file or block device"
229 elif [ ! -w "$boot" -o ! -r "$boot" ] ; then
230 [ -z "$mntpoint" ] && echo 1>&2 "$PRG: $boot: Permission denied"
231 [ -z "$mntpoint" ] && CONFERR=1
234 if [ ! -e "$install" ] ; then
235 echo 1>&2 "$PRG: $install: No such file or directory"
237 elif [ ! -f "$install" ] ; then
238 echo 1>&2 "$PRG: $bootconf: Not a regular file"
240 elif [ ! -r "$install" ] ; then
241 echo 1>&2 "$PRG: $install: Permission denied"
245 if [ "$bootconf" = auto ] ; then
247 elif [ ! -e "$bootconf" ] ; then
248 echo 1>&2 "$PRG: $bootconf: No such file or directory"
250 elif [ ! -f "$bootconf" ] ; then
251 echo 1>&2 "$PRG: $bootconf: Not a regular file"
253 elif [ ! -r "$bootconf" ] ; then
254 echo 1>&2 "$PRG: $bootconf: Permission denied"
258 if [ -n "$magicboot" ] ; then
259 if [ ! -e "$magicboot" ] ; then
260 echo 1>&2 "$PRG: $magicboot: No such file or directory"
262 elif [ ! -f "$magicboot" ] ; then
263 echo 1>&2 "$PRG: $magicboot: Not a regular file"
265 elif [ ! -r "$magicboot" ] ; then
266 echo 1>&2 "$PRG: $magicboot: Permission denied"
275 if [ "$ARGFS" = 1 ] ; then
276 echo 1>&2 "$PRG: --filesystem must be either \`hfs', \`msdos', or \`raw'"
278 echo 1>&2 "$PRG:$ERR \`fstype' must be either \`hfs', \`msdos', or \`raw'"
284 ## if we are not using HFS filesystems we don't care about HFS
286 if [ "$fstype" = hfs ] ; then
287 if [ `echo ${#hfstype}` != 4 ] ; then
288 if [ "$ARGTP" = 1 ] ; then
289 echo 1>&2 "$PRG: --type must be 4 characters"
291 echo 1>&2 "$PRG:$ERR \`hfstype' must be 4 characters"
296 if [ `echo ${#hfscreator}` != 4 ] ; then
297 if [ "$ARGCT" = 1 ] ; then
298 echo 1>&2 "$PRG: --creator must be 4 characters"
300 echo 1>&2 "$PRG:$ERR \`hfscreator' must be 4 characters"
306 ## some options are not compatible with fstype=raw
307 if [ "$fstype" = raw ] ; then
308 if [ -n "$mntpoint" ] ; then
309 echo 1>&2 "$PRG:$ERR \`mntpoint' is not compatible with fstype=raw"
312 if [ "$usemount" = yes ] ; then
313 echo 1>&2 "$PRG:$ERR \`usemount' is not compatible with fstype=raw"
316 if [ -n "$magicboot" ] ; then
317 echo 1>&2 "$PRG:$ERR \`magicboot' scripts cannot be used with fstype=raw"
322 if [ -n "$mntpoint" ] ; then
324 if [ ! -e "$mntpoint" ] ; then
325 echo 1>&2 "$PRG: $mntpoint: No such file or directory"
327 elif [ ! -d "$mntpoint" ] ; then
328 echo 1>&2 "$PRG: $mntpoint: Not a directory"
330 elif [ ! -w "$mntpoint" -o ! -r "$mntpoint" ] ; then
331 echo 1>&2 "$PRG: $mntpoint: Permission denied"
333 elif [ ! -O "$mntpoint" -a `id -u` != 0 ] ; then
334 echo 1>&2 "$PRG: $mntpoint: Permission denied (not owner)"
338 ## make sure no embedded spaces exist
339 echo "$mntpoint" | grep -q [[:space:]]
341 echo 1>&2 "$PRG:$ERR \`mntpoint=$mntpoint' contains embedded spaces, don't use lame filenames"
345 ## make sure $mntpoint is on $boot, this matters to nvram updating.
346 if [ "$(v=`df "$mntpoint" 2> /dev/null | grep ^/dev/` ; echo ${v%%[ ]*})" != "$boot" -a -d "$mntpoint" ] ; then
347 echo 1>&2 "$PRG: $mntpoint is not located on $boot"
349 ## more then one subdirectory deep is not supported. no sed available on boot floppies ( / -> \ )
350 elif [ "$mntpoint" != "$(v=`df "$mntpoint" 2> /dev/null | grep ^/dev/` ; echo ${v##*[ ]})" ] ; then
351 echo "$(v=`df "$mntpoint" 2>/dev/null | grep ^/dev/`; m=${v##*[ ]}; echo "${mntpoint##*$m/}")" | grep -q /
353 echo 1>&2 "$PRG:$ERR $mntpoint is more then one subdirectory deep from root of $boot"
356 OFDIR="$(v=`df "$mntpoint" 2>/dev/null | grep ^/dev/`; m=${v##*[ ]}; echo "${mntpoint##*$m/}")"
360 if [ "$usemount" = no ] ; then
361 echo 1>&2 "$PRG:$ERR \`mntpoint=' requires \`usemount' be set"
366 if [ -n "$magicboot" ] ; then
367 ## check for bsd loader
368 if [ -n "$bsd" ] ; then
369 if [ -f /usr/lib/yaboot/ofwboot -a -r /usr/lib/yaboot/ofwboot ] ; then
370 BSDLOADER="/usr/lib/yaboot/ofwboot"
371 elif [ -f /usr/local/lib/yaboot/ofwboot -a -r /usr/local/lib/yaboot/ofwboot ] ; then
372 BSDLOADER="/usr/local/lib/yaboot/ofwboot"
374 echo 1>&2 "$PRG: /usr/local/lib/yaboot/ofwboot: No such file or directory"
375 echo 1>&2 "$PRG: With the bsd= option set you must have the bsd boot loader ofwboot"
380 ## convert defaultos variable
382 linux|Linux|GNU|Gnu|gnu)
389 if [ -z "$bsd" ] ; then
390 echo 1>&2 "$PRG:$ERR no entry for \`bsd' found, but defaultos is set to \`bsd'"
396 if [ -z "$macos" ] ; then
397 echo 1>&2 "$PRG:$ERR no entry for \`macos' found, but defaultos is set to \`macos'"
403 if [ -z "$macosx" ] ; then
404 echo 1>&2 "$PRG:$ERR no entry for \`macosx' found, but defaultos is set to \`macosx'"
410 if [ -z "$darwin" ] ; then
411 echo 1>&2 "$PRG:$ERR no entry for \`darwin' found, but defaultos is set to \`darwin'"
416 echo 1>&2 "$PRG:$ERR \`defaultos' must be either \`linux', \`bsd', \`macos' or \`macosx'"
422 ## nvsetenv requires /proc
423 if [ ! -f /proc/uptime -a "$nonvram" = 0 ] ; then
424 echo 1>&2 "$PRG: /proc filesystem is not mounted, nvram will not be updated"
428 if [ "$nonvram" = 0 ] ; then
429 ## see if nvsetenv exists and is executable
430 if (command -v nvsetenv > /dev/null 2>&1) ; then
431 [ -x `command -v nvsetenv` ] || MISSING=1 ; else MISSING=1
434 if [ "$nonvram" = 0 ] ; then
435 ## if nvsetenv exists see if its the old broken version
436 if [ "$MISSING" != 1 ] ; then
437 nvsetenv --version > /dev/null 2>&1 || OLD=1
440 echo 1>&2 "$PRG: Warning: \`nvsetenv' could not be found, nvram will not be updated"
443 if [ "$OLD" = 1 ] ; then
444 ## i check this myself to avoid misleading error
445 ## messages. nvsetenv should REALLY support --version.
446 if [ ! -e /dev/nvram ] ; then
447 echo 1>&2 "$PRG: /dev/nvram: No such file or directory"
448 echo 1>&2 "$PRG: Warning: nvram will not be updated"
450 elif [ ! -c /dev/nvram ] ; then
451 echo 1>&2 "$PRG: /dev/nvram: Not a character device"
452 echo 1>&2 "$PRG: Warning: nvram will not be updated"
454 elif [ ! -w /dev/nvram -o ! -r /dev/nvram ] ; then
455 echo 1>&2 "$PRG: /dev/nvram: Permission denied"
456 echo 1>&2 "$PRG: Warning: nvram will not be updated"
460 echo 1>&2 "$PRG: Warning: Incompatible version of \`nvsetenv', nvram will not be updated"
465 if [ -f "$boot" ] ; then
466 echo 1>&2 "$PRG: $boot is a regular file, disabling nvram updating"
471 ## check for newworld mac. use cat hack due to /proc wierdness.
472 ## do not bail if we are on an OldWorld only warn (very loudly).
473 if [ "$(v=`cat /proc/cpuinfo 2>/dev/null | grep pmac-generation` ; echo ${v##*:})" = NewWorld ] ; then
475 elif [ "$(v=`cat /proc/cpuinfo 2>/dev/null | grep pmac-generation` ; echo ${v##*:})" = OldWorld ] ; then
477 echo 1>&2 '@@@@@@@@@@@@@@ WARNING!! WARNING!! WARNING!! @@@@@@@@@@@@@@'
478 echo 1>&2 "$PRG: Warning: This is an OldWorld PowerMac, $boot will **NOT** be bootable on this machine"
479 echo 1>&2 "$PRG: Oldworld PowerMacs need to use the quik bootloader, not yaboot"
480 echo 1>&2 '@@@@@@@@@@@@@@ WARNING!! WARNING!! WARNING!! @@@@@@@@@@@@@@'
482 [ "$nonvram" = 0 ] && echo 1>&2 "$PRG: OldWorld PowerMac, nvram will not be updated"
484 elif (cat /proc/cpuinfo 2>/dev/null | grep ^motherboard | grep -q AAPL) ; then
486 echo 1>&2 '@@@@@@@@@@@@@@ WARNING!! WARNING!! WARNING!! @@@@@@@@@@@@@@'
487 echo 1>&2 "$PRG: Warning: This is an OldWorld PowerMac, $boot will **NOT** be bootable on this machine"
488 echo 1>&2 "$PRG: Oldworld PowerMacs need to use the quik bootloader, not yaboot"
489 echo 1>&2 '@@@@@@@@@@@@@@ WARNING!! WARNING!! WARNING!! @@@@@@@@@@@@@@'
491 [ "$nonvram" = 0 ] && echo 1>&2 "$PRG: OldWorld PowerMac, nvram will not be updated"
493 elif (cat /proc/cpuinfo 2> /dev/null | grep ^machine | grep -q 'CHRP IBM') ; then
494 ## IBM hardware does not need nvram update AFAICT
498 #echo 1>&2 "$PRG: Warning: Unknown archetecture, $boot may not be bootable on this machine"
499 [ "$nonvram" = 0 ] && echo 1>&2 "$PRG: Warning: Unknown architecture, nvram will not be updated"
503 ## convert human readable color values from config to proper color
506 black) fgc=0 ;; blue) fgc=1 ;; green) fgc=2 ;; cyan) fgc=3 ;;
507 red) fgc=4 ;; purple) fgc=5 ;; brown) fgc=6 ;; light-gray) fgc=7 ;;
508 dark-gray) fgc=8 ;; light-blue) fgc=9 ;; light-green) fgc=a ;;
509 light-cyan) fgc=b ;; light-red) fgc=c ;; light-purple) fgc=d ;;
510 yellow) fgc=e ;; white) fgc=f ;;
512 echo 1>&2 "$PRG:$ERR Invalid fgcolor: \`$fgcolor'"
517 black) bgc=0 ;; blue) bgc=1 ;; green) bgc=2 ;; cyan) bgc=3 ;;
518 red) bgc=4 ;; purple) bgc=5 ;; brown) bgc=6 ;; light-gray) bgc=7 ;;
519 dark-gray) bgc=8 ;; light-blue) bgc=9 ;; light-green) bgc=a ;;
520 light-cyan) bgc=b ;; light-red) bgc=c ;; light-purple) bgc=d ;;
521 yellow) bgc=e ;; white) bgc=f ;;
523 echo 1>&2 "$PRG:$ERR Invalid bgcolor: \`$bgcolor'"
528 ## if delay is not set use yaboot's timeout
529 if [ -z "$delay" ] ; then
530 delay="$(($timeout / 10))"
533 if [ "$CONFERR" = 1 ] ; then
541 ## if readlink is missing use a kludge
542 if (command -v readlink > /dev/null 2>&1) ; then
547 SYMTARGET="$(v=`ls -l "$2" 2>/dev/null` ; echo ${v##*> })"
548 if [ -n "$SYMTARGET" ] ; then
557 ## /etc/yaboot.conf with password should not be world readable.
560 if [ -L "$bootconf" ] ; then
561 local realfile="$(readlink -f "$bootconf")" || return 0
563 local realfile="$bootconf"
566 ## don't bother if we could not read the symlink
567 [ -z "$realfile" ] && return 0
568 [ ! -f "$realfile" ] && return 0
570 ## get permissions, and don't bother checking if we can't
571 local PERM=`v=$(ls -l "$realfile" 2>/dev/null) ; echo ${v%% *}`
572 [ -z "$PERM" ] && return 0
573 [ `echo ${#PERM}` != 10 ] && return 0
576 -rw-------|-r--------)
577 if [ ! -O "$realfile" -a `id -u` = 0 ] ; then
578 echo 1>&2 "$PRG: Warning: $bootconf is not owned by root"
581 -rw-r-----|-r--r-----)
582 if [ ! -O "$realfile" -a `id -u` = 0 ] ; then
583 echo 1>&2 "$PRG: Warning: $bootconf is not owned by root"
585 if [ ! -G "$realfile" -a `id -g` = 0 ] ; then
586 echo 1>&2 "$PRG: Warning: $bootconf is not owned by group root"
589 -r--r--r--|-rw-r--r--|-rw-rw-r--|-rw-rw-rw-|-rw-rw----)
590 echo 1>&2 "$PRG: Warning: Insecure permissions on $bootconf: $PERM should be -rw-------"
593 echo 1>&2 "$PRG: Warning: Incorrect permissions on $bootconf: $PERM should be -rw-------"
600 ## figure out bootstrap device OF pathname if user did not supply it.
601 if [ -z "$ofboot" ] ; then
602 [ "$VERBOSE" = 1 ] && echo "$PRG: Finding OpenFirmware device path to \`$boot'..."
603 ofboot="$(ofpath $boot)"
604 if [ $? != 0 ] ; then
605 echo 1>&2 "$PRG: Unable to find OpenFirmware path for boot=$boot"
606 echo 1>&2 "$PRG: Please add ofboot=<path> where <path> is the OpenFirmware path to $boot to $CONF"
609 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: ofboot set to \`$ofboot'"
612 ## figure out OF device path for macos/macosx if user supplied a unix device node.
613 if [ -n "$bsd" ] ; then
616 [ "$VERBOSE" = 1 ] && echo "$PRG: Finding OpenFirmware device path to \`$bsd'..."
619 if [ $? != 0 ] ; then
620 echo 1>&2 "$PRG: Unable to determine OpenFirmware path for bsd=$sbsd"
621 echo 1>&2 "$PRG: Try specifying the real OpenFirmware path for bsd=$sbsd in $CONF"
624 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: bsd set to \`$bsd' from \`$sbsd'"
627 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: bsd left alone: \`$bsd'"
632 if [ -n "$macos" ] ; then
635 [ "$VERBOSE" = 1 ] && echo "$PRG: Finding OpenFirmware device path to \`$macos'..."
636 local smacos="$macos"
637 macos="$(ofpath $macos)"
638 if [ $? != 0 ] ; then
639 echo 1>&2 "$PRG: Unable to determine OpenFirmware path for macos=$smacos"
640 echo 1>&2 "$PRG: Try specifying the real OpenFirmware path for macos=$smacos in $CONF"
643 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: macos set to \`$macos' from \`$smacos'"
646 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: macos left alone: \`$macos'"
651 if [ -n "$macosx" ] ; then
654 [ "$VERBOSE" = 1 ] && echo "$PRG: Finding OpenFirmware device path to \`$macosx'..."
655 local smacosx="$macosx"
656 macosx="$(ofpath $macosx)"
657 if [ $? != 0 ] ; then
658 echo 1>&2 "$PRG: Unable to determine OpenFirmware path for macosx=$smacosx"
659 echo 1>&2 "$PRG: Try specifying the real OpenFirmware path for macosx=$smacosx in $CONF"
662 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: macosx set to \`$macosx' from \`$smacosx'"
665 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: macosx left alone: \`$macosx'"
670 if [ -n "$darwin" ] ; then
673 [ "$VERBOSE" = 1 ] && echo "$PRG: Finding OpenFirmware device path to \`$darwin'..."
674 local sdarwin="$darwin"
675 darwin="$(ofpath $darwin)"
676 if [ $? != 0 ] ; then
677 echo 1>&2 "$PRG: Unable to determine OpenFirmware path for darwin=$sdarwin"
678 echo 1>&2 "$PRG: Try specifying the real OpenFirmware path for darwin=$sdarwin in $CONF"
681 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: darwin set to \`$darwin' from \`$sdarwin'"
684 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: darwin left alone: \`$darwin'"
689 if [ "$CONVERR" = 1 ] ; then
696 ## make sure the hfsutils we need are installed and executable.
699 if (command -v hmount > /dev/null 2>&1) ; then
700 [ -x `command -v hmount` ] || FAIL=1 ; else FAIL=1 ; fi
701 if (command -v humount > /dev/null 2>&1) ; then
702 [ -x `command -v humount` ] || FAIL=1 ; else FAIL=1 ; fi
703 if (command -v hcopy > /dev/null 2>&1) ; then
704 [ -x `command -v hcopy` ] || FAIL=1 ; else FAIL=1 ; fi
705 if (command -v hattrib > /dev/null 2>&1) ; then
706 [ -x `command -v hattrib` ] || FAIL=1 ; else FAIL=1 ; fi
707 if (command -v hformat > /dev/null 2>&1) ; then
708 [ -x `command -v hformat` ] || FAIL=1 ; else FAIL=1 ; fi
710 if [ "$FAIL" = 1 ] ; then
717 ## This is gross, IBM CHRP OF needs a .note added to the yaboot
718 ## binary, nobody knows whether this note will affect PowerMac OF or
719 ## not (or could in the future).
722 local YBDIR="${install%/*}"
723 if [ -x "$YBDIR/addnote" ] ; then
724 TMPYABOOT=`mktemp -q "$TMP/yaboot.XXXXXX"`
725 if [ $? != 0 ] ; then
726 echo 1>&2 "$PRG: Could not create temporary file, aborting."
729 if (cat "$install" > "$TMPYABOOT" 2> /dev/null) ; then
732 echo 1>&2 "$PRG: Could not create temporary file, aborting."
736 [ "$DEBUG" = 1 ] && echo "$PRG: Embedding CHRP note section in temp yaboot..."
737 "$YBDIR/addnote" "$install" > /dev/null 2>&1
738 if [ $? != 0 ] ; then
739 echo 1>&2 "$PRG: Could not install note section required by your architecture"
743 echo 1>&2 "$PRG: Your architecture requires $YBDIR/addnote which cannot be found"
749 ## install using userspace utilities rather then kernel filesytem
750 ## support. hfsutils only, mtools not supported.
753 ## catch signals, and humount, cleanup done by trap 0.
754 trap "humount $boot ; exit 129" 1
755 trap "echo 1>&2 $SIGINT ; humount $boot ; exit 130" 2
756 trap "humount $boot ; exit 131" 3
757 trap "humount $boot ; exit 143" 15
759 ## filenames on bootstrap partition. ofboot hard codes yaboot.
761 local CFFILE=yaboot.conf
763 ## if there is a magicboot script to install we will give it the
764 ## hfstype (should be "tbxi") and give yaboot type "boot".
765 if [ -n "$magicboot" ] ; then
768 local BTTYPE="$hfstype"
771 if [ -n "$magicboot" ] ; then
772 local WRAP="${magicboot##*/}"
775 ## set verbose messages here so they don't show temporary file paths
776 local INSTALLFIRST="$PRG: Installing first stage bootstrap $magicboot onto $boot..."
777 local INSTALLPRIMARY="$PRG: Installing primary bootstrap $install onto $boot..."
779 ## repoint magicboot as the real first stage loader if using the
780 ## modern automatic generating ofboot.b.
781 if [ -n "$FIRST" ] ; then
783 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: set magicboot to $FIRST"
786 ## gross hack, add note section for IBM CHRP
787 if [ "$ADDNOTE" = yes ] ; then
788 hack_yaboot || return 1
791 if [ "$fstype" = hfs ] ; then
792 if [ "$protect" = yes ] ; then
796 if [ "$hide" = yes ] ; then
800 ## make sure the device is not mounted as a filesystem before
801 ## we start mucking with it directly.
802 mount | grep "^$boot\>" > /dev/null
804 echo 1>&2 "$PRG: $boot appears to be mounted! aborting."
808 ## hmount is really more of a way to make sure we have a valid HFS
809 ## filesystem before proceding, and hcopy requires it...
810 hmount "$boot" > /dev/null
811 if [ $? != 0 ] ; then
812 echo 1>&2 "$PRG: $boot appears to have never had a bootstrap installed, please run mkofboot"
816 ## must be explicit with target filename to avoid hfsutils
817 ## braindamage ("_" -> " " filename mangling) also avoid
818 ## ambiguity in the bootstrap partition.
819 if [ -n "$magicboot" ] ; then
820 [ "$VERBOSE" = 1 ] && echo "$INSTALLFIRST"
821 hcopy -r "$magicboot" :ofboot.b
822 if [ $? != 0 ] ; then
823 echo 1>&2 "$PRG: An error occured while writing to $boot"
828 [ "$VERBOSE" = 1 ] && echo "$INSTALLPRIMARY"
829 hcopy -r "$install" :"$BTFILE"
830 if [ $? != 0 ] ; then
831 echo 1>&2 "$PRG: An error occured while writing to $boot"
835 [ "$VERBOSE" = 1 ] && echo "$PRG: Installing $bootconf onto $boot..."
836 hcopy -r "$bootconf" :"$CFFILE"
837 if [ $? != 0 ] ; then
838 echo 1>&2 "$PRG: An error occured while writing to $boot"
842 if [ -n "$BSDLOADER" ] ; then
843 [ "$VERBOSE" = 1 ] && echo "$PRG: Installing $BSDLOADER onto $boot..."
844 hcopy -r "$BSDLOADER" :ofwboot
845 if [ $? != 0 ] ; then
846 echo 1>&2 "$PRG: An error occured while writing to $boot"
851 ## set all file's attributes, if a magicboot script exists it
852 ## gets the configured hfstype instead of yaboot (should be
853 ## "tbxi") so it gets booted by OF.
854 if [ -n "$magicboot" ] ; then
855 [ "$VERBOSE" = 1 ] && echo "$PRG: Setting attributes on $WRAP..."
856 hattrib -t "$hfstype" -c "$hfscreator" $INVISIBLE $LOCK :ofboot.b
857 if [ $? != 0 ] ; then
858 echo 1>&2 "$PRG: Warning: error setting attributes on $WRAP"
859 echo 1>&2 "$PRG: This is probably bad but we'll ignore it."
863 [ "$VERBOSE" = 1 ] && echo "$PRG: Setting attributes on $BTFILE..."
864 hattrib -t "$BTTYPE" -c "$hfscreator" $INVISIBLE $LOCK :"$BTFILE"
865 if [ $? != 0 ] ; then
866 echo 1>&2 "$PRG: Warning: error setting attributes on $BTFILE"
867 echo 1>&2 "$PRG: This is probably bad but we'll ignore it"
870 [ "$VERBOSE" = 1 ] && echo "$PRG: Setting attributes on $CFFILE..."
871 hattrib -t "conf" -c "$hfscreator" $INVISIBLE $LOCK :"$CFFILE"
872 if [ $? != 0 ] ; then
873 echo 1>&2 "$PRG: Warning: error setting attributes on $CFFILE"
874 echo 1>&2 "$PRG: This is probably unimportant so we'll ignore it"
877 if [ -n "$BSDLOADER" ] ; then
878 [ "$VERBOSE" = 1 ] && echo "$PRG: Setting attributes on ofwboot..."
879 hattrib -t "bsdb" -c "$hfscreator" $INVISIBLE $LOCK :ofwboot
880 if [ $? != 0 ] ; then
881 echo 1>&2 "$PRG: Warning: error setting attributes on ofwboot"
882 echo 1>&2 "$PRG: This is probably unimportant so we'll ignore it"
886 ## bless the root directory so OF will find the boot file
887 if [ "$bless" = yes ] ; then
888 [ "$VERBOSE" = 1 ] && echo "$PRG: Blessing $boot with Holy Penguin Pee..."
890 if [ $? != 0 ] ; then
891 echo 1>&2 "$PRG: Warning: error blessing $boot"
892 echo 1>&2 "$PRG: This is probably bad but we'll ignore it"
896 ## clean up the ~/.hcwd file hmount creates
897 humount "$boot" > /dev/null
900 ## use explicit filename if we don't bless.
901 if [ "$bless" = yes ] ; then
902 local OFFILE='\\:tbxi'
904 if [ -n "$magicboot" ] ; then
905 local OFFILE=ofboot.b
907 local OFFILE="$BTFILE"
911 ## update the boot-device variable in OF nvram.
912 if [ "$nonvram" = 0 ] ; then
913 [ "$VERBOSE" = 1 ] && echo "$PRG: Updating OpenFirmware boot-device variable in nvram..."
914 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: boot-device=${ofboot},${OFFILE}"
915 nvsetenv boot-device "${ofboot},${OFFILE}"
916 if [ $? != 0 ] ; then
917 echo 1>&2 "$PRG: An error occured while updating nvram, we'll ignore it"
922 echo 1>&2 "$PRG: mtools support is not implemented"
923 echo 1>&2 "$PRG: Use --mount or add \`usemount' to $CONF"
930 ## used by mnt_install so mntpoint= can be supported in a cleaner way.
933 ## we can even create bootstrap filesystem images directly if you
935 if [ -f "$boot" ] ; then
939 if [ -e "$TMP/bootstrap.$$" ] ; then
940 echo 1>&2 "$PRG: $TMP/bootstrap.$$ exists, aborting."
944 mkdir -m 700 "$TMP/bootstrap.$$"
945 if [ $? != 0 ] ; then
946 echo 1>&2 "$PRG: Could not create mountpoint directory, aborting."
950 mount | grep "^$boot\>" > /dev/null
952 echo 1>&2 "$PRG: $boot appears to be mounted! aborting."
956 [ "$VERBOSE" = 1 ] && echo "$PRG: Mounting $boot..."
957 mount -t "$fstype" -o rw,umask=077$loop "$boot" "$TMP/bootstrap.$$"
958 if [ $? != 0 ] ; then
959 echo 1>&2 "$PRG: An error occured mounting $boot"
963 ## catch signals, set here to avoid umounting something we did not
964 ## mount. cleanup done by trap 0.
965 trap "umount $boot ; exit 129" 1
966 trap "echo 1>&2 $SIGINT ; umount $boot ; exit 130" 2
967 trap "umount $boot ; exit 131" 3
968 trap "umount $boot ; exit 143" 15
970 TARGET="$TMP/bootstrap.$$"
974 ## umnt funtion which checks whether we mounted anything or not, for
975 ## mntpoint= this makes the code below cleaner IMO.
978 if [ -z "$mntpoint" ] ; then
979 [ "$1" = failure ] && echo 1>&2 "$PRG: Attempting to umount $boot..."
981 if [ $? != 0 ] ; then
982 echo 1>&2 "$PRG: umount of $boot failed!"
985 [ "$1" = failure ] && echo 1>&2 "$PRG: umount successfull"
993 ## Use kernel filesytem drivers to mount the bootstrap partition like
994 ## any other filesystem and copy the files there with standard un*x
1000 ## msdosfs is broken, yaboot may not support this filename.
1001 if [ "$fstype" = msdos ] ; then
1002 local CFFILE=yaboot.cnf
1004 local CFFILE=yaboot.conf
1007 if [ -n "$magicboot" ] ; then
1008 local WRAP="${magicboot##*/}"
1011 ## set verbose messages here so they don't show temporary file paths
1012 local INSTALLFIRST="$PRG: Installing first stage bootstrap $magicboot onto $boot..."
1013 local INSTALLPRIMARY="$PRG: Installing primary bootstrap $install onto $boot..."
1015 ## repoint magicboot as the real first stage loader if using the
1016 ## modern automatic generating ofboot.b.
1017 if [ -n "$FIRST" ] ; then
1019 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: set magicboot to $FIRST"
1022 ## gross hack, add note section for IBM CHRP
1023 if [ "$ADDNOTE" = yes ] ; then
1024 hack_yaboot || return 1
1027 ## call mnt() function to take care of mounting filesystem if needed
1028 if [ -z "$mntpoint" ] ; then
1034 ## this is probably insecure on modern filesystems, but i think
1035 ## safe on crippled hfs/dosfs. user should ensure mntpoint= is safe.
1036 if [ -n "$magicboot" ] ; then
1037 [ "$VERBOSE" = 1 ] && echo "$INSTALLFIRST"
1038 cp -f "$magicboot" "$TARGET/ofboot.b"
1039 if [ $? != 0 ] ; then
1040 echo 1>&2 "$PRG: An error occured while writing to $boot"
1041 umnt failure "$TARGET"
1046 [ "$VERBOSE" = 1 ] && echo "$INSTALLPRIMARY"
1047 cp -f "$install" "$TARGET/$BTFILE"
1048 if [ $? != 0 ] ; then
1049 echo 1>&2 "$PRG: An error occured while writing to $boot"
1050 umnt failure "$TARGET"
1054 [ "$VERBOSE" = 1 ] && echo "$PRG: Installing $bootconf onto $boot..."
1055 cp -f "$bootconf" "$TARGET/$CFFILE"
1056 if [ $? != 0 ] ; then
1057 echo 1>&2 "$PRG: An error occured while writing to $boot"
1058 umnt failure "$TARGET"
1062 if [ -n "$BSDLOADER" ] ; then
1063 [ "$VERBOSE" = 1 ] && echo "$PRG: Installing $BSDLOADER onto $boot..."
1064 cp -f "$BSDLOADER" "$TARGET/ofwboot"
1065 if [ $? != 0 ] ; then
1066 echo 1>&2 "$PRG: An error occured while writing to $boot"
1067 umnt failure "$TARGET"
1072 if [ "$protect" = yes ] ; then
1073 [ "$VERBOSE" = 1 ] && echo "$PRG: Setting read-only attributes..."
1074 chmod a-w "$TARGET/$BTFILE"
1075 chmod a-w "$TARGET/$CFFILE"
1076 if [ -n "$magicboot" ] ; then
1077 chmod a-w "$TARGET/ofboot.b"
1079 if [ -n "$BSDLOADER" ] ; then
1080 chmod a-w "$TARGET/ofwboot"
1085 umnt success "$TARGET" || return 1
1087 ## make variable with a \ to avoid shell fsckage. ugly ugly ugly.
1089 if [ -n "$magicboot" ] ; then
1090 [ -n "$OFDIR" ] && OFDIR="${BS}${OFDIR}${BS}"
1091 local OFFILE="${OFDIR}ofboot.b"
1093 [ -n "$OFDIR" ] && OFDIR="${BS}${OFDIR}${BS}"
1094 local OFFILE="${OFDIR}${BTFILE}"
1097 ## update the boot-device variable in OF nvram.
1098 if [ "$nonvram" = 0 ] ; then
1099 [ "$VERBOSE" = 1 ] && echo "$PRG: Updating OpenFirmware boot-device variable in nvram..."
1100 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: boot-device=${ofboot},${OFFILE}"
1101 nvsetenv boot-device "${ofboot},${OFFILE}"
1102 if [ $? != 0 ] ; then
1103 echo 1>&2 "$PRG: An error occured while updating nvram, we'll ignore it"
1106 echo 1>&2 "$PRG: Warning: You must manually configure OpenFirmware to boot."
1112 ## raw installation, for IBM RS/6000 hardware, yaboot is dded to the
1113 ## bootstrap partition.
1116 ## make sure the device is not mounted as a filesystem before
1117 ## we start mucking with it directly.
1118 mount | grep "^$boot\>" > /dev/null
1119 if [ $? = 0 ] ; then
1120 echo 1>&2 "$PRG: $boot appears to be mounted! aborting."
1124 ## set verbosity message before munging the yaboot pathname
1125 local INSTALLPRIMARY="$PRG: Installing primary bootstrap $install onto $boot..."
1127 ## gross hack, add note section for IBM CHRP
1128 if [ "$ADDNOTE" = yes ] ; then
1129 hack_yaboot || return 1
1132 [ "$VERBOSE" = 1 ] && echo "$INSTALLPRIMARY"
1133 dd if=/dev/zero of="$boot" bs=512 count=1600 > /dev/null 2>&1
1134 dd if="$install" of="$boot" bs=512 > /dev/null 2>&1
1135 if [ $? != 0 ] ; then
1136 echo 1>&2 "$PRG: Installation failed."
1140 [ "$VERBOSE" = 1 ] && echo "$PRG: Installation successful"
1143 ## make sure the first stage ofboot generator is compatible.
1146 grep -q "^#%ybinscript-" "$magicboot" 2> /dev/null
1147 if [ "$?" = 0 ] ; then
1148 local magic=`grep "^#%ybinscript-" "$magicboot"`
1149 local ver="${magic##*-}"
1150 if [ "$ver" = "1.1" ] ; then
1154 echo 1>&2 "$PRG: Incompatible version of first stage loader $magicboot. aborting..."
1163 ## build the first stage loader.
1166 ## must have 7 backslashes to == \\ printf + shell = bizarre... or,
1167 ## make special variable to contain a \ (need \\ to make \) to work
1168 ## around echo -e -n brokeness.
1172 ## deal with mntpoint=
1173 [ -n "$OFDIR" ] && local OFDIR="${BS}${OFDIR}${BS}"
1175 ## some misguided people insist on installing OSX on
1176 ## HorribleFileSystem+ instead of UFS, as a result MacOS deblesses
1177 ## OSX, making it unbootable. if apple localizes the filesystem hierarchy again screw it.
1178 [ "$brokenosx" = yes ] && local OSXBOOT="${BS}System${BS}Library${BS}CoreServices${BS}BootX"
1179 [ "$brokenosx" = no ] && local OSXBOOT="${BS}${BS}:tbxi"
1181 ## assign variables for configured menu options.
1182 [ "$usemount" = no -a "$bless" = yes ] && local YB="yaboot GNU l $ofboot ,${BS}${BS}yaboot"
1183 [ "$usemount" = yes -o "$bless" = no ] && local YB="yaboot GNU l $ofboot ,${OFDIR}yaboot"
1184 [ -n "$bsd" ] && OS="$(($OS + 1))" && local BSD="ybsd BSD b $ofboot ,${BS}${BS}ofwboot/$bsd"
1185 [ -n "$macos" ] && OS="$(($OS + 1))" && local MAC="macos MacOS m $macos ,${BS}${BS}:tbxi"
1186 [ -n "$macosx" ] && OS="$(($OS + 1))" && local MX="macosx MacOSX x $macosx ,${OSXBOOT}"
1187 [ -n "$darwin" ] && OS="$(($OS + 1))" && local DW="darwin Darwin d $darwin ,${BS}${BS}:tbxi"
1188 [ "$cdrom" = yes ] && OS="$(($OS + 1))" && local CD="cd CDROM c cd: ,${BS}${BS}:tbxi"
1189 [ "$network" = yes ] && OS="$(($OS + 1))" && local NET="net Network n enet: 0"
1190 [ "$of" = yes ] && OS="$(($OS + 1))" && local OF="of OpenFirmware o quit now"
1191 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: OS=$OS"
1194 ## Usage: OS-count defaultos timeout fgc bgc osname oslabel oskey osdev osfile ...
1195 [ "$DEBUG" = 1 ] && $PRINTF 1>&2 "$PRG: DEBUG: /bin/sh $magicboot $OS $defaultos $delay $fbc $bgc $YB $BSD $MAC $MX $DW $CD $NET $OF\n"
1196 FIRST="$(/bin/sh "$magicboot" "$OS" "$defaultos" "$delay" $fgc $bgc ${YB} ${BSD} ${MAC} ${MX} ${DW} ${CD} ${NET} ${OF})" || return 1
1201 ## mkofboot function.
1204 mount | grep "^$boot\>" > /dev/null
1205 if [ $? = 0 ] ; then
1206 echo 1>&2 "$PRG: $boot appears to be mounted! aborting."
1212 [ "$VERBOSE" = 1 ] && echo "$PRG: Creating HFS filesystem on $boot..."
1213 if (command -v dd > /dev/null 2>&1) ; then
1214 dd if=/dev/zero of="$boot" bs=512 count=1600 > /dev/null 2>&1
1216 hformat -l bootstrap "$boot" > /dev/null
1217 if [ $? != 0 ] ; then
1218 echo 1>&2 "$PRG: HFS filesystem creation failed!"
1221 humount "$boot" ## otherwise we might get confused.
1225 if (command -v mkdosfs > /dev/null 2>&1) ; then
1226 [ -x `command -v mkdosfs` ] || FAIL=1 ; else FAIL=1 ; fi
1227 if [ "$FAIL" = 1 ] ; then
1228 echo 1>&2 "$PRG: mkdosfs is not installed or cannot be found"
1232 [ "$VERBOSE" = 1 ] && echo "$PRG: Creating DOS filesystem on $boot..."
1233 if (command -v dd > /dev/null 2>&1) ; then
1234 dd if=/dev/zero of="$boot" bs=512 count=1600 > /dev/null 2>&1
1236 mkdosfs -n bootstrap "$boot" > /dev/null
1237 if [ $? != 0 ] ; then
1238 echo 1>&2 "$PRG: DOS filesystem creation failed!"
1248 if [ "$FORCE" = yes ] ; then
1252 [ "$fstype" = raw ] && $PRINTF 1>&2 "$PRG: Overwrite contents of $boot with $install? [y/N] "
1253 [ "$fstype" != raw ] && $PRINTF 1>&2 "$PRG: Create $fstype filesystem on $boot? [y/N] "
1260 echo 1>&2 "$PRG: Abort."
1267 ## for fstype=raw check if an ELF binary has already been dded.
1270 if [ "$(dd if="$boot" bs=1 skip=1 count=3 2>/dev/null)" = ELF ] ; then
1273 echo 1>&2 "$PRG: This partition has never had yaboot installed before, please run mkofboot"
1280 ## defaults for this are defined at the beginning of the script with
1284 "## yaboot configuration file generated by ybin $VERSION
1291 partition=$partition
1294 " > "$TMPCONF" || return 1
1296 [ "$DEBUG" = 1 ] && $PRINTF 1>&2 "\nDEBUG: autoconf:\n----\n" && cat "$TMPCONF" 1>&2 && echo 1>&2 "----"
1300 ## take out the trash.
1303 if [ -n "$TMPCONF" ] ; then rm -f "$TMPCONF" ; fi
1304 if [ -n "$FIRST" ] ; then rm -f "$FIRST" ; fi
1305 if [ -n "$TMPYABOOT" ] ; then rm -f "$TMPYABOOT" ; fi
1306 if [ -d "$TMP/bootstrap.$$" -a "$usemount" = yes ] ; then rmdir "$TMP/bootstrap.$$" ; fi
1314 ## absurdly bloated case statement to parse command line options.
1315 if [ $# != 0 ] ; then
1339 if [ -n "$2" ] ; then
1344 echo 1>&2 "$PRG: option requires an argument $1"
1345 echo 1>&2 "Try \`$PRG --help' for more information."
1350 if [ -n "$2" ] ; then
1355 echo 1>&2 "$PRG: option requires an argument $1"
1356 echo 1>&2 "Try \`$PRG --help' for more information."
1361 if [ -n "$2" ] ; 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
1375 ERR=" Error in $CONF:"
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
1400 echo 1>&2 "$PRG: option requires an argument $1"
1401 echo 1>&2 "Try \`$PRG --help' for more information."
1431 if [ -n "$2" ] ; then
1434 echo 1>&2 "$PRG: WARNING: Deprecated option --device"
1437 echo 1>&2 "$PRG: option requires an argument $1"
1438 echo 1>&2 "Try \`$PRG --help' for more information."
1443 if [ -n "$2" ] ; then
1446 echo 1>&2 "$PRG: WARNING: Deprecated option --device"
1449 echo 1>&2 "$PRG: option requires an argument $1"
1450 echo 1>&2 "Try \`$PRG --help' for more information."
1455 if [ -n "$2" ] ; then
1458 echo 1>&2 "$PRG: WARNING: Deprecated option --device"
1461 echo 1>&2 "$PRG: option requires an argument $1"
1462 echo 1>&2 "Try \`$PRG --help' for more information."
1467 if [ -n "$2" ] ; then
1470 echo 1>&2 "$PRG: WARNING: Deprecated option --device"
1473 echo 1>&2 "$PRG: option requires an argument $1"
1474 echo 1>&2 "Try \`$PRG --help' for more information."
1479 if [ -n "$2" ] ; then
1482 echo 1>&2 "$PRG: WARNING: Deprecated option --device"
1485 echo 1>&2 "$PRG: option requires an argument $1"
1486 echo 1>&2 "Try \`$PRG --help' for more information."
1491 if [ -n "$2" ] ; then
1494 echo 1>&2 "$PRG: WARNING: Deprecated option --device"
1497 echo 1>&2 "$PRG: option requires an argument $1"
1498 echo 1>&2 "Try \`$PRG --help' for more information."
1506 echo 1>&2 "$PRG: unrecognized option \`$1'"
1507 echo 1>&2 "Try \`$PRG --help' for more information."
1514 ## check that specified config file exists, unless its /dev/null in
1515 ## which case we assume all options are done on the command line.
1516 if [ "$CONF" = /dev/null ] ; then
1522 ## if there is no config file use the automatic generation to make a
1523 ## generic yaboot.conf. do this before the confcheck to avoid wierd errors.
1524 if [ "$bootconf" = /dev/null ] ; then
1525 if (command -v yabootconfig > /dev/null 2>&1) ; then
1526 echo 1>&2 "$PRG: Warning: no /etc/yaboot.conf, running yabootconfig to make one"
1527 yabootconfig --noinstall --quiet
1528 if [ $? != 0 ] ; then
1529 echo 1>&2 "$PRG: yabootconfig failed, please supply a valid /etc/yaboot.conf"
1530 echo 1>&2 "$PRG: You may also use $PRG's --boot, --image, --partition, and --device switches"
1531 echo 1>&2 "$PRG: These switches will cause $PRG to generate a basic yaboot.conf on the fly"
1534 CONF=/etc/yaboot.conf
1536 ERR=" Error in $CONF:"
1542 ## Checks if each option was defined on the command line, and if so
1543 ## don't read it from the configuration file. this avoids
1544 ## configuration options from being set null, as well as command line
1545 ## options from being clobbered.
1546 [ "$ARGBT" != 1 -a $(parseconf ck boot) = 0 ] && boot=`parseconf str boot`
1547 [ "$ARGOB" != 1 -a $(parseconf ck ofboot) = 0 ] && ofboot=`parseconf str ofboot`
1548 [ "$ARGBF" != 1 -a $(parseconf ck install) = 0 ] && install=`parseconf str install`
1549 [ "$ARGWP" != 1 -a $(parseconf ck magicboot) = 0 ] && magicboot=`parseconf str magicboot`
1550 [ "$ARGMT" != 1 -a $(parseconf flag usemount) = 0 ] && usemount=yes
1551 [ "$ARGFS" != 1 -a $(parseconf ck fstype) = 0 ] && fstype=`parseconf str fstype`
1552 [ "$ARGBS" != 1 -a $(parseconf flag nobless) = 0 ] && bless=no
1553 [ "$ARGPT" != 1 -a $(parseconf flag protect) = 0 ] && protect=yes
1554 [ "$ARGHD" != 1 -a $(parseconf flag hide) = 0 ] && hide=yes
1555 [ "$ARGNV" != 1 -a $(parseconf flag nonvram) = 0 ] && nonvram=1
1556 [ $(parseconf ck hfstype) = 0 ] && hfstype=`parseconf str hfstype`
1557 [ $(parseconf ck hfscreator) = 0 ] && hfscreator=`parseconf str hfscreator`
1558 [ $(parseconf ck mntpoint) = 0 ] && mntpoint=`parseconf str mntpoint`
1559 [ $(parseconf ck delay) = 0 ] && delay=`parseconf str delay`
1560 [ $(parseconf ck timeout) = 0 ] && timeout=`parseconf str timeout`
1561 [ $(parseconf ck bsd) = 0 ] && bsd=`parseconf str bsd`
1562 [ $(parseconf ck macos) = 0 ] && macos=`parseconf str macos`
1563 [ $(parseconf ck macosx) = 0 ] && macosx=`parseconf str macosx`
1564 [ $(parseconf ck darwin) = 0 ] && darwin=`parseconf str darwin`
1565 [ $(parseconf ck defaultos) = 0 ] && defaultos=`parseconf str defaultos`
1566 [ $(parseconf ck fgcolor) = 0 ] && fgcolor=`parseconf str fgcolor`
1567 [ $(parseconf ck bgcolor) = 0 ] && bgcolor=`parseconf str bgcolor`
1568 [ $(parseconf ck icon) = 0 ] && export YBINOFICON=`parseconf str icon`
1569 [ $(parseconf flag enablecdboot) = 0 ] && cdrom=yes
1570 [ $(parseconf flag enablenetboot) = 0 ] && network=yes
1571 [ $(parseconf flag enableofboot) = 0 ] && of=yes
1572 [ $(parseconf flag brokenosx) = 0 ] && brokenosx=yes
1574 ## ffs!! rtfm! foad!
1575 if [ "$boot" = unconfigured ] ; then
1576 echo 1>&2 "$PRG: You must specify the device for the bootstrap partition. (ie: boot=/dev/hdaX)"
1577 echo 1>&2 "$PRG: Try \`$PRG --help' for more information."
1581 ## if there is still no config file use the automatic generation to make a
1582 ## generic yaboot.conf. do this before the confcheck to avoid wierd errors.
1583 if [ "$bootconf" = /dev/null ] ; then
1584 echo 1>&2 "$PRG: Warning: no yaboot.conf, using generic configuration."
1588 ## mntpoint is incompatible with mkofboot.
1589 if [ "$PRG" = mkofboot -a -n "$mntpoint" ] ; then
1590 echo 1>&2 "$PRG: Cannot be used with \`mntpoint='"
1594 ## validate configuration for sanity.
1597 ## check that we can use ofpath, its only needed for magicboot script
1598 ## building and nvram updates.
1599 if [ -n "$magicboot" -o "$nonvram" = 0 ] ; then
1600 if [ -z "$ofboot" -o -n "$macos" -o -n "$macosx" -o -n "$darwin" ] ; then
1601 if (command -v ofpath > /dev/null 2>&1) ; then
1602 [ -x `command -v ofpath` ]
1603 if [ $? != 0 ] ; then
1604 echo 1>&2 "$PRG: ofpath could not be found, aborting."
1608 echo 1>&2 "$PRG: ofpath could not be found, aborting."
1614 ## if password is set in yaboot.conf make sure permissions on that
1615 ## file are safe, warn if not.
1616 if (grep -q '^[[:space:]]*password[[:space:]]*=' "$bootconf" > /dev/null 2>&1) ; then
1620 ## check if we are root if needed.
1621 if [ "$usemount" = yes -a -z "$mntpoint" ] ; then
1622 if [ `id -u` != 0 ] ; then
1623 echo 1>&2 "$PRG: \`usemount' requires root privileges, go away."
1628 if [ "$fstype" = hfs ] ; then
1630 if [ $? != 0 ] ; then
1631 echo 1>&2 "$PRG: hfsutils is not installed or cannot be found"
1632 echo 1>&2 "$PRG: Try --mount if `uname -sr` supports HFS"
1637 ## convert unix device nodes to OpenFirmware pathnames
1638 if [ -n "$magicboot" -o "$nonvram" = 0 ] ; then
1639 convertpath || exit 1
1642 ## yaboot.conf autogeneration. MUST have secure mktemp to
1643 ## avoid race conditions. Debian's mktemp qualifies.
1644 if [ "$bootconf" = auto ] ; then
1645 TMPCONF=`mktemp -q "$TMP/$PRG.XXXXXX"`
1646 if [ $? != 0 ] ; then
1647 echo 1>&2 "$PRG: Could not create temporary file, aborting."
1652 if [ $? != 0 ] ; then
1653 echo 1>&2 "$PRG: An error occured generating yaboot.conf, aborting."
1660 if [ -n "$magicboot" ] ; then
1661 checkfirststage || exit 1
1662 if [ "$FIRSTSTG" = compat ] ; then
1664 if [ $? != 0 ] ; then
1665 echo 1>&2 "$PRG: An error occured while building first stage loader. aborting..."
1675 if [ "$fstype" = raw ] ; then
1677 raw_install || exit 1
1679 util_install || exit 1
1684 mnt_install || exit 1
1692 ## its not nice to erase the partition and then bail!
1693 if [ "$fstype" = msdos ] ; then
1694 echo 1>&2 "$PRG: mtools support is not implemented"
1695 echo 1>&2 "$PRG: Use --mount or add \`usemount' to $CONF"
1699 if [ "$fstype" = raw ] ; then
1700 raw_install || exit 1
1703 util_install || exit 1
1705 [ "$VERBOSE" = 1 ] && echo "$PRG: Installation complete."
1711 mnt_install || exit 1
1712 [ "$VERBOSE" = 1 ] && echo "$PRG: Installation complete."