#!/bin/sh
INSTDIR="$1"

sed s#_path_#"$INSTDIR"#g -i "$INSTDIR/etc/camd_3.908.emu"
sed s#_path_#"$INSTDIR"#g -i "$INSTDIR/bin/camd_3.908.emu"

if [ "/mnt/swapextensions" == "$INSTDIR" ]; then
	sed s#_type_#"MNT"#g -i "$INSTDIR/etc/camd_3.908.emu"
elif [ "/var/swap" == "$INSTDIR" ]; then
	sed s#_type_#"SWAP"#g -i "$INSTDIR/etc/camd_3.908.emu"
else
	sed s#_type_#"VAR"#g -i "$INSTDIR/etc/camd_3.908.emu"	
fi

if [ ! -e "$INSTDIR/keys/camd3.config" ]; then
	echo "use ipk config file: camd3.config"
	echo "rename $INSTDIR/keys/camd3.config.camd3 > $INSTDIR/keys/camd3.config"
	mv -f "$INSTDIR/keys/camd3.config.camd3" "$INSTDIR/keys/camd3.config"
else
	echo "found user config file: camd3.config"
	echo "skip ipk config file: camd3.config.camd3"
fi

if [ ! -e "$INSTDIR/keys/camd3.keys" ]; then
	echo "use ipk config file: camd3.keys"
	echo "rename $INSTDIR/keys/camd3.keys.camd3 > $INSTDIR/keys/camd3.keys"
	mv -f "$INSTDIR/keys/camd3.keys.camd3" "$INSTDIR/keys/camd3.keys"
else
	echo "found user config file: camd3.keys"
	echo "skip ipk config file: camd3.keys.camd3"
fi

if [ ! -e "$INSTDIR/keys/camd3.servers" ]; then
	echo "use ipk config file: camd3.servers"
	echo "rename $INSTDIR/keys/camd3.servers.camd3 > $INSTDIR/keys/camd3.servers"
	mv -f "$INSTDIR/keys/camd3.servers.camd3" "$INSTDIR/keys/camd3.servers"
else
	echo "found user config file: camd3.servers"
	echo "skip ipk config file: camd3.servers.camd3"
fi

if [ ! -e "$INSTDIR/keys/camd3.users" ]; then
	echo "use ipk config file: camd3.users"
	echo "rename $INSTDIR/keys/camd3.users.camd3 > $INSTDIR/keys/camd3.users"
	mv -f "$INSTDIR/keys/camd3.users.camd3" "$INSTDIR/keys/camd3.users"
else
	echo "found user config file: camd3.users."
	echo "skip ipk config file: camd3.users.camd3"
fi

exit 0