#!/bin/sh
. /etc/xensource-inventory

if [ -z "$OEM_BUILD_NUMBER" ] ; then
    # Retail edition - use method employed by install.img
    
    # name of new file contains timestamp to distinguish it
    initrd=initrd-$(uname -r).$(date +%s).img

    symlink=/boot/initrd-2.6-xen.img
    /sbin/mkinitrd --theme=/usr/share/citrix-splash --with ide-generic /boot/$initrd $(uname -r)

    # point symlink at the new initrd 
    ln -sf $initrd $symlink
else
    # OEM edition - use method employed by recovery.img

    # name of new file contains timestamp to distinguish it
    initrd=initrd-$(uname -r).$(date +%s).img

    symlink=/boot/initrd

    # remount /boot as rw
    mount -o remount,rw /boot || {
	echo "failed to remount /boot - is this a flash install?" >&2
	echo "$0 only supported on hard disk installations" >&2
	exit 1
    }

    # get root device from kernel command line
    ROOTDEV=$(cat /proc/cmdline | sed -ne 's/^.*root=\([^ ]*\) .*$/\1/p')

    # fake an fstab to tell mkinitrd it needs to access this disk
    tmpfstab=$(mktemp /tmp/fstab-XXXXXXXX)
    echo "${ROOTDEV}  /  ext3  defaults,ro  0  0" > $tmpfstab
    /sbin/mkinitrd --theme=/usr/share/citrix-splash --fstab=$tmpfstab \
	--with=usb-storage --with=ext3 --with=zlib_inflate --with=squashfs --shell=tash /boot/$initrd $(uname -r)

    rm -f $tmpfstab

    # point symlink at the new initrd 
    [ -e $symlink ] && [ ! -L $symlink ] && mv -f $symlink $symlink.orig
    ln -sf $initrd $symlink

    # remount /boot as ro again
    mount -o remount,ro /boot
fi

