#!/bin/bash


ACTION="$1"
shift

PACKAGE_LIST=$@
EXTRA_PACKAGES=pcaputils,cdc-mapper-wireshark

case $ACTION in
	remove)
		for ix in $PACKAGE_LIST	
		do
			apt-get remove -y $ix
			TEST=$( dpkg-query -s  $ix 2> /dev/null| grep Status | cut -d " " -f 4 )
			if [ "$TEST" == 'installed' ];then
				exit 1

			else
				apt-get remove -y wireshark-common wireshark-qt 2>/dev/null  || true
				apt-get remove -y ${EXTRA_PACKAGES/,/ /} 2>/dev/null  || true
			fi
		done
	;;	
	postInstall)
		echo "[EPI]:Checking permission group..."
		if dpkg -s wireshark &>/dev/null ; then
			apt-get install -y ${EXTRA_PACKAGES/,/ /}
		fi
	;;	
esac	

