All pastes #410723 Raw Edit

Unnamed

public text v1 · immutable
#410723 ·published 2007-03-26 16:54 UTC
rendered paste body
#!/bin/sh

# Script to prepare root device

function die () {
    echo "$@"
    sleep 10
    bless --device `redirect --recovery` --setBoot --nextonly
    reboot
}

function mount() {
    if [ "$1" = "-uw" -o "$1" = "-vat" ]; then
        echo "Skipping $@"
        return 0
    else
        /sbin/mount "$@"
    fi
}


BOOTTYPE=`redirect --boottype`
SCRATCH=`redirect --scratch`
BOOTIDENTIFIER=`redirect --bootidentifier`

MOUNT="/mnt/testmnt"
SEEDSCRATCH="/SeedScratch"

mount -ur /

echo "Boot type is $BOOTTYPE"

if [ $BOOTTYPE != "recovery" -a $BOOTTYPE != "redirected" ]; then
    exit 0
fi

case "$SCRATCH" in
    ram://*)
        SCRATCH=`hdik -nomount -drivekey system-image=yes "$SCRATCH"`
        if [ $? -ne 0 ]; then
            die "Can't create RAM disk"
        fi
        
        newfs_hfs -v Scratch $SCRATCH || die "Can't format scratch partition"
        ;;
esac

mount_hfs $SCRATCH "$MOUNT" || die

if [ -e "$MOUNT/Scratch/.identifier" ]; then
    OLDIDENTIFIER="`cat \"$MOUNT/Scratch/.identifier\"`"
else
    OLDIDENTIFIER=""
fi

if [ -z "$OLDIDENTIFIER" ]; then
    ditto "$SEEDSCRATCH" "$MOUNT/Scratch" || die "Can't copy $SEEDSCRATCH"
    printf "%s" "$BOOTIDENTIFIER" > "$MOUNT/Scratch/.identifier" 
fi

if [ ! -d "$MOUNT/Media" ]; then
    mkdir -p -m 755 "$MOUNT/Media"
    chown 501:501 "$MOUNT/Media"
fi

umount "$MOUNT"
MOUNT="/mnt"
mount_hfs $SCRATCH "$MOUNT" || die "Can't mount $SCRATCH"

osputil -v -g0 -g1 -g2 -g3 -g4 > /var/log/osp.log
if [ $BOOTTYPE == "recovery" ]; then
    mkfstab /dev/disk0s3 /dev/disk0s4 -ro / > /etc/fstab
fi

mount -u "$MOUNT"


if [ -e "/.readwrite" ]; then
	/sbin/mount -uw /
fi

. /etc/rc "$@"