#! /bin/bash
# ********************************************************************************************* 
# IRA Istituto di Radioastronomia                                                                      
#
# This code is under GNU General Public Licence (GPL).                                              
#                                                                                                     
# Who                                when            What                                             
# Andrea Orlati(aorlati@ira.inaf.it) 12/02/2011      Creation                
# Andrea Orlati(aorlati@ira.inaf.it) 11/01/2013      Adapted to environment of escs 0.3                  
#************************************************************************
#   NAME
#		removeObserver
# 
#   SYNOPSIS
# 
#   DESCRIPTION
#   This script removes a user for the observing system. It could be executed only by the system manager on the user server machine.
#   The manager must have sudoers grants for bash commands userdel. For that reason it is recommended to create 
#   the sudoers grants for manager on user server machine only.
#	
#   FILES
#
#   ENVIRONMENT
#
#   RETURN VALUES
#
#   CAUTIONS
#
#   EXAMPLES
#
#   SEE ALSO
#
#   BUGS     
#

function printUsage {
   echo "Removes a user/project from the ESCS observing system"
   echo ""
        echo "Usage: `basename $0` userid  "
}

if [ ! -n "$1" ]
then
   printUsage
   exit
fi

read -p "remove project "$1" and all its related files?" yn
case $yn in
	[Yy]* ) echo "removing.....";;
	* ) echo "bye!"; exit;;
esac
sudo /usr/sbin/userdel -r $1
rm -rf /archive/data/$1
rm -rf /archive/schedules/$1
rm -rf /archive/extraData/$1
echo "done!"
echo "update yellow pages......"
sudo /usr/lib/yp/ypinit -m
sudo /sbin/service ypserv restart
echo "deleted!"
