#----------------------------------------------------------------------------
# /etc/boot.d/rc100.hdboot
#
# Creation:     2004-06-26 hs
# Last Update:  $Id: rc100.hdboot 10688 2005-12-21 12:10:04Z jw5 $
#----------------------------------------------------------------------------

# search for boot-partition if no boot=... was found in append-line
if [ "$boot" = "" ]
then
    for i in hda1 hdc1 nftla1 sda1
    do
        if [ -n "`grep " $i" /proc/partitions`" ]
        then
            boot=/dev/"$i"
            break
        fi
    done
fi

boot_dev=$boot
boot_fs=vfat

if [ ! "$boot_dev" ] || ! mount -r $boot_dev /boot -t $boot_fs
then
    log_error "unable to mount boot partition $boot_dev, available partitions:"
    cat /proc/partitions | log_error
    stop "can't mount boot-partition, check partitions and drivers"
fi

# do some things for recovery-installation
optbackup=opt2_tar.bz2
rcbackup=rc2.cfg
if [ -f /boot/rc999.recover -a -f /boot/$optbackup -a -f /boot/$rcbackup ]
then
    cp /boot/rc999.recover /etc/rc.d
    recover=start
    . /etc/rc.d/rc999.recover
fi
    
read_config /boot/hd.cfg
read_config /boot/$rcfile

# find swap-partition created with opt_hdinstall typ a or b
grep "$hd_swap" /proc/partitions >/dev/nul
if [ "$?" = "0" -a "$hd_swap" != "" ]
then
    colecho "activating swapspace..." gn
    
    echo "/dev/$hd_swap swap swap defaults 0 0" >> /etc/fstab

    swapon -a
    if [ "$?" != "0" ]
    then
        colecho "ERROR: can't activate swapspace" br x br
        sleep 10        
    fi
fi        

if [ "$hd_opt" = "" -o "$recover" = "active" ]
then        # typ A
    extract_opt /boot/$opt_archive "$unzip_method" "you seem to be out of ram"
    exec_scripts /opt/etc/prep
elif [ -f /boot/$opt_archive ]
then        # typ B, fresh optfile exists
    rm -rf /opt
    rm -rf /files
    mkdir /opt
    echo "/dev/$hd_opt /opt ext3 ro,noatime 0 0" >>/etc/fstab
    e2fsck -p /dev/"$hd_opt"
    mount /opt || stop "can't mount opt-partition, check drivers"
    mount -w -o remount /opt
    cd /opt
    # remove old files first
    rm -rf files etc var
    extract_opt /boot/$opt_archive "$unzip_method" "you seem to be out of ram"
    cd /
    exec_scripts /opt/etc/prep
    mount -r -o remount /opt
    mount -w -o remount $boot /boot
    mv /boot/$opt_archive /boot/opt.old
    /etc/mklinks.sh /opt/files /
    cp -R /opt/etc/* /etc 2>/dev/null
    cp -R /opt/var/* /var 2>/dev/null
else        # typ B, optfile already unpacked
    rm -rf /opt
    mkdir /opt
    echo "/dev/$hd_opt /opt ext3 ro,noatime 0 0" >>/etc/fstab
    e2fsck -p /dev/"$hd_opt"
    mount /opt || stop "can't mount opt-partition, check drivers"
    /etc/mklinks.sh /opt/files /
    cp -R /opt/etc/* /etc 2>/dev/null
    cp -R /opt/var/* /var 2>/dev/null
fi
umount /boot

