#!/bin/sh


if [ ! "$1" ]; then
cat <<EOF
Usage: $0 TARGET
where TARGET is the base directory of the system to change

prepares the system under TARGET to be used as the rescue
system. That means it moves important directories to
TARGET/var/ and leaves only symlinks. It also overrides
TARGET/etc/fstab and moves the old fstab to
TARGET/etc/fstab.old, so that system won't boot anymore.
read also doc/README.own_system to get more information.
EOF
    exit 1
fi
    

BASE="$1"
MV_DIRS="etc home root dev tmp"
MK_DIRS="proc isolinux initrd boot var/files usr/lib/varbase"

# These directories will be replaced by symlinks and moved to var/
for DIR in $MV_DIRS; do
    mv "$BASE/$DIR" "$BASE/var/$DIR"
    ln -s "var/$DIR" "$BASE/$DIR"
done

# These directories will be created if they don't exist
for DIR in $MK_DIRS; do
    if ! test -d "$BASE/$DIR"; then
	mkdir "$BASE/$DIR"
    fi
done

# we need a new fstab
mv "$BASE/etc/fstab" "$BASE/etc/fstab.old"
cat << EOF > "$BASE"/etc/fstab
# /etc/fstab: static file system information.
#
# <file system>	<mount point>	<type>	<options>			<dump>	<pass>
proc		/proc		proc	defaults			0	0
/dev/root_dev	/		iso9660	defaults			0	0
EOF

# and finally we touch RESCUECD to identify the rescuecd
touch "$BASE/RESCUECD"

