#!/bin/sh
# <BEGIN COPYRIGHT>
# This file is part of the "Bad Penguin" GNU/Linux distribution
# Copyright (C) 1997-98-99 by Antonio GALLO aka AGX
# Home Page at ......: http://www.badpenguin.org
# Home Page at ......: http://www.linux.it/~agx/
# e-mail contact ....: mailto:agx@linux.it	mailto:agx@geocities.com
# This program is distributed under the GNU General Public License
# You are not allowed to remove the copyright notice
# <END COPYRIGHT>

# Un-Register a SM into BP
# 2000-01-20, Versione 0.0.1 by AGX

# Parameters Checking
if [ "$1" = "" ]; then
  echoc RED "remove-sessionmanager: Parametri sbagliati"
  exit 1
fi  
SM_NAME="$1"
SM_COMMAND="X"

# DB Check
SMDB="/etc/sysconfig/SESSION-MANAGERS"
if [ ! -f "$SMDB" ]; then
  >"$SMDB"
fi

# Temps
TEMPDIR="$HOME/tmp"
[ ! -d $TEMPDIR ] && mkdir -p $TEMPDIR
TEMPSCRIPT=$TEMPDIR/tempscript.$$
TEMPDATA=$TEMPDIR/tempdata.$$
trap 'rm -f $TEMPSCRIPT $TEMPDATA ; exit $USCITA' 0


# Un-Register Session Manager
grep  "^$SM_NAME:"  "$SMDB"  >$TEMPSCRIPT  2>/dev/null
if [ $? -eq 0 ]; then
  SM_COMMAND=`cat $TEMPSCRIPT | cut -f 2 -d ':'`
  echoc GREEN "- Rimuovo le informazioni sul Session Manager $SM_NAME"
  grep  -v  "^$SM_NAME:"  "$SMDB"  >/tmp/wmgrep
  mv  "/tmp/wmgrep"  "$SMDB"

  grep -q "$SM_COMMAND"  "$HOME/.WINDOSMANAGER"
  if [ $? -eq 0 ]; then
    echoc CYAN "- $SM_NAME non e' piu' il SM predefinito."
    rm -f $HOME/.WINDOSMANAGER
  fi
else
  echoc CYAN "- Session Manager $SM_NAME non registrato."
  exit 0
fi
