#!/bin/sh

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

image=$1
unpacked=`mktemp`
mntpoint=`mktemp -d`

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

olddir=`pwd`
cd $mntpoint
/bin/bash --login

echo "------------------------------------------------------------------------"
echo "Unmounting initrd."
cd $olddir
umount $mntpoint
echo -n "Packing initrd... "
gzip -9 < $unpacked > $image
echo "done."

rm -rf $unpacked $mntpoint
#echo "Installing new bootsector... "
#/sbin/chos && echo "done."
