#!/bin/sh
set -e

log_debug() {
	echo "Debug: piuparts exception for package $PIUPARTS_OBJECTS"
}

if [ "$PIUPARTS_DISTRIBUTION" = "squeeze" ]; then

	case ${PIUPARTS_OBJECTS%%=*} in
		linpopup)
			# package removed after lenny
			log_debug
			for file in /var/lib/linpopup/messages.dat
			do
				test ! -f "$file" || chmod -c o-w "$file"
			done
			;;
	esac

fi

if [ "$PIUPARTS_DISTRIBUTION" = "wheezy" ]; then

	case ${PIUPARTS_OBJECTS%%=*} in
		kismet|\
		tshark|\
		wireshark|\
		wireshark-common|\
		wireshark-dbg|\
		libcap2-bin)
			# libcap2-bin/wheezy is part of the minimal chroot and recommends libpam-cap
			# a conffile moved from libcap2-bin/squeeze to libpam-cap/wheezy
			log_debug
			apt-get install -yf libpam-cap
			;;
		phpgacl)
			# #682825
			# package not in wheezy
			log_debug
			for dir in /usr/share/phpgacl/admin/templates_c
			do
				test ! -d "$dir" || chmod -c o-w "$dir"
			done
			;;
	esac

fi

if [ "$PIUPARTS_DISTRIBUTION" = "jessie" ]; then

	# base-files only upgrades pristine /etc/nsswitch.conf
	if grep -q ^gshadow: /etc/nsswitch.conf ; then
		echo "Removing gshadow line from /etc/nsswitch.conf"
		sed -i /^gshadow:/d /etc/nsswitch.conf
	fi

fi
