#!/bin/sh

if [ $# -lt 1 ] ; then 
  echo "Usage: $0 <path to created image>"
  exit 1
fi

image=$1

echo -n "Unpacking initrd... "
gzip -cd < $image > /tmp/initrd.img-$$
mkdir -p /tmp/mnt-initrd-$$
echo "done."
echo "Mounting initrd."
mount -o loop -t ext2 /tmp/initrd.img-$$ /tmp/mnt-initrd-$$
echo "Exit the shell when finished editing."
echo "------------------------------------------------------------------------"

olddir=`pwd`
cd /tmp/mnt-initrd-$$
/bin/bash --login

echo "------------------------------------------------------------------------"
echo "Unmounting initrd."
cd $olddir
umount /tmp/mnt-initrd-$$
echo -n "Packing initrd... "
gzip -9 < /tmp/initrd.img-$$ > $image
echo "done."

rm -rf /tmp/mnt-initrd-$$ /tmp/initrd.img-$$
#echo "Installing new bootsector... "
#/sbin/chos && echo "done."
