#!/bin/sh
#set -e

. kumatux.org-vars

APPDIR=`basename $1`

for DIR in $KUMATUXETCDIRSNOTHIRD
do
    if [ -e $KUMATUXETC/$DIR/$APPDIR.conf ]
    then
        rm $KUMATUXETC/$DIR/$APPDIR.conf
	echo "Deleted $KUMATUXETC/$DIR/$APPDIR.conf"
	DELETED=1
    fi
done

for DIR in $KUMATUXPYTHONVERSIONS
do
    if [ -e $KUMATUXETC/$KUMATUXETCPYTHON/$DIR/$APPDIR.conf ]
    then
        rm $KUMATUXETC/$KUMATUXETCPYTHON/$DIR/$APPDIR.conf
	echo "Deleted $KUMATUXETC/$KUMATUXETCPYTHON/$DIR/$APPDIR.conf"
	DELETED=1
    fi
done

for LINKDIR in $KUMATUXROOTDIRS
do
    for FILE in `ls -l $KUMATUXROOT/$LINKDIR/ | grep $APPDIR | sed 's/ -> .*//' | sed 's/.* //'`
    do
	rm $KUMATUXROOT/$LINKDIR/$FILE
	echo "Deleted $KUMATUXROOT/$LINKDIR/$FILE"
	DELETED=1
    done
done

if [ $DELETED ]
then
    echo "Deleted kumatux.org links for $1"
else
    echo "No kumatux.org links for $1 deleted, as not installed."
fi