#!/bin/sh
#
# --------------------------------------------------------------------------
# Copyright notice
# --------------------------------------------------------------------------
# Copyright: Rene Mayrhofer, Mar. 2000
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING.  If not, write to
# the Free Software Foundation, 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
# On Debian GNU/Linux systems, the complete text of the GNU General
# Public License can be found in `/usr/share/common-licenses/GPL'.
# --------------------------------------------------------------------------
#
mntpoint=/tmp/mnt-bootimg-$$
copy_files_from=/usr/share/mkinitrd-cd

if [ $# -lt 4 ] || ( [ "$1" != "1440" ] && [ "$1" != "2880" ] ); then
  echo "Usage: $0 <image size> <linux kernel> <initrd image> <created image file>"
  echo "where <image size> can be either 1440 or 2880 (in kB)"
  exit 1
fi

size_kb=$1

if [ `id -u` -ne 0 ]; then
  echo "This script must be run as root."
  exit 1
fi

umask 077
set -e

echo -n "Creating image file with FAT file system ($size_kb kB)... "
dd if=/dev/zero of=$4 bs=1024 count=$size_kb >/dev/null 2>/dev/null
mkdosfs $4 >/dev/null 2>/dev/null
syslinux $4
echo "done"

echo -n "Mounting ... "
mkdir $mntpoint
mount -o loop $4 $mntpoint
echo "done"
echo -n "Copying linux kernel ... "
cp $2 $mntpoint/linux
echo "done"
echo -n "Copying initrd image ... "
cp $3 $mntpoint/initrd.bin
echo "done"
echo -n "Copying configuration ... "
cp $copy_files_from/syslinux.cfg $mntpoint
cp /etc/gibraltar-bootcd/bootmsg.txt $mntpoint
echo "done"
umount $mntpoint
rm -rf $mntpoint
