#!/bin/sh
if [ $(id -u) != 0 ]; then
 echo Error: You must be root to run this script! >&2
 exit 1
fi
DIR=KANOTIX
FILE=KANOTIX
USER=kanotix
TARGET=/dev/hda3
#TARGET=/dev/sda8
FS=ext3
#BUILD=/dev/hda6
if [ ! -e $DIR/$FILE ]; then
 echo Error: $DIR/$FILE not found. >&2
 echo Please mount cdrom/iso and change to that dir. >&2
 exit 2
fi
if grep -q ^cloop /proc/modules; then
 echo Error: cloop module already used.
 exit 3
fi
umount $TARGET
mkfs -t $FS $TARGET || exit 4
rm -rf /dev/cloop
mknod /dev/cloop b 240 0
#modprobe cloop file=$(pwd)/$DIR/$FILE
mkdir -p /mnt/cloop /mnt/target
#mount -o ro /dev/cloop /mnt/cloop
mount -o loop,ro -t squashfs $(pwd)/$DIR/$FILE /mnt/cloop
mount $TARGET /mnt/target
cd /mnt/cloop
cp -av . /mnt/target
if [ $BUILD ]; then
 mkdir -p /mnt/target/KANOTIX.build
else
 ln -s / /mnt/target/KANOTIX.build
fi
mkdir -p /mnt/target/home/$USER /mnt/target/proc
chown -R 1000.1000 /mnt/target/home/$USER
echo $TARGET / $FS defaults 0 1 >/mnt/target/etc/fstab
[ $BUILD ] && echo $BUILD /KANOTIX.build $FS defaults 0 0 >>/mnt/target/etc/fstab
echo
cd -
umount /mnt/cloop
umount /mnt/target
rm -rf /mnt/cloop /mnt/target
#rmmod cloop
