#!/bin/bash

DESKTOP2ICEWM=desktop2icewm

if [ -d ~/.icewm ]; then 
    ICECONFIG=~/.icewm
else
    ICECONFIG=/etc/icewm
fi
if [ ! -d $ICECONFIG ]; then
    mkdir -p $ICECONFIG
fi

for i in Office Network Multimedia Graphics Games Utilities System
do
  if [ -f $ICECONFIG/$i ]; then
    mv $ICECONFIG/$i $ICECONFIG/$i.bak
  fi
done

for file in /usr/share/applications/*; do
    if [ -e $file ]; then
	TYPE=`grep -ie 'Categories=' $file | cut -d';' -f 1-4`
	case $TYPE in 
	    *Office*)
		    $DESKTOP2ICEWM $file >> $ICECONFIG/Office
		;;
	    *Network*)
		    $DESKTOP2ICEWM $file >> $ICECONFIG/Network
		;;
	    *AudioVideo*)
		    $DESKTOP2ICEWM $file >> $ICECONFIG/Multimedia
		;;
	    *Graphics*)
		    $DESKTOP2ICEWM $file >> $ICECONFIG/Graphics
		;;
	    *Games*)
		    $DESKTOP2ICEWM $file >> $ICECONFIG/Games
		;;
	    *Game*)
		    $DESKTOP2ICEWM $file >> $ICECONFIG/Games
		;;
	    *Settings*)
		    $DESKTOP2ICEWM $file >> $ICECONFIG/System
		;;
	    *System*)
		    $DESKTOP2ICEWM $file >> $ICECONFIG/System
		;;
	    *Panel*|*Action*)
		    #$DESKTOP2ICEWM $file >> ~/.icewm/Panel
		;;
	    *)
		    $DESKTOP2ICEWM $file >> ~/.icewm/Utilities
		;;
	esac
    fi
done
