#!/bin/sh
#
# --------------------------------------------------------------------------
# Copyright notice
# --------------------------------------------------------------------------
# Copyright: Rene Mayrhofer, Sep. 2001
#
# 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'.
# --------------------------------------------------------------------------
#

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

if [ $# -lt 2 ] || [ $# -gt 3 ]; then
  echo "Usage: $0 <saved config filename> <mountpoint> [<maximum ramdisk size>]"
  exit 1
fi

. /etc/default/common-definitions.sh

umask 077
set -e

image=$1
mountpoint=$2

# check the syntax of the size string
check_disk_size_string $ETCDISK_SIZE ETCDISK_SIZE

if [ -n "$3" ]; then
  check_disk_size_string $3 ""
  ETCDISK_SIZE="$3"
fi

echo -n "Creating configuration ramdisk and unpacking saved data to it (maximum ${ETCDISK_SIZE}b)... "
mount_tmpfs $ETCDISK_SIZE $mountpoint
pushd $mountpoint > /dev/null
tar xz --preserve --same-owner -f $image
popd > /dev/null
echo "done"

# now remount the ramdisk, applying the maximum size setting from the newly
# loaded configuration data
. /etc/default/common-definitions.sh
remount_tmpfs $ETCDISK_SIZE $mountpoint

exit 0
