#!/bin/sh
# Debian maintainer script for sensor-control
#DEBHELPER#

set -e

case "$1" in
	configure)
		# Ensure installed scripts are executable; debhelper usually handles this,
		# but be conservative in case packaging placed files without executable bit.
		if [ -f /usr/bin/sr ]; then
			chmod 0755 /usr/bin/sr || true
		fi
		if [ -f /usr/bin/sc-prototype ]; then
			chmod 0755 /usr/bin/sc-prototype || true
		fi
		if [ -f /usr/bin/sensor-onboard ]; then
			chmod 0755 /usr/bin/sensor-onboard || true
		fi
			# Create log directory for runtime stderr logs and set sensible perms
			if [ ! -d /var/log/sensor-control ]; then
				mkdir -p /var/log/sensor-control || true
			fi
			# Try to set owner to root:adm if the group exists, otherwise root:root
			if getent group adm >/dev/null 2>&1; then
				chown root:adm /var/log/sensor-control || true
			else
				chown root:root /var/log/sensor-control || true
			fi
			chmod 0755 /var/log/sensor-control || true
		;;
	purge|remove|abort-upgrade|disappear)
		;;
	*)
		# Should not be reached, but exit 0 to be safe for future additions
		;;
esac

exit 0
