#!/bin/sh -ex

check_mod() {
	mod=$1 ; shift
	own=$1 ; shift

	echo "Checking file or directory $@ for mod $mod and owner $own"
	if [ -d "$@" -o -f "$@" ] ; then
		chmod $mod "$@"
		chown $own "$@"
	fi
}

enable() {
	local _app

	for _app in agent alerting ; do
		if ! /bin/systemctl enable yandex-solomon-${_app} ; then
			echo "Cannot enable ${_app} service!"
		fi
	done
}

case "$1" in
	configure)
		check_mod 755 user_alerting:group_solomon /Berkanavt/solomon/alerting
		enable
	;;
esac
