#!/bin/sh
# MapList v1.0 (linux) - By Toby Reed <toby@eskimo.com> [GNU Public License]

# Set MAPDIR to the Quake map directory, and MAPFILE to the database file,
# an executable quake config file, type "exec ml.cfg".

MAPDIR=/usr/games/quake/id1/maps
MAPFILE=/usr/games/quake/id1/ml.cfg

# Uncomment this to send output to STDOUT instead.
#DEBUG=/dev/tty

# No user-servicable parts below:

VERSION=1.0

if [ $DEBUG ]; then
  MAPFILE=$DEBUG
fi
echo -n MapList - Updating Map Database ...
if [ ! -d $MAPDIR ]; then
	echo
	echo Cannot find the ID1\\MAPS directory.
	exit 1
fi
echo "// MapList Map Database (ml-linux $VERSION)" > $MAPFILE
echo -n "alias ml \"echo " >> $MAPFILE
if [ -z "`find $MAPDIR -type f | grep .bsp`" ]; then
	echo no maps.\" >> $MAPFILE
	exit 1
fi
ls $MAPDIR | grep .bsp | sed "s/\*//g" | cut -d. -f1 | xargs echo -n >> $MAPFILE
echo -n \" >> $MAPFILE
echo
exit 0
