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 -i, --install pathname to the actual bootloader binary
159 default: /usr/{local/}lib/yaboot/yaboot same as
160 install= in config file [ -i bootloader_file ]
161 -C, --config use alternate configuration file (ybin and yaboot)
163 -m, --magicboot pathname to a OpenFirmware magicboot (CHRP) script
164 --filesystem set the filesystem type of the bootstrap partition
165 available options are hfs, msdos, and raw
166 [ --filesystem hfs ] default is hfs
167 --nobless don't bless the root directory, this should only
168 be used if you are using a MacOS boot partition
169 as the bootstrap partition (not recommended)
170 -M, --mount don't use userspace hfsutils to modify the
171 bootstrap instead try and mount the filesystem
172 directly. Note that attributes cannot be set
173 this way and you will have to manually modify
174 OpenFirmware to make your system bootable
175 --protect set the read-only (locked) bit on all bootstrap
177 --hide set the invisible bit on all bootstrap files
178 this is useful of you don't want them to be
180 --nonvram do not update the boot-device variable in nvram.
181 --force don't ever ask for confirmation
182 -v, --verbose make $PRG more verbose
183 --debug print boring junk only useful for debugging
184 -h, --help display this help and exit
185 -V, --version output version information and exit"
188 ## configuration file parsing. FIXME: need a method which can parse
194 v=`grep "^$2[\ ,=]" "$CONF"` ; echo "${v#*=}"
197 grep "^$2\>" "$CONF" > /dev/null && echo 0 || echo 1
200 grep "^$2[\ ,=]" "$CONF" > /dev/null && echo 0 || echo 1
205 ## check for existence of a configuration file, and make sure we have
209 if [ ! -e "$CONF" ] ; then
210 echo 1>&2 "$PRG: $CONF: No such file or directory"
212 elif [ ! -f "$CONF" ] ; then
213 echo 1>&2 "$PRG: $CONF: Not a regular file"
215 elif [ ! -r "$CONF" ] ; then
216 echo 1>&2 "$PRG: $CONF: Permission denied"
223 ## check to make sure the configuration file is sane and correct.
224 ## maybe this is an insane ammount of error checking, but I want to
225 ## make sure (hopfully) nothing unexpected ever happens. and i just
226 ## like useful errors from programs. every error just marks an error
227 ## variable so we give the user as much info as possible before we
231 if [ ! -e "$boot" ] ; then
232 echo 1>&2 "$PRG: $boot: No such file or directory"
234 elif [ ! -b "$boot" -a ! -f "$boot" ] ; then
235 echo 1>&2 "$PRG: $boot: Not a regular file or block device"
237 elif [ ! -w "$boot" -o ! -r "$boot" ] ; then
238 [ -z "$mntpoint" ] && echo 1>&2 "$PRG: $boot: Permission denied"
239 [ -z "$mntpoint" ] && CONFERR=1
242 if [ ! -e "$install" ] ; then
243 echo 1>&2 "$PRG: $install: No such file or directory"
245 elif [ ! -f "$install" ] ; then
246 echo 1>&2 "$PRG: $bootconf: Not a regular file"
248 elif [ ! -r "$install" ] ; then
249 echo 1>&2 "$PRG: $install: Permission denied"
253 if [ "$bootconf" = auto ] ; then
255 elif [ ! -e "$bootconf" ] ; then
256 echo 1>&2 "$PRG: $bootconf: No such file or directory"
258 elif [ ! -f "$bootconf" ] ; then
259 echo 1>&2 "$PRG: $bootconf: Not a regular file"
261 elif [ ! -r "$bootconf" ] ; then
262 echo 1>&2 "$PRG: $bootconf: Permission denied"
266 if [ -n "$magicboot" ] ; then
267 if [ ! -e "$magicboot" ] ; then
268 echo 1>&2 "$PRG: $magicboot: No such file or directory"
270 elif [ ! -f "$magicboot" ] ; then
271 echo 1>&2 "$PRG: $magicboot: Not a regular file"
273 elif [ ! -r "$magicboot" ] ; then
274 echo 1>&2 "$PRG: $magicboot: Permission denied"
283 if [ "$ARGFS" = 1 ] ; then
284 echo 1>&2 "$PRG: --filesystem must be either \`hfs', \`msdos', or \`raw'"
286 echo 1>&2 "$PRG:$ERR \`fstype' must be either \`hfs', \`msdos', or \`raw'"
292 ## if we are not using HFS filesystems we don't care about HFS
294 if [ "$fstype" = hfs ] ; then
295 if [ `echo ${#hfstype}` != 4 ] ; then
296 if [ "$ARGTP" = 1 ] ; then
297 echo 1>&2 "$PRG: --type must be 4 characters"
299 echo 1>&2 "$PRG:$ERR \`hfstype' must be 4 characters"
304 if [ `echo ${#hfscreator}` != 4 ] ; then
305 if [ "$ARGCT" = 1 ] ; then
306 echo 1>&2 "$PRG: --creator must be 4 characters"
308 echo 1>&2 "$PRG:$ERR \`hfscreator' must be 4 characters"
314 ## some options are not compatible with fstype=raw
315 if [ "$fstype" = raw ] ; then
316 if [ -n "$mntpoint" ] ; then
317 echo 1>&2 "$PRG:$ERR \`mntpoint' is not compatible with fstype=raw"
320 if [ "$usemount" = yes ] ; then
321 echo 1>&2 "$PRG:$ERR \`usemount' is not compatible with fstype=raw"
324 if [ -n "$magicboot" ] ; then
325 echo 1>&2 "$PRG:$ERR \`magicboot' scripts cannot be used with fstype=raw"
330 if [ -n "$mntpoint" ] ; then
332 if [ ! -e "$mntpoint" ] ; then
333 echo 1>&2 "$PRG: $mntpoint: No such file or directory"
335 elif [ ! -d "$mntpoint" ] ; then
336 echo 1>&2 "$PRG: $mntpoint: Not a directory"
338 elif [ ! -w "$mntpoint" -o ! -r "$mntpoint" ] ; then
339 echo 1>&2 "$PRG: $mntpoint: Permission denied"
341 elif [ ! -O "$mntpoint" -a `id -u` != 0 ] ; then
342 echo 1>&2 "$PRG: $mntpoint: Permission denied (not owner)"
346 ## make sure no embedded spaces exist
347 echo "$mntpoint" | grep -q [[:space:]]
349 echo 1>&2 "$PRG:$ERR \`mntpoint=$mntpoint' contains embedded spaces, don't use lame filenames"
353 ## make sure $mntpoint is on $boot, this matters to nvram updating.
354 if [ "$(v=`df "$mntpoint" 2> /dev/null | grep ^/dev/` ; echo ${v%%[ ]*})" != "$boot" -a -d "$mntpoint" ] ; then
355 echo 1>&2 "$PRG: $mntpoint is not located on $boot"
357 ## more then one subdirectory deep is not supported. no sed available on boot floppies ( / -> \ )
358 elif [ "$mntpoint" != "$(v=`df "$mntpoint" 2> /dev/null | grep ^/dev/` ; echo ${v##*[ ]})" ] ; then
359 echo "$(v=`df "$mntpoint" 2>/dev/null | grep ^/dev/`; m=${v##*[ ]}; echo "${mntpoint##*$m/}")" | grep -q /
361 echo 1>&2 "$PRG:$ERR $mntpoint is more then one subdirectory deep from root of $boot"
364 OFDIR="$(v=`df "$mntpoint" 2>/dev/null | grep ^/dev/`; m=${v##*[ ]}; echo "${mntpoint##*$m/}")"
368 if [ "$usemount" = no ] ; then
369 echo 1>&2 "$PRG:$ERR \`mntpoint=' requires \`usemount' be set"
374 if [ -n "$magicboot" ] ; then
375 ## check for bsd loader
376 if [ -n "$bsd" ] ; then
377 if [ -f /usr/lib/yaboot/ofwboot -a -r /usr/lib/yaboot/ofwboot ] ; then
378 BSDLOADER="/usr/lib/yaboot/ofwboot"
379 elif [ -f /usr/local/lib/yaboot/ofwboot -a -r /usr/local/lib/yaboot/ofwboot ] ; then
380 BSDLOADER="/usr/local/lib/yaboot/ofwboot"
382 echo 1>&2 "$PRG: /usr/local/lib/yaboot/ofwboot: No such file or directory"
383 echo 1>&2 "$PRG: With the bsd= option set you must have the bsd boot loader ofwboot"
388 ## convert defaultos variable
390 linux|Linux|GNU|Gnu|gnu)
397 if [ -z "$bsd" ] ; then
398 echo 1>&2 "$PRG:$ERR no entry for \`bsd' found, but defaultos is set to \`bsd'"
404 if [ -z "$macos" ] ; then
405 echo 1>&2 "$PRG:$ERR no entry for \`macos' found, but defaultos is set to \`macos'"
411 if [ -z "$macosx" ] ; then
412 echo 1>&2 "$PRG:$ERR no entry for \`macosx' found, but defaultos is set to \`macosx'"
418 if [ -z "$darwin" ] ; then
419 echo 1>&2 "$PRG:$ERR no entry for \`darwin' found, but defaultos is set to \`darwin'"
424 echo 1>&2 "$PRG:$ERR \`defaultos' must be either \`linux', \`bsd', \`macos' or \`macosx'"
430 ## nvsetenv requires /proc
431 if [ ! -f /proc/uptime -a "$nonvram" = 0 ] ; then
432 echo 1>&2 "$PRG: /proc filesystem is not mounted, nvram will not be updated"
436 if [ "$nonvram" = 0 ] ; then
437 ## see if nvsetenv exists and is executable
438 if (command -v nvsetenv > /dev/null 2>&1) ; then
439 [ -x `command -v nvsetenv` ] || MISSING=1 ; else MISSING=1
442 if [ "$nonvram" = 0 ] ; then
443 ## if nvsetenv exists see if its the old broken version
444 if [ "$MISSING" != 1 ] ; then
445 nvsetenv --version > /dev/null 2>&1 || OLD=1
448 echo 1>&2 "$PRG: Warning: \`nvsetenv' could not be found, nvram will not be updated"
451 if [ "$OLD" = 1 ] ; then
452 ## i check this myself to avoid misleading error
453 ## messages. nvsetenv should REALLY support --version.
454 if [ ! -e /dev/nvram ] ; then
455 echo 1>&2 "$PRG: /dev/nvram: No such file or directory"
456 echo 1>&2 "$PRG: Warning: nvram will not be updated"
458 elif [ ! -c /dev/nvram ] ; then
459 echo 1>&2 "$PRG: /dev/nvram: Not a character device"
460 echo 1>&2 "$PRG: Warning: nvram will not be updated"
462 elif [ ! -w /dev/nvram -o ! -r /dev/nvram ] ; then
463 echo 1>&2 "$PRG: /dev/nvram: Permission denied"
464 echo 1>&2 "$PRG: Warning: nvram will not be updated"
466 elif ! (dd if=/dev/nvram of=/dev/null bs=1 count=10 > /dev/null 2>&1) ; then
467 echo 1>&2 "$PRG: /dev/nvram: No such device"
468 echo 1>&2 "$PRG: Warning: nvram will not be updated"
472 echo 1>&2 "$PRG: Warning: Incompatible version of \`nvsetenv', nvram will not be updated"
477 if [ -f "$boot" ] ; then
478 echo 1>&2 "$PRG: $boot is a regular file, disabling nvram updating"
483 ## check for newworld mac. use cat hack due to /proc wierdness.
484 ## do not bail if we are on an OldWorld only warn (very loudly).
485 if [ "$(v=`cat /proc/cpuinfo 2>/dev/null | grep pmac-generation` ; echo ${v##*:})" = NewWorld ] ; then
487 elif [ "$(v=`cat /proc/cpuinfo 2>/dev/null | grep pmac-generation` ; echo ${v##*:})" = OldWorld ] ; then
489 echo 1>&2 '@@@@@@@@@@@@@@ WARNING!! WARNING!! WARNING!! @@@@@@@@@@@@@@'
490 echo 1>&2 "$PRG: Warning: This is an OldWorld PowerMac, $boot will **NOT** be bootable on this machine"
491 echo 1>&2 "$PRG: Oldworld PowerMacs need to use the quik bootloader, not yaboot"
492 echo 1>&2 '@@@@@@@@@@@@@@ WARNING!! WARNING!! WARNING!! @@@@@@@@@@@@@@'
494 [ "$nonvram" = 0 ] && echo 1>&2 "$PRG: OldWorld PowerMac, nvram will not be updated"
496 elif (cat /proc/cpuinfo 2>/dev/null | grep ^motherboard | grep -q AAPL) ; then
498 echo 1>&2 '@@@@@@@@@@@@@@ WARNING!! WARNING!! WARNING!! @@@@@@@@@@@@@@'
499 echo 1>&2 "$PRG: Warning: This is an OldWorld PowerMac, $boot will **NOT** be bootable on this machine"
500 echo 1>&2 "$PRG: Oldworld PowerMacs need to use the quik bootloader, not yaboot"
501 echo 1>&2 '@@@@@@@@@@@@@@ WARNING!! WARNING!! WARNING!! @@@@@@@@@@@@@@'
503 [ "$nonvram" = 0 ] && echo 1>&2 "$PRG: OldWorld PowerMac, nvram will not be updated"
505 elif (cat /proc/cpuinfo 2> /dev/null | grep ^machine | grep -q 'CHRP IBM') ; then
506 ## IBM hardware does not need nvram update AFAICT
510 #echo 1>&2 "$PRG: Warning: Unknown archetecture, $boot may not be bootable on this machine"
511 [ "$nonvram" = 0 ] && echo 1>&2 "$PRG: Warning: Unknown architecture, nvram will not be updated"
515 ## convert human readable color values from config to proper color
518 black) fgc=0 ;; blue) fgc=1 ;; green) fgc=2 ;; cyan) fgc=3 ;;
519 red) fgc=4 ;; purple) fgc=5 ;; brown) fgc=6 ;; light-gray) fgc=7 ;;
520 dark-gray) fgc=8 ;; light-blue) fgc=9 ;; light-green) fgc=a ;;
521 light-cyan) fgc=b ;; light-red) fgc=c ;; light-purple) fgc=d ;;
522 yellow) fgc=e ;; white) fgc=f ;;
524 echo 1>&2 "$PRG:$ERR Invalid fgcolor: \`$fgcolor'"
529 black) bgc=0 ;; blue) bgc=1 ;; green) bgc=2 ;; cyan) bgc=3 ;;
530 red) bgc=4 ;; purple) bgc=5 ;; brown) bgc=6 ;; light-gray) bgc=7 ;;
531 dark-gray) bgc=8 ;; light-blue) bgc=9 ;; light-green) bgc=a ;;
532 light-cyan) bgc=b ;; light-red) bgc=c ;; light-purple) bgc=d ;;
533 yellow) bgc=e ;; white) bgc=f ;;
535 echo 1>&2 "$PRG:$ERR Invalid bgcolor: \`$bgcolor'"
540 ## if delay is not set use yaboot's timeout
541 if [ -z "$delay" ] ; then
542 delay="$(($timeout / 10))"
545 if [ "$CONFERR" = 1 ] ; then
553 ## if readlink is missing use a kludge
554 if (command -v readlink > /dev/null 2>&1) ; then
559 local SYMTARGET="$(v=`ls -l "$2" 2>/dev/null` ; echo ${v##*> })"
560 if [ -n "$SYMTARGET" ] ; then
569 ## /etc/yaboot.conf with password should not be world readable.
572 if [ -L "$bootconf" ] ; then
573 local realfile="$(readlink -f "$bootconf")" || return 0
575 local realfile="$bootconf"
578 ## don't bother if we could not read the symlink
579 [ -z "$realfile" ] && return 0
580 [ ! -f "$realfile" ] && return 0
582 ## get permissions, and don't bother checking if we can't
583 local PERM=`v=$(ls -l "$realfile" 2>/dev/null) ; echo ${v%% *}`
584 [ -z "$PERM" ] && return 0
585 [ `echo ${#PERM}` != 10 ] && return 0
588 -rw-------|-r--------)
589 if [ ! -O "$realfile" -a `id -u` = 0 ] ; then
590 echo 1>&2 "$PRG: Warning: $bootconf is not owned by root"
593 -rw-r-----|-r--r-----)
594 if [ ! -O "$realfile" -a `id -u` = 0 ] ; then
595 echo 1>&2 "$PRG: Warning: $bootconf is not owned by root"
597 if [ ! -G "$realfile" -a `id -g` = 0 ] ; then
598 echo 1>&2 "$PRG: Warning: $bootconf is not owned by group root"
601 -r--r--r--|-rw-r--r--|-rw-rw-r--|-rw-rw-rw-|-rw-rw----)
602 echo 1>&2 "$PRG: Warning: Insecure permissions on $bootconf: $PERM should be -rw-------"
605 echo 1>&2 "$PRG: Warning: Incorrect permissions on $bootconf: $PERM should be -rw-------"
612 ## figure out bootstrap device OF pathname if user did not supply it.
613 if [ -z "$ofboot" ] ; then
614 [ "$VERBOSE" = 1 ] && echo "$PRG: Finding OpenFirmware device path to \`$boot'..."
615 ofboot="$($OFPATH $boot)"
616 if [ $? != 0 ] ; then
617 echo 1>&2 "$PRG: Unable to find OpenFirmware path for boot=$boot"
618 echo 1>&2 "$PRG: Please add ofboot=<path> where <path> is the OpenFirmware path to $boot to $CONF"
621 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: ofboot set to \`$ofboot'"
624 ## figure out OF device path for macos/macosx if user supplied a unix device node.
625 if [ -n "$bsd" ] ; then
628 [ "$VERBOSE" = 1 ] && echo "$PRG: Finding OpenFirmware device path to \`$bsd'..."
630 bsd="$($OFPATH $bsd)"
631 if [ $? != 0 ] ; then
632 echo 1>&2 "$PRG: Unable to determine OpenFirmware path for bsd=$sbsd"
633 echo 1>&2 "$PRG: Try specifying the real OpenFirmware path for bsd=$sbsd in $CONF"
636 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: bsd set to \`$bsd' from \`$sbsd'"
639 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: bsd left alone: \`$bsd'"
644 if [ -n "$macos" ] ; then
647 [ "$VERBOSE" = 1 ] && echo "$PRG: Finding OpenFirmware device path to \`$macos'..."
648 local smacos="$macos"
649 macos="$($OFPATH $macos)"
650 if [ $? != 0 ] ; then
651 echo 1>&2 "$PRG: Unable to determine OpenFirmware path for macos=$smacos"
652 echo 1>&2 "$PRG: Try specifying the real OpenFirmware path for macos=$smacos in $CONF"
655 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: macos set to \`$macos' from \`$smacos'"
658 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: macos left alone: \`$macos'"
663 if [ -n "$macosx" ] ; then
666 [ "$VERBOSE" = 1 ] && echo "$PRG: Finding OpenFirmware device path to \`$macosx'..."
667 local smacosx="$macosx"
668 macosx="$($OFPATH $macosx)"
669 if [ $? != 0 ] ; then
670 echo 1>&2 "$PRG: Unable to determine OpenFirmware path for macosx=$smacosx"
671 echo 1>&2 "$PRG: Try specifying the real OpenFirmware path for macosx=$smacosx in $CONF"
674 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: macosx set to \`$macosx' from \`$smacosx'"
677 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: macosx left alone: \`$macosx'"
682 if [ -n "$darwin" ] ; then
685 [ "$VERBOSE" = 1 ] && echo "$PRG: Finding OpenFirmware device path to \`$darwin'..."
686 local sdarwin="$darwin"
687 darwin="$($OFPATH $darwin)"
688 if [ $? != 0 ] ; then
689 echo 1>&2 "$PRG: Unable to determine OpenFirmware path for darwin=$sdarwin"
690 echo 1>&2 "$PRG: Try specifying the real OpenFirmware path for darwin=$sdarwin in $CONF"
693 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: darwin set to \`$darwin' from \`$sdarwin'"
696 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: darwin left alone: \`$darwin'"
701 if [ "$CONVERR" = 1 ] ; then
708 ## make sure the hfsutils we need are installed and executable.
711 if (command -v hmount > /dev/null 2>&1) ; then
712 [ -x `command -v hmount` ] || FAIL=1 ; else FAIL=1 ; fi
713 if (command -v humount > /dev/null 2>&1) ; then
714 [ -x `command -v humount` ] || FAIL=1 ; else FAIL=1 ; fi
715 if (command -v hcopy > /dev/null 2>&1) ; then
716 [ -x `command -v hcopy` ] || FAIL=1 ; else FAIL=1 ; fi
717 if (command -v hattrib > /dev/null 2>&1) ; then
718 [ -x `command -v hattrib` ] || FAIL=1 ; else FAIL=1 ; fi
719 if (command -v hformat > /dev/null 2>&1) ; then
720 [ -x `command -v hformat` ] || FAIL=1 ; else FAIL=1 ; fi
722 if [ "$FAIL" = 1 ] ; then
729 ## This is gross, IBM CHRP OF needs a .note added to the yaboot
730 ## binary, nobody knows whether this note will affect PowerMac OF or
731 ## not (or could in the future).
734 local YBDIR="${install%/*}"
735 if [ -x "$YBDIR/addnote" ] ; then
736 TMPYABOOT=`mktemp -q "$TMP/yaboot.XXXXXX"`
737 if [ $? != 0 ] ; then
738 echo 1>&2 "$PRG: Could not create temporary file, aborting."
741 if (cat "$install" > "$TMPYABOOT" 2> /dev/null) ; then
744 echo 1>&2 "$PRG: Could not create temporary file, aborting."
748 [ "$DEBUG" = 1 ] && echo "$PRG: Embedding CHRP note section in temp yaboot..."
749 "$YBDIR/addnote" "$install" > /dev/null 2>&1
750 if [ $? != 0 ] ; then
751 echo 1>&2 "$PRG: Could not install note section required by your architecture"
755 echo 1>&2 "$PRG: Your architecture requires $YBDIR/addnote which cannot be found"
761 ## install using userspace utilities rather then kernel filesytem
762 ## support. hfsutils only, mtools not supported.
765 ## catch signals, and humount, cleanup done by trap 0.
766 trap "humount $boot ; exit 129" 1
767 trap "echo 1>&2 $SIGINT ; humount $boot ; exit 130" 2
768 trap "humount $boot ; exit 131" 3
769 trap "humount $boot ; exit 143" 15
771 ## filenames on bootstrap partition. ofboot hard codes yaboot.
773 local CFFILE=yaboot.conf
775 ## if there is a magicboot script to install we will give it the
776 ## hfstype (should be "tbxi") and give yaboot type "boot".
777 if [ -n "$magicboot" ] ; then
780 local BTTYPE="$hfstype"
783 if [ -n "$magicboot" ] ; then
784 local WRAP="${magicboot##*/}"
787 ## set verbose messages here so they don't show temporary file paths
788 local INSTALLFIRST="$PRG: Installing first stage bootstrap $magicboot onto $boot..."
789 local INSTALLPRIMARY="$PRG: Installing primary bootstrap $install onto $boot..."
791 ## repoint magicboot as the real first stage loader if using the
792 ## modern automatic generating ofboot.b.
793 if [ -n "$FIRST" ] ; then
795 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: set magicboot to $FIRST"
798 ## gross hack, add note section for IBM CHRP
799 if [ "$ADDNOTE" = yes ] ; then
800 hack_yaboot || return 1
803 if [ "$fstype" = hfs ] ; then
804 if [ "$protect" = yes ] ; then
808 if [ "$hide" = yes ] ; then
812 ## make sure the device is not mounted as a filesystem before
813 ## we start mucking with it directly.
814 mount | grep "^$boot\>" > /dev/null
816 echo 1>&2 "$PRG: $boot appears to be mounted! aborting."
820 ## hmount is really more of a way to make sure we have a valid HFS
821 ## filesystem before proceding, and hcopy requires it...
822 hmount "$boot" > /dev/null
823 if [ $? != 0 ] ; then
824 echo 1>&2 "$PRG: $boot appears to have never had a bootstrap installed, please run mkofboot"
828 ## must be explicit with target filename to avoid hfsutils
829 ## braindamage ("_" -> " " filename mangling) also avoid
830 ## ambiguity in the bootstrap partition.
831 if [ -n "$magicboot" ] ; then
832 [ "$VERBOSE" = 1 ] && echo "$INSTALLFIRST"
833 hcopy -r "$magicboot" :ofboot.b
834 if [ $? != 0 ] ; then
835 echo 1>&2 "$PRG: An error occured while writing to $boot"
840 [ "$VERBOSE" = 1 ] && echo "$INSTALLPRIMARY"
841 hcopy -r "$install" :"$BTFILE"
842 if [ $? != 0 ] ; then
843 echo 1>&2 "$PRG: An error occured while writing to $boot"
847 [ "$VERBOSE" = 1 ] && echo "$PRG: Installing $bootconf onto $boot..."
848 hcopy -r "$bootconf" :"$CFFILE"
849 if [ $? != 0 ] ; then
850 echo 1>&2 "$PRG: An error occured while writing to $boot"
854 if [ -n "$BSDLOADER" ] ; then
855 [ "$VERBOSE" = 1 ] && echo "$PRG: Installing $BSDLOADER onto $boot..."
856 hcopy -r "$BSDLOADER" :ofwboot
857 if [ $? != 0 ] ; then
858 echo 1>&2 "$PRG: An error occured while writing to $boot"
863 ## set all file's attributes, if a magicboot script exists it
864 ## gets the configured hfstype instead of yaboot (should be
865 ## "tbxi") so it gets booted by OF.
866 if [ -n "$magicboot" ] ; then
867 [ "$VERBOSE" = 1 ] && echo "$PRG: Setting attributes on $WRAP..."
868 hattrib -t "$hfstype" -c "$hfscreator" $INVISIBLE $LOCK :ofboot.b
869 if [ $? != 0 ] ; then
870 echo 1>&2 "$PRG: Warning: error setting attributes on $WRAP"
871 echo 1>&2 "$PRG: This is probably bad but we'll ignore it."
875 [ "$VERBOSE" = 1 ] && echo "$PRG: Setting attributes on $BTFILE..."
876 hattrib -t "$BTTYPE" -c "$hfscreator" $INVISIBLE $LOCK :"$BTFILE"
877 if [ $? != 0 ] ; then
878 echo 1>&2 "$PRG: Warning: error setting attributes on $BTFILE"
879 echo 1>&2 "$PRG: This is probably bad but we'll ignore it"
882 [ "$VERBOSE" = 1 ] && echo "$PRG: Setting attributes on $CFFILE..."
883 hattrib -t "conf" -c "$hfscreator" $INVISIBLE $LOCK :"$CFFILE"
884 if [ $? != 0 ] ; then
885 echo 1>&2 "$PRG: Warning: error setting attributes on $CFFILE"
886 echo 1>&2 "$PRG: This is probably unimportant so we'll ignore it"
889 if [ -n "$BSDLOADER" ] ; then
890 [ "$VERBOSE" = 1 ] && echo "$PRG: Setting attributes on ofwboot..."
891 hattrib -t "bsdb" -c "$hfscreator" $INVISIBLE $LOCK :ofwboot
892 if [ $? != 0 ] ; then
893 echo 1>&2 "$PRG: Warning: error setting attributes on ofwboot"
894 echo 1>&2 "$PRG: This is probably unimportant so we'll ignore it"
898 ## bless the root directory so OF will find the boot file
899 if [ "$bless" = yes ] ; then
900 [ "$VERBOSE" = 1 ] && echo "$PRG: Blessing $boot with Holy Penguin Pee..."
902 if [ $? != 0 ] ; then
903 echo 1>&2 "$PRG: Warning: error blessing $boot"
904 echo 1>&2 "$PRG: This is probably bad but we'll ignore it"
908 ## clean up the ~/.hcwd file hmount creates
909 humount "$boot" > /dev/null
912 ## use explicit filename if we don't bless.
913 if [ "$bless" = yes ] ; then
914 local OFFILE='\\:tbxi'
916 if [ -n "$magicboot" ] ; then
917 local OFFILE=ofboot.b
919 local OFFILE="$BTFILE"
923 ## update the boot-device variable in OF nvram.
924 if [ "$nonvram" = 0 ] ; then
925 [ "$VERBOSE" = 1 ] && echo "$PRG: Updating OpenFirmware boot-device variable in nvram..."
926 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: boot-device=${ofboot},${OFFILE}"
927 nvsetenv boot-device "${ofboot},${OFFILE}"
928 if [ $? != 0 ] ; then
929 echo 1>&2 "$PRG: An error occured while updating nvram, we'll ignore it"
934 echo 1>&2 "$PRG: mtools support is not implemented"
935 echo 1>&2 "$PRG: Use --mount or add \`usemount' to $CONF"
942 ## used by mnt_install so mntpoint= can be supported in a cleaner way.
945 ## we can even create bootstrap filesystem images directly if you
947 if [ -f "$boot" ] ; then
951 if [ -e "$TMP/bootstrap.$$" ] ; then
952 echo 1>&2 "$PRG: $TMP/bootstrap.$$ exists, aborting."
956 mkdir -m 700 "$TMP/bootstrap.$$"
957 if [ $? != 0 ] ; then
958 echo 1>&2 "$PRG: Could not create mountpoint directory, aborting."
962 mount | grep "^$boot\>" > /dev/null
964 echo 1>&2 "$PRG: $boot appears to be mounted! aborting."
968 [ "$VERBOSE" = 1 ] && echo "$PRG: Mounting $boot..."
969 mount -t "$fstype" -o rw,umask=077$loop "$boot" "$TMP/bootstrap.$$"
970 if [ $? != 0 ] ; then
971 echo 1>&2 "$PRG: An error occured mounting $boot"
975 ## catch signals, set here to avoid umounting something we did not
976 ## mount. cleanup done by trap 0.
977 trap "umount $boot ; exit 129" 1
978 trap "echo 1>&2 $SIGINT ; umount $boot ; exit 130" 2
979 trap "umount $boot ; exit 131" 3
980 trap "umount $boot ; exit 143" 15
982 TARGET="$TMP/bootstrap.$$"
986 ## umnt funtion which checks whether we mounted anything or not, for
987 ## mntpoint= this makes the code below cleaner IMO.
990 if [ -z "$mntpoint" ] ; then
991 [ "$1" = failure ] && echo 1>&2 "$PRG: Attempting to umount $boot..."
993 if [ $? != 0 ] ; then
994 echo 1>&2 "$PRG: umount of $boot failed!"
997 [ "$1" = failure ] && echo 1>&2 "$PRG: umount successfull"
1005 ## Use kernel filesytem drivers to mount the bootstrap partition like
1006 ## any other filesystem and copy the files there with standard un*x
1012 ## msdosfs is broken, yaboot may not support this filename.
1013 if [ "$fstype" = msdos ] ; then
1014 local CFFILE=yaboot.cnf
1016 local CFFILE=yaboot.conf
1019 if [ -n "$magicboot" ] ; then
1020 local WRAP="${magicboot##*/}"
1023 ## set verbose messages here so they don't show temporary file paths
1024 local INSTALLFIRST="$PRG: Installing first stage bootstrap $magicboot onto $boot..."
1025 local INSTALLPRIMARY="$PRG: Installing primary bootstrap $install onto $boot..."
1027 ## repoint magicboot as the real first stage loader if using the
1028 ## modern automatic generating ofboot.b.
1029 if [ -n "$FIRST" ] ; then
1031 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: set magicboot to $FIRST"
1034 ## gross hack, add note section for IBM CHRP
1035 if [ "$ADDNOTE" = yes ] ; then
1036 hack_yaboot || return 1
1039 ## call mnt() function to take care of mounting filesystem if needed
1040 if [ -z "$mntpoint" ] ; then
1046 ## this is probably insecure on modern filesystems, but i think
1047 ## safe on crippled hfs/dosfs. user should ensure mntpoint= is safe.
1048 if [ -n "$magicboot" ] ; then
1049 [ "$VERBOSE" = 1 ] && echo "$INSTALLFIRST"
1050 cp -f "$magicboot" "$TARGET/ofboot.b"
1051 if [ $? != 0 ] ; then
1052 echo 1>&2 "$PRG: An error occured while writing to $boot"
1053 umnt failure "$TARGET"
1058 [ "$VERBOSE" = 1 ] && echo "$INSTALLPRIMARY"
1059 cp -f "$install" "$TARGET/$BTFILE"
1060 if [ $? != 0 ] ; then
1061 echo 1>&2 "$PRG: An error occured while writing to $boot"
1062 umnt failure "$TARGET"
1066 [ "$VERBOSE" = 1 ] && echo "$PRG: Installing $bootconf onto $boot..."
1067 cp -f "$bootconf" "$TARGET/$CFFILE"
1068 if [ $? != 0 ] ; then
1069 echo 1>&2 "$PRG: An error occured while writing to $boot"
1070 umnt failure "$TARGET"
1074 if [ -n "$BSDLOADER" ] ; then
1075 [ "$VERBOSE" = 1 ] && echo "$PRG: Installing $BSDLOADER onto $boot..."
1076 cp -f "$BSDLOADER" "$TARGET/ofwboot"
1077 if [ $? != 0 ] ; then
1078 echo 1>&2 "$PRG: An error occured while writing to $boot"
1079 umnt failure "$TARGET"
1084 if [ "$protect" = yes ] ; then
1085 [ "$VERBOSE" = 1 ] && echo "$PRG: Setting read-only attributes..."
1086 chmod a-w "$TARGET/$BTFILE"
1087 chmod a-w "$TARGET/$CFFILE"
1088 if [ -n "$magicboot" ] ; then
1089 chmod a-w "$TARGET/ofboot.b"
1091 if [ -n "$BSDLOADER" ] ; then
1092 chmod a-w "$TARGET/ofwboot"
1097 umnt success "$TARGET" || return 1
1099 ## make variable with a \ to avoid shell fsckage. ugly ugly ugly.
1101 if [ -n "$magicboot" ] ; then
1102 [ -n "$OFDIR" ] && OFDIR="${BS}${OFDIR}${BS}"
1103 local OFFILE="${OFDIR}ofboot.b"
1105 [ -n "$OFDIR" ] && OFDIR="${BS}${OFDIR}${BS}"
1106 local OFFILE="${OFDIR}${BTFILE}"
1109 ## update the boot-device variable in OF nvram.
1110 if [ "$nonvram" = 0 ] ; then
1111 [ "$VERBOSE" = 1 ] && echo "$PRG: Updating OpenFirmware boot-device variable in nvram..."
1112 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: boot-device=${ofboot},${OFFILE}"
1113 nvsetenv boot-device "${ofboot},${OFFILE}"
1114 if [ $? != 0 ] ; then
1115 echo 1>&2 "$PRG: An error occured while updating nvram, we'll ignore it"
1118 echo 1>&2 "$PRG: Warning: You must manually configure OpenFirmware to boot."
1124 ## raw installation, for IBM RS/6000 hardware, yaboot is dded to the
1125 ## bootstrap partition.
1128 ## make sure the device is not mounted as a filesystem before
1129 ## we start mucking with it directly.
1130 mount | grep "^$boot\>" > /dev/null
1131 if [ $? = 0 ] ; then
1132 echo 1>&2 "$PRG: $boot appears to be mounted! aborting."
1136 ## set verbosity message before munging the yaboot pathname
1137 local INSTALLPRIMARY="$PRG: Installing primary bootstrap $install onto $boot..."
1139 ## gross hack, add note section for IBM CHRP
1140 if [ "$ADDNOTE" = yes ] ; then
1141 hack_yaboot || return 1
1144 [ "$VERBOSE" = 1 ] && echo "$INSTALLPRIMARY"
1145 dd if=/dev/zero of="$boot" bs=512 count=1600 > /dev/null 2>&1
1146 dd if="$install" of="$boot" bs=512 > /dev/null 2>&1
1147 if [ $? != 0 ] ; then
1148 echo 1>&2 "$PRG: Installation failed."
1152 [ "$VERBOSE" = 1 ] && echo "$PRG: Installation successful"
1155 ## make sure the first stage ofboot generator is compatible.
1158 grep -q "^#%ybinscript-" "$magicboot" 2> /dev/null
1159 if [ "$?" = 0 ] ; then
1160 local magic=`grep "^#%ybinscript-" "$magicboot"`
1161 local ver="${magic##*-}"
1162 if [ "$ver" = "1.1" ] ; then
1166 echo 1>&2 "$PRG: Incompatible version of first stage loader $magicboot. aborting..."
1175 ## build the first stage loader.
1178 ## must have 7 backslashes to == \\ printf + shell = bizarre... or,
1179 ## make special variable to contain a \ (need \\ to make \) to work
1180 ## around echo -e -n brokeness.
1184 ## deal with mntpoint=
1185 [ -n "$OFDIR" ] && local OFDIR="${BS}${OFDIR}${BS}"
1187 ## some misguided people insist on installing OSX on
1188 ## HorribleFileSystem+ instead of UFS, as a result MacOS deblesses
1189 ## OSX, making it unbootable. if apple localizes the filesystem hierarchy again screw it.
1190 [ "$brokenosx" = yes ] && local OSXBOOT="${BS}System${BS}Library${BS}CoreServices${BS}BootX"
1191 [ "$brokenosx" = no ] && local OSXBOOT="${BS}${BS}:tbxi"
1193 ## assign variables for configured menu options.
1194 [ "$usemount" = no -a "$bless" = yes ] && local YB="yaboot GNU l $ofboot ,${BS}${BS}yaboot"
1195 [ "$usemount" = yes -o "$bless" = no ] && local YB="yaboot GNU l $ofboot ,${OFDIR}yaboot"
1196 [ -n "$bsd" ] && OS="$(($OS + 1))" && local BSD="ybsd BSD b $ofboot ,${BS}${BS}ofwboot/$bsd"
1197 [ -n "$macos" ] && OS="$(($OS + 1))" && local MAC="macos MacOS m $macos ,${BS}${BS}:tbxi"
1198 [ -n "$macosx" ] && OS="$(($OS + 1))" && local MX="macosx MacOSX x $macosx ,${OSXBOOT}"
1199 [ -n "$darwin" ] && OS="$(($OS + 1))" && local DW="darwin Darwin d $darwin ,${BS}${BS}:tbxi"
1200 [ "$cdrom" = yes ] && OS="$(($OS + 1))" && local CD="cd CDROM c cd: ,${BS}${BS}:tbxi"
1201 [ "$network" = yes ] && OS="$(($OS + 1))" && local NET="net Network n enet: 0"
1202 [ "$of" = yes ] && OS="$(($OS + 1))" && local OF="of OpenFirmware o quit now"
1203 [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: OS=$OS"
1206 ## Usage: OS-count defaultos timeout fgc bgc osname oslabel oskey osdev osfile ...
1207 [ "$DEBUG" = 1 ] && $PRINTF 1>&2 "$PRG: DEBUG: /bin/sh $magicboot $OS $defaultos $delay $fbc $bgc $YB $BSD $MAC $MX $DW $CD $NET $OF\n"
1208 FIRST="$(/bin/sh "$magicboot" "$OS" "$defaultos" "$delay" $fgc $bgc ${YB} ${BSD} ${MAC} ${MX} ${DW} ${CD} ${NET} ${OF})" || return 1
1213 ## mkofboot function.
1216 mount | grep "^$boot\>" > /dev/null
1217 if [ $? = 0 ] ; then
1218 echo 1>&2 "$PRG: $boot appears to be mounted! aborting."
1224 [ "$VERBOSE" = 1 ] && echo "$PRG: Creating HFS filesystem on $boot..."
1225 if (command -v dd > /dev/null 2>&1) ; then
1226 dd if=/dev/zero of="$boot" bs=512 count=1600 > /dev/null 2>&1
1228 hformat -l bootstrap "$boot" > /dev/null
1229 if [ $? != 0 ] ; then
1230 echo 1>&2 "$PRG: HFS filesystem creation failed!"
1233 humount "$boot" ## otherwise we might get confused.
1237 if (command -v mkdosfs > /dev/null 2>&1) ; then
1238 [ -x `command -v mkdosfs` ] || FAIL=1 ; else FAIL=1 ; fi
1239 if [ "$FAIL" = 1 ] ; then
1240 echo 1>&2 "$PRG: mkdosfs is not installed or cannot be found"
1244 [ "$VERBOSE" = 1 ] && echo "$PRG: Creating DOS filesystem on $boot..."
1245 if (command -v dd > /dev/null 2>&1) ; then
1246 dd if=/dev/zero of="$boot" bs=512 count=1600 > /dev/null 2>&1
1248 mkdosfs -n bootstrap "$boot" > /dev/null
1249 if [ $? != 0 ] ; then
1250 echo 1>&2 "$PRG: DOS filesystem creation failed!"
1260 if [ "$FORCE" = yes ] ; then
1264 [ "$fstype" = raw ] && $PRINTF 1>&2 "$PRG: Overwrite contents of $boot with $install? [y/N] "
1265 [ "$fstype" != raw ] && $PRINTF 1>&2 "$PRG: Create $fstype filesystem on $boot? [y/N] "
1272 echo 1>&2 "$PRG: Abort."
1279 ## for fstype=raw check if an ELF binary has already been dded.
1282 if [ "$(dd if="$boot" bs=1 skip=1 count=3 2>/dev/null)" = ELF ] ; then
1285 echo 1>&2 "$PRG: This partition has never had yaboot installed before, please run mkofboot"
1292 ## defaults for this are defined at the beginning of the script with
1296 "## yaboot configuration file generated by ybin $VERSION
1303 partition=$partition
1306 " > "$TMPCONF" || return 1
1308 [ "$DEBUG" = 1 ] && $PRINTF 1>&2 "\nDEBUG: autoconf:\n----\n" && cat "$TMPCONF" 1>&2 && echo 1>&2 "----"
1312 ## take out the trash.
1315 if [ -n "$TMPCONF" ] ; then rm -f "$TMPCONF" ; fi
1316 if [ -n "$FIRST" ] ; then rm -f "$FIRST" ; fi
1317 if [ -n "$TMPYABOOT" ] ; then rm -f "$TMPYABOOT" ; fi
1318 if [ -d "$TMP/bootstrap.$$" -a "$usemount" = yes ] ; then rmdir "$TMP/bootstrap.$$" ; fi
1326 ## absurdly bloated case statement to parse command line options.
1327 if [ $# != 0 ] ; then
1354 if [ -n "$2" ] ; then
1355 if [ "$boot" = "unconfigured" ]; then
1363 echo 1>&2 "$PRG: option requires an argument $1"
1364 echo 1>&2 "Try \`$PRG --help' for more information."
1369 if [ -n "$2" ] ; then
1375 echo 1>&2 "$PRG: option requires an argument $1"
1376 echo 1>&2 "Try \`$PRG --help' for more information."
1381 if [ -n "$2" ] ; then
1387 echo 1>&2 "$PRG: option requires an argument $1"
1388 echo 1>&2 "Try \`$PRG --help' for more information."
1393 if [ -n "$2" ] ; then
1396 ERR=" Error in $CONF:"
1400 echo 1>&2 "$PRG: option requires an argument $1"
1401 echo 1>&2 "Try \`$PRG --help' for more information."
1406 if [ -n "$2" ] ; then
1412 echo 1>&2 "$PRG: option requires an argument $1"
1413 echo 1>&2 "Try \`$PRG --help' for more information."
1418 if [ -n "$2" ] ; then
1424 echo 1>&2 "$PRG: option requires an argument $1"
1425 echo 1>&2 "Try \`$PRG --help' for more information."
1460 if [ -n "$2" ] ; then
1463 echo 1>&2 "$PRG: WARNING: Deprecated option --device"
1467 echo 1>&2 "$PRG: option requires an argument $1"
1468 echo 1>&2 "Try \`$PRG --help' for more information."
1473 if [ -n "$2" ] ; then
1476 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"
1493 echo 1>&2 "$PRG: option requires an argument $1"
1494 echo 1>&2 "Try \`$PRG --help' for more information."
1499 if [ -n "$2" ] ; then
1502 echo 1>&2 "$PRG: WARNING: Deprecated option --device"
1506 echo 1>&2 "$PRG: option requires an argument $1"
1507 echo 1>&2 "Try \`$PRG --help' for more information."
1512 if [ -n "$2" ] ; then
1515 echo 1>&2 "$PRG: WARNING: Deprecated option --device"
1519 echo 1>&2 "$PRG: option requires an argument $1"
1520 echo 1>&2 "Try \`$PRG --help' for more information."
1525 if [ -n "$2" ] ; then
1528 echo 1>&2 "$PRG: WARNING: Deprecated option --device"
1532 echo 1>&2 "$PRG: option requires an argument $1"
1533 echo 1>&2 "Try \`$PRG --help' for more information."
1541 echo 1>&2 "$PRG: unrecognized option \`$1'"
1542 echo 1>&2 "Try \`$PRG --help' for more information."
1549 ## check that specified config file exists, unless its /dev/null in
1550 ## which case we assume all options are done on the command line.
1551 if [ "$CONF" = /dev/null ] ; then
1557 ## if there is no config file use the automatic generation to make a
1558 ## generic yaboot.conf. do this before the confcheck to avoid wierd errors.
1559 if [ "$bootconf" = /dev/null ] ; then
1560 if (command -v yabootconfig > /dev/null 2>&1) ; then
1561 echo 1>&2 "$PRG: Warning: no /etc/yaboot.conf, running yabootconfig to make one"
1562 yabootconfig --noinstall --quiet
1563 if [ $? != 0 ] ; then
1564 echo 1>&2 "$PRG: yabootconfig failed, please supply a valid /etc/yaboot.conf"
1565 echo 1>&2 "$PRG: You may also use $PRG's --boot, --image, --partition, and --device switches"
1566 echo 1>&2 "$PRG: These switches will cause $PRG to generate a basic yaboot.conf on the fly"
1569 CONF=/etc/yaboot.conf
1571 ERR=" Error in $CONF:"
1577 ## Checks if each option was defined on the command line, and if so
1578 ## don't read it from the configuration file. this avoids
1579 ## configuration options from being set null, as well as command line
1580 ## options from being clobbered.
1581 [ "$ARGBT" != 1 -a $(parseconf ck boot) = 0 ] && boot=`parseconf str boot`
1582 [ "$ARGOB" != 1 -a $(parseconf ck ofboot) = 0 ] && ofboot=`parseconf str ofboot`
1583 [ "$ARGBF" != 1 -a $(parseconf ck install) = 0 ] && install=`parseconf str install`
1584 [ "$ARGWP" != 1 -a $(parseconf ck magicboot) = 0 ] && magicboot=`parseconf str magicboot`
1585 [ "$ARGMT" != 1 -a $(parseconf flag usemount) = 0 ] && usemount=yes
1586 [ "$ARGFS" != 1 -a $(parseconf ck fstype) = 0 ] && fstype=`parseconf str fstype`
1587 [ "$ARGBS" != 1 -a $(parseconf flag nobless) = 0 ] && bless=no
1588 [ "$ARGPT" != 1 -a $(parseconf flag protect) = 0 ] && protect=yes
1589 [ "$ARGHD" != 1 -a $(parseconf flag hide) = 0 ] && hide=yes
1590 [ "$ARGNV" != 1 -a $(parseconf flag nonvram) = 0 ] && nonvram=1
1591 [ $(parseconf ck hfstype) = 0 ] && hfstype=`parseconf str hfstype`
1592 [ $(parseconf ck hfscreator) = 0 ] && hfscreator=`parseconf str hfscreator`
1593 [ $(parseconf ck mntpoint) = 0 ] && mntpoint=`parseconf str mntpoint`
1594 [ $(parseconf ck delay) = 0 ] && delay=`parseconf str delay`
1595 [ $(parseconf ck timeout) = 0 ] && timeout=`parseconf str timeout`
1596 [ $(parseconf ck bsd) = 0 ] && bsd=`parseconf str bsd`
1597 [ $(parseconf ck macos) = 0 ] && macos=`parseconf str macos`
1598 [ $(parseconf ck macosx) = 0 ] && macosx=`parseconf str macosx`
1599 [ $(parseconf ck darwin) = 0 ] && darwin=`parseconf str darwin`
1600 [ $(parseconf ck defaultos) = 0 ] && defaultos=`parseconf str defaultos`
1601 [ $(parseconf ck fgcolor) = 0 ] && fgcolor=`parseconf str fgcolor`
1602 [ $(parseconf ck bgcolor) = 0 ] && bgcolor=`parseconf str bgcolor`
1603 [ $(parseconf ck icon) = 0 ] && export YBINOFICON=`parseconf str icon`
1604 [ $(parseconf flag enablecdboot) = 0 ] && cdrom=yes
1605 [ $(parseconf flag enablenetboot) = 0 ] && network=yes
1606 [ $(parseconf flag enableofboot) = 0 ] && of=yes
1607 [ $(parseconf flag brokenosx) = 0 ] && brokenosx=yes
1611 bootparts=$(($bootparts + 1))
1613 if [ "$bootparts" -gt 1 ]; then
1614 [ "$VERBOSE" = 1 ] && echo "$PRG: Iterating through list of boot partitions..."
1617 [ "$VERBOSE" = 1 ] && echo "$ABSPRG $ARGS -b $i"
1618 $ABSPRG $ARGS -b $i || rc=$?
1623 ## ffs!! rtfm! foad!
1624 if [ "$boot" = unconfigured ] ; then
1625 echo 1>&2 "$PRG: You must specify the device for the bootstrap partition. (ie: boot=/dev/hdaX)"
1626 echo 1>&2 "$PRG: Try \`$PRG --help' for more information."
1630 ## if there is still no config file use the automatic generation to make a
1631 ## generic yaboot.conf. do this before the confcheck to avoid wierd errors.
1632 if [ "$bootconf" = /dev/null ] ; then
1633 echo 1>&2 "$PRG: Warning: no yaboot.conf, using generic configuration."
1637 ## mntpoint is incompatible with mkofboot.
1638 if [ "$PRG" = mkofboot -a -n "$mntpoint" ] ; then
1639 echo 1>&2 "$PRG: Cannot be used with \`mntpoint='"
1643 ## validate configuration for sanity.
1646 ## check that we can use ofpath, its only needed for magicboot script
1647 ## building and nvram updates.
1648 if [ -n "$magicboot" -o "$nonvram" = 0 ] ; then
1649 if [ -z "$ofboot" -o -n "$macos" -o -n "$macosx" -o -n "$darwin" ] ; then
1650 if (command -v ofpath > /dev/null 2>&1) ; then
1651 [ -x `command -v ofpath` ]
1652 if [ $? != 0 ] ; then
1653 echo 1>&2 "$PRG: ofpath could not be found, aborting."
1657 echo 1>&2 "$PRG: ofpath could not be found, aborting."
1663 ## if password is set in yaboot.conf make sure permissions on that
1664 ## file are safe, warn if not.
1665 if (grep -q '^[[:space:]]*password[[:space:]]*=' "$bootconf" > /dev/null 2>&1) ; then
1669 ## check if we are root if needed.
1670 if [ "$usemount" = yes -a -z "$mntpoint" ] ; then
1671 if [ `id -u` != 0 ] ; then
1672 echo 1>&2 "$PRG: \`usemount' requires root privileges, go away."
1677 if [ "$fstype" = hfs ] ; then
1679 if [ $? != 0 ] ; then
1680 echo 1>&2 "$PRG: hfsutils is not installed or cannot be found"
1681 echo 1>&2 "$PRG: Try --mount if `uname -sr` supports HFS"
1686 ## convert unix device nodes to OpenFirmware pathnames
1687 if [ -n "$magicboot" -o "$nonvram" = 0 ] ; then
1688 convertpath || exit 1
1691 ## yaboot.conf autogeneration. MUST have secure mktemp to
1692 ## avoid race conditions. Debian's mktemp qualifies.
1693 if [ "$bootconf" = auto ] ; then
1694 TMPCONF=`mktemp -q "$TMP/$PRG.XXXXXX"`
1695 if [ $? != 0 ] ; then
1696 echo 1>&2 "$PRG: Could not create temporary file, aborting."
1701 if [ $? != 0 ] ; then
1702 echo 1>&2 "$PRG: An error occured generating yaboot.conf, aborting."
1709 if [ -n "$magicboot" ] ; then
1710 checkfirststage || exit 1
1711 if [ "$FIRSTSTG" = compat ] ; then
1713 if [ $? != 0 ] ; then
1714 echo 1>&2 "$PRG: An error occured while building first stage loader. aborting..."
1724 if [ "$fstype" = raw ] ; then
1726 raw_install || exit 1
1728 util_install || exit 1
1733 mnt_install || exit 1
1741 ## its not nice to erase the partition and then bail!
1742 if [ "$fstype" = msdos ] ; then
1743 echo 1>&2 "$PRG: mtools support is not implemented"
1744 echo 1>&2 "$PRG: Use --mount or add \`usemount' to $CONF"
1748 if [ "$fstype" = raw ] ; then
1749 raw_install || exit 1
1752 util_install || exit 1
1754 [ "$VERBOSE" = 1 ] && echo "$PRG: Installation complete."
1760 mnt_install || exit 1
1761 [ "$VERBOSE" = 1 ] && echo "$PRG: Installation complete."