#!/bin/sh

usage()
{
    echo "This tool removes the installed libreoffice* packages"
    echo
    echo "Usage: ${0##*/} [-f/--force] [--clean]"
    echo
    echo "Options:"
    echo -e "\t-f/--force - removes all packages including the templates, thesaurus"
    echo -e "\t\t\tdictionaries, KDE quickstarter..."
    echo -e "\t--clean - clean up the LO-related directories"
}

test "$1" = "-h" -o "$1" = "--help" && usage && exit 0

force=no
test "$1" = "-f" -o "$1" = "--force" && force=yes && shift

clean_installation=no
test "$1" = "--clean" && clean_installation=yes && shift

grep_options="-e OpenOffice_org- -e libreoffice- -e odf-converter"

command="rpm -qa | grep $grep_options"
if test "$force" != "yes" ; then
    command="$command | grep -v -e templates -e thesaurus -e hyphen -e Quickstarter"
fi

for rpm in `eval $command` ; do
    echo "Removing $rpm..."
    rpm -e --nodeps $rpm
done

if test "$clean_installation" = "yes" ; then
    for dir in /usr/lib/ooo-2.0 \
	       /usr/lib64/ooo-2.0 \
	       /usr/share/ooo-2.0 \
	       /usr/lib/ooo3 \
	       /usr/lib64/ooo3 \
	       /usr/share/ooo3 \
	       /usr/lib/libreoffice \
	       /usr/lib64/libreoffice \
	       /usr/share/libreoffice ; do
	echo "Removing $dir..."
	rm -rf $dir
    done
fi
