#! /bin/sh

#   postinst - StarOffice 3.1 postinstallation script
#   Copyright (c) by Martin Schulze <joey@orgatech.de>
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   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 General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc.,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

set -e

libdir=/usr/lib/StarOffice-3.1

if [ "$1" = "remove" ]; then
  if [ -d $libdir ]; then
    rm -rf $libdir
  fi

  echo -n "Remove all .sd.c?sh scripts from user directories (y/N)? "
  read ans

  if [ "$ans" = "y" -o "$ans" = "Y" ]; then
      cut -d: -f1,3,6 /etc/passwd|sed 's/:/ /g' \
      | while read user uid dir
	do
	    if [ $uid -gt 1000 ]; then
		test -f $dir/.sd.sh && rm -f $dir/.sd.sh
		test -f $dir/.sd.csh && rm -f $dir/.sd.csh
	    fi
	done
  fi
fi

if [ "$1" = "remove" -o "$1" = "purge" ]; then
  if [ `grep -c '/usr/lib/StarOffice-3.1/linux-x86/lib' /etc/ld.so.conf` -gt 0 ]; then
    grep -v '/usr/lib/StarOffice-3.1/linux-x86/lib' /etc/ld.so.conf > /etc/ld.so.conf.new
    mv -f /etc/ld.so.conf.new /etc/ld.so.conf
  fi
fi

if [ $1 != "upgrade" ]; then
  update-alternatives --remove swriter /usr/bin/swriter3 2> /dev/null
  update-alternatives --remove scalc   /usr/bin/scalc3 2> /dev/null
  update-alternatives --remove schart  /usr/bin/schart3 2> /dev/null
  update-alternatives --remove simage  /usr/bin/simage3 2> /dev/null
  update-alternatives --remove sdraw   /usr/bin/sdraw3 2> /dev/null
  update-alternatives --remove smath   /usr/bin/smath3 2> /dev/null
fi
