#!/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'.
# --------------------------------------------------------------------------
#

# customize here

# do not edit below this line
# =================================================

if [ $# -ne 3 ] ; then
  echo "Usage: $0 <image name> <mountpoint> <ramdisk device number>"
  exit 1
fi

. /usr/lib/gibraltar-bootsupport/common-definitions.sh

umask 077
set -e

image=$1
mountpoint=$2
ramdevnumber=$3

# first determine the size of the uncompressed etc image - this will be the
# size that is needed for the ramdisk
temp=`gzip -l $image | grep -v "compressed"`
set $temp
ramdisk_size=`expr $2 / 1024 + 1`

echo -n "Mounting a RAM disk as $mountpoint ($ramdisk_size kb)... "
# the etc image already contains an ext2 filesystem - simply copy it onto the
# ramdisk and mount it to the mountpoint
gzip -cd < $image > "${ramdisks}${ramdevnumber}"
if ! mount -n -t ext2 "${ramdisks}${ramdevnumber}" $mountpoint; then
  echo "Error during mounting."
  exit 1
fi
echo "done."

exit 0
