#
# This script takes care about perms in required dirs.
#
case "${ACTION}" in
post)
	if [ ! -d var/gdm ]; then
		mkdir -p var/gdm
	fi
	chmod 1770 var/gdm
	chown root:gdm var/gdm

	if [ ! -d var/lib/gdm/greeter ]; then
		mkdir -p var/lib/gdm/greeter
	fi
	chmod 0755 var/lib/gdm/greeter
	chown gdm:gdm var/lib/gdm/greeter

	if [ ! -d var/lib/gdm/.config ]; then
		mkdir -p var/lib/gdm/.config
	fi
	chmod 1755 var/lib/gdm/.config
	chown gdm:gdm var/lib/gdm/.config

	if [ ! -d var/lib/gdm/.config/dconf ]; then
		mkdir -p var/lib/gdm/.config/dconf
	fi
	chmod 0755 var/lib/gdm/.config/dconf
	chown gdm:gdm var/lib/gdm/.config/dconf

	if [ ! -d var/lib/gdm/.local/share/applications ]; then
		mkdir -p var/lib/gdm/.local/share/applications
	fi
	chown -R gdm:gdm var/lib/gdm/.local

	if [ ! -d var/cache/gdm ]; then
		mkdir -p var/cache/gdm
	fi
	chmod 1755 var/cache/gdm
	chown root:gdm var/cache/gdm

	if [ ! -d var/log/gdm ]; then
		mkdir -p var/log/gdm
	fi
	chmod 1770 var/log/gdm
	chown gdm:gdm var/log/gdm

	dconf update

	# Use XDG_RUNTIME_DIR for gdm via pam_env(8)
	echo "XDG_RUNTIME_DIR=/tmp/gdm-runtime-dir" > var/lib/gdm/.pam_environment
	;;
esac
