#!/bin/bash
# ----------------------------------------------------------------------
# File: eos-uninstall
# Author: Andreas-Joachim Peters - CERN
# ----------------------------------------------------------------------

# ************************************************************************
# * EOS - the CERN Disk Storage System                                   *
# * Copyright (C) 2011 CERN/Switzerland                                  *
# *                                                                      *
# * 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 3 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, see <http://www.gnu.org/licenses/>.*
# ************************************************************************
runtest="yes";

if [ "x$1" = "x--do-cleanup" ]; then
  runtest="no";
fi

echo "# [ to execute the cleaning of the MGM give '--do-cleanup' as option ] ...";

ECHO="echo"
CLEANUP=""

if [ "$runtest" = "no" ]; then
  ECHO=""
  CLEANUP="--do-cleanup"
fi

for name in `rpm -qa | grep ^eos- | grep -v eos-cleanup` ; do 
  echo "# Uninstalling RPM $name ...";
  $ECHO rpm -e $name
done

/usr/sbin/eos-mgm-clean $CLEANUP
/usr/sbin/eos-fst-clean $CLEANUP
/usr/sbin/eos-log-clean $CLEANUP

for name in `rpm -qa | grep ^eos- ` ; do 
  echo "# Uninstalling RPM $name ...";
  $ECHO rpm -e $name
done
