#!/bin/bash
if [ $UID != 0 ]; then
 echo Error: You must be root to run this script!
 exit 1 
fi 

TMPDIR="/tmp/$1.$$-$RANDOM"

stringinstring()
{
  case "$2" in *$1*) return 0;; esac
  return 1
}

function suknoppixmenus
{
  [ "$#" -lt "2" ] && return 1

  supath=$1
  suprog=$2
  
  # This menu entries do not need root-rights
  SU_WHITELIST="configure_xawtv kppp knx-live-inst"
  
  SUTMPDIR="$TMPDIR/suknxmenus"
  mkdir -p $SUTMPDIR

  cp -a $supath/* $SUTMPDIR
  (
  cd $SUTMPDIR
  for i in $(find . -name "*.desktop")
  do
    stringinstring "$(basename ${i/.desktop/})" "$SU_WHITELIST" && continue
    sed 's/Exec=/Exec='$suprog' \-\- /g' $i > $supath/$i
  done
  )

  # Cleanup
  rm -rf $SUTMPDIR
}

suknoppixmenus /usr/share/applnk/KANOTIX kdesu

rm -rf $TMPDIR

echo KANOTIX menu was changed. Do NOT run this script again!
