Path : /var/lib/dpkg/info/
File Upload :
Current File : /var/lib/dpkg/info/ds-agent.prerm

#!/bin/sh

# Do not stop them if this is an upgrade (Please sync behavior with rpm.)
if [ "$1" = "remove" ] ; then
	# cannot uninstall agent if self-protection is running
	if [ -f "/proc/driver/bmhook/self_protection/dump" ]; then
		val=`grep Enable /proc/driver/bmhook/self_protection/dump | awk '{print $2}'`
		if [ $? -eq 0 ] && [ $val -eq 1 ]; then
			echo "Please stop self-protection before uninstall ds-agent"
			exit 1
		fi
	fi

	if [ -x "/etc/init.d/ds_agent" ]; then
		if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
			invoke-rc.d ds_agent stop || exit $?
		else
			/etc/init.d/ds_agent stop || exit $?
		fi
	fi

	if [ -f "/usr/lib/systemd/system/ds_agent.service" ]; then
		/bin/systemctl stop ds_agent
		/bin/systemctl disable ds_agent
	fi

	/opt/ds_agent/dsa -a uninstall -w /var/opt/ds_agent -e /opt/ds_agent/ext
	#try to remove ports that might have been left open on iptables
	lsmod | grep -e 'ip6\?table_filter' > /dev/null
	if [ $? -eq 0 ]; then
		for port in `cat /var/opt/ds_agent/OpenPorts 2>/dev/null`; do
			iptables -D INPUT -j ACCEPT -m state --state NEW --proto tcp --dport $port > /dev/null
		done
	fi
	#try to remove ports that might have been left open on firewalld
	firewall-cmd --state 2>&1 | grep "^running" > /dev/null
	if [ $? -eq 0 ]; then
		for port in `cat /var/opt/ds_agent/OpenPorts_firewalld 2>/dev/null`; do
			firewall-cmd --zone=public --remove-port  $port/tcp > /dev/null
		done
	fi
	
	rm -rf /opt/ds_agent /var/opt/ds_agent /var/log/ds_agent
	lsmod | grep -m1 acdc > /dev/null
    if [ $? = 0 ]; then 
        rmmod acdc
    fi
fi