#!/bin/sh
#DEBHELPER#

set -e

if [ "$1" = configure ]; then
    # Find out any desktop file which refers to the old prism-firstpersontetris and write
    # them over with our own
    # try with locatedb first
    files=
    if [ $(command -v locate) ] && locate -c '*-favorite-*.desktop' >/dev/null 2>&1; then
        files=$(locate '*-favorite-*.desktop')
    # no locatedb, try brute force
    else
        # If no files ar found, ls will error out and fail the whole
        # script. Only do the ls check if it's guaranteed to find at least
        # something.
        if [ -e /home/*/.local/share/applications/*-favorite-*.desktop ]; then
            files=$(ls /home/*/.local/share/applications/*-favorite-*.desktop)
        fi
    fi

    # replace content with the new one
    for file in $files ; do
        if [ -r $file -a -w $file ] && grep -q Exec=prism-firstpersontetris $file ; then
            cat /usr/share/applications/jolicloud-webapp-firstpersontetris.desktop > $file
            sed -i -e 's/^Categories=.*/Categories=Favorites/' $file
        fi
    done
fi

exit 0
