#!/bin/bash
#
# convert-config
#
# --------------------------------------------------------------------------
# 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 [ $# -ne 2 ] ; then
  echo "Usage: $0 <old config image> <new config mountpoint>"
  exit 1
fi

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

umask 077
set -e

oldimage=$1
mountpoint=$2

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

# if /etc is mounted, umount it first
umount /etc >/dev/null 2>/dev/null || true
# the same for the temporary mountpoint
umount $temp_mntpoint >/dev/null 2>/dev/null || true

if [ "$VERBOSE" = "yes" ]; then
  echo "Unpacking configuration data in old format."
fi
# the old configuration dat ais unpacked to a temporary folder
restore-etc-old $oldimage $temp_mntpoint 1

echo -n "Creating configuration RAM disk in new format (no size limit)... "
mount_tmpfs_without_sizelimit $mountpoint
cp -a $temp_mntpoint/* $mountpoint
echo "done"

if [ "$VERBOSE" = "yes" ]; then
  echo "Unmounting old configuration data."
fi
umount $temp_mntpoint

exit 0
