#!/usr/bin/env bash

## Creates an initial mtmock.conf and tries to set the
## SCRIPTDIR and WORLDDIR members.
SCRIPTDIRS="/usr/share/games/minetest/builtin /usr/share/minetest/builtin"
WORLDDIRS=$HOME/.minetest/worlds

for sd in ${SCRIPTDIRS}; do
    if [ -d $sd ]; then
        SCRIPTDIR=$sd
        break
    fi
done

for wd in ${WORLDDIRS}; do
    if [ -d $wd ]; then
        WORLDDIR=$wd
        break
    fi
done

if [ -z "${SCRIPTDIR}" ]; then
    echo "*** $(basename $0): cannot find minetest LUA script directory" >>/dev/stderr
    exit 1
elif [ -z "${WORLDDIR}" ]; then
    echo "*** $(basename $0): cannot find minetest world directory" >>/dev/stderr
    exit 2
fi

cat >mtmock.conf <<-EOF
	-- path to minetest's builtin LUA scrips
	mtmock.SCRIPTDIR='${SCRIPTDIR}/'

	-- path to minetest's worlds
	mtmock.WORLDDIR='${WORLDDIR}/'

	-- path to mods
	mtmock.MODDIR='$(realpath ../mods)/'
EOF

