#!/bin/bash
# Copyright 2014 Canonical Ltd.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; version 2.1.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Author: Juhapekka Piiroinen <juhapekka.piiroinen@canonical.com>
# Author: Benjamin Zeller <benjamin.zeller@canonical.com>

SCRIPTPATH=$(dirname $0)
DESKTOPFILE=$1

# lets read the manifest description and set that to desktop comment - fix bug #1223388
MANIFEST_DESCRIPTION=`${SCRIPTPATH}/manifest_description manifest.json`

#lets check if there is a Comment
grep -e "^Comment=.*$" ${DESKTOPFILE}

if [ $? -eq 0 ]
then
#replace the Comment with description from manifest, if it is empty
sed -i "s/^Comment=.*/Comment=${MANIFEST_DESCRIPTION}/g" ${DESKTOPFILE}
else
#add a comment if none is in the desktopfile
echo -e "Comment=${MANIFEST_DESCRIPTION}\n" >> ${DESKTOPFILE}
fi
