#!/bin/sh

set -e

FILES="Makefile Makefile.vars Makefile.std CONFIG"

if [ "$1" = "" ] ; then
        echo usage: setup mlz-directory-name
        exit 1
fi

dir=$1

# sanity check, we don't want to overwrite anything
for i in $FILES
do
        if [ -f $dir/$i ] ; then
                echo "Sorry, there is already a file called $i in this directory"
                echo "Please remove it before continuing."
                exit 1
        fi
done


# create directory if it does not exist
mkdir -p $dir

# get  midori linux directory

ml=`pwd`
ml=`dirname $ml`
ml=`dirname $ml`
ml=`dirname $ml`
ml=`dirname $ml`
if [ ! -d $ml/cache -o ! -f $ml/Makefile ] ; then
        echo "Cannot find Midori Linux topdir, aborting"
        exit 1
fi

for i in $FILES
do
        sed "s,@MIDORI@,$ml,g" < $i > $dir/$i
done

echo "Your directory $dir is now initialized correctly:"
ls -l $dir
