#!/bin/sh #DESTDIR=build CONFIGFILE=${DESTDIR}/etc/sgt-puzzles.conf disenable() { game=$1 status=$2 var=DESKTOP$game [ -r $CONFIGFILE ] && . $CONFIGFILE varval="\$$var" varval=`eval "echo $varval"` if [ "$varval" = "$status" ]; then echo "$game is already $status." return fi tempfile=`mktemp -t sgt-puzzles.conf.XXXXXXXXXX` if [ $? -ne 0 ]; then echo "Unable to create temporary file." exit 1 fi if [ -r $CONFIGFILE ]; then grep -v "^${var}\\s*[=]" $CONFIGFILE > $tempfile fi echo "${var}=$status" >> $tempfile mv $tempfile $CONFIGFILE echo "$game $status. Remember to run update." } do_default() { game=$1 var=DESKTOP$game if [ ! -r $CONFIGFILE ]; then echo "$game is already not configured." return fi grep "^${var}\\s*[=]" $CONFIGFILE >/dev/null 2>&1 if [ $? -eq 1 ]; then echo "$game is already not configured." return fi tempfile=`mktemp -t sgt-puzzles.conf.XXXXXXXXXX` if [ $? -ne 0 ]; then echo "Unable to create temporary file." exit 1 fi grep -v "^${var}\\s*[=]" $CONFIGFILE > $tempfile mv $tempfile $CONFIGFILE echo "$game unconfigured. Remember to run update if needed." } do_update() { outdir=${DESTDIR}/usr/share/applications force=0 removeall=0 haslauncher=0 if [ -e ${DESTDIR}/usr/share/sgt-puzzles/has-launcher ]; then haslauncher=1 fi [ -r $CONFIGFILE ] && . $CONFIGFILE if [ "$1" = "force" ]; then force=1 fi if [ "$1" = "removeall" ]; then removeall=1 fi exec 7<${DESTDIR}/usr/share/sgt-puzzles/gameinfo cont=0 while [ $cont -eq 0 ]; do read -u 7 gname && read -u 7 gcommand && read -u 7 gcomment cont=$? if [ $cont -eq 0 ]; then outfile=${outdir}/sgt-puzzles/${gcommand}.desktop var=DESKTOP${gcommand} varval="\$$var" varval=`eval "echo $varval"` if [ $removeall -eq 1 -o "$varval" = "disabled" -o \( $haslauncher -eq 1 -a "$varval" != "enabled" \) ]; then if [ -e $outfile ]; then rm $outfile fi elif [ $force -eq 1 -o ! -e $outfile ]; then cat > $outfile < or: $exename update [force|removeall] The first variant enables or disables the desktop icon for a specific game, or removes configuration for one so that the default is used for that game. The second variant updates the actual desktop files based on the configuration. If the "force" parameter is given, existing desktop files are rewritten; if the "removeall" parameter is given, all the desktop files are removed (until next update). END ;; esac