#!/bin/bash
#
#	FarSync WAN driver for Linux
#
#	Software removal script
#
#	Copyright (C) 2008 FarSite Communications Ltd.
#	www.farsite.co.uk
#
#	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.
#
#	File:	uninstall
#	Author:	K.P. Curtis	<kevin.curtis@farsite.co.uk>
#
#	Revision history at end of file
#

PATH=/sbin:/usr/sbin:/usr/local/sbin:/bin:/usr/bin

KERNEL_DIR=/usr/src/linux
COMPNY_DIR=/etc/farsite
CONFIG_DIR=$COMPNY_DIR/farsync
DOWNLD_DIR=$COMPNY_DIR/downloads

cat <<EOF

       FarSync WAN driver for Linux removal

       Copyright (C) 2001-2008 FarSite Communications Ltd.

       Removing installed files,  Please wait.

EOF


if [ ! "`id -u`" = "0" ]
then
	echo Sorry you must be root to run this script
	exit 1
fi
sleep 3

echo " FarSync Drivers and any Kernel patches applied will remain in place"
sleep 1

echo "Stopping the drivers"
/etc/init.d/farsync stop

echo " Removing FarSync configuration scripts"
rm -rf /etc/ppp/ppp-on
rm -rf /etc/ppp/ppp-off
rm -rf /etc/ppp/options.tty_hdlc*
rm -rf /etc/ppp/options.tty_sync*
rm -rf $CONFIG_DIR/ifcfg-hdlc*
rm -rf $CONFIG_DIR/ifcfg-sync*
rm -rf $CONFIG_DIR/ifcfg-pvc*
rm -rf $CONFIG_DIR/ifup-hdlc
rm -rf $CONFIG_DIR/ifup-pvc
rm -rf $CONFIG_DIR/ifdown-pvc
rm -rf $CONFIG_DIR/farifup
rm -rf $CONFIG_DIR/farifdown
rm -rf $CONFIG_DIR/ifup-sync
rm -rf $COMPNY_DIR
sleep 1

echo " Removing farutil command"
rm /sbin/farutil
rm /sbin/farmon
rm /usr/share/man/man8/farutil.8
rm /sbin/fardsl
sleep 1

echo " Removing init scripts"
# Divide distros into Red Hat like and non-RH (Debian)
if [ -a /etc/rc.d/init.d/farsync ]
then
    INITBASE=/etc/rc.d/init.d
else
    INITBASE=/etc/init.d
fi

${INITBASE}/farsync stop
if [ -f /etc/sysconfig/network-scripts/ifup ]
then
	DS=rh
	echo
	echo Network configuration is Red Hat like
	sleep 1

else
	DS=db
	echo
	echo "Network configuration is non-Red Hat like (possibly Debian like)"
	sleep 1

fi

if [ -x /sbin/chkconfig ]
then
        #
        # We are a RH like distro so chkconfig should work to set
        # up the init scripts
        #
        echo "last minute check for debian/ubuntu"
        if [ -f /etc/debian_version ]
        then
            update-rc.d -f farsync remove
        else
            chkconfig --del farsync
        fi

else 
        if [ -x /sbin/insserv ]
        then
                #
                # We are most definitely SuSe so use insserv to set
                # up the init scripts
                #
		SYSVBASE=/etc
        else
                #
                # No RH or SuSe, so just setup the init scripts manually
                #
		if [ -d /etc/rc0.d ]
		then
		    SYSVBASE=/etc
		else
		    SYSVBASE=/etc/rc.d
		fi
                echo Base for init scripts calculated as $SYSVBASE 
		rm $INITBASE/farsync
                rm -f $SYSVBASE/rc?.d/K??farsync $SYSVBASE/rc?.d/S??farsync
	fi
fi
${INITBASE}/farsync stop
rm ${INITBASE}/farsync*
rm -f ${INITBASE}/rc?.d/K??farsync ${INITBASE}/rc?.d/S??farsync
rm -f ${SYSVBASE}/rc?.d/K??farsync ${SYSVBASE}/rc?.d/S??farsync
sleep 1

echo " Removal complete"

#
#	Revision History
#	$Log: uninstall,v $
#	Revision 1.2  2009/12/17 11:31:54  kevinc
#	Make the release version 1.09.05 - build 143
#	
#	Revision 1.1.1.1  2009/05/06 12:45:30  kevinc
#	
#	
#	Revision 1.6  2008/07/09 08:58:29  kevinc
#	Changes to the install process to make extra checks that all the required components are present
#	
#	Revision 1.5  2008/03/04 14:55:03  kevinc
#	Update for 1.07.10
#	
#	Revision 1.4  2005/05/17 13:01:33  kevinc
#	Release 1.05
#	
#	Revision 1.3  2003/11/14 16:39:08  kevinc
#	Minor typo
#	
#	Revision 1.2  2003/10/27 10:32:56  kevinc
#	Removed some more files that should have been left behind
#	---------------------------------------------------------------------------
#	
#	Revision 1.1  2003/10/21 08:25:29  kevinc
#	New file (and feature)

