#!/bin/sh

set -e

GROUP=$(id -g "$USER")
HOMEDIR="/home/$USER"

# this is maily for Debian buster or rather Firefox versions that don't support
# the policies.json file

if [ -e "/usr/share/debian-edu-config/profiles.ini.ff" ]; then
	mkdir -p "$HOMEDIR/.mozilla/firefox/debian-edu.default"
	if [ ! -e "$HOMEDIR/.mozilla/firefox/profiles.ini" ]; then
		cp "/usr/share/debian-edu-config/profiles.ini.ff" "$HOMEDIR/.mozilla/firefox/profiles.ini"
	fi
fi

if [ -e "/usr/share/debian-edu-config/installs.ini" ]; then
	if [ ! -e "$HOMEDIR/.mozilla/firefox/installs.ini" ]; then
		cp "/usr/share/debian-edu-config/installs.ini" "$HOMEDIR/.mozilla/firefox/installs.ini"
	fi
fi

if [ -d "$HOMEDIR/.mozilla" ]; then
	chmod -R u+w,go-rwx "$HOMEDIR/.mozilla/"
	chown -R $USER:$GROUP "$HOMEDIR/.mozilla/"
fi

if [ -e "/usr/share/debian-edu-config/profiles.ini" ]; then
	mkdir -p "$HOMEDIR/.thunderbird/debian-edu.default"
	if [ ! -e "$HOMEDIR/.thunderbird/profiles.ini" ]; then
		cp "/usr/share/debian-edu-config/profiles.ini" "$HOMEDIR/.thunderbird/profiles.ini"
	fi
fi

if [ -d "$HOMEDIR/.thunderbird" ]; then
	chmod -R u+w,go-rwx "$HOMEDIR/.thunderbird/"
	chown -R $USER:$GROUP "$HOMEDIR/.thunderbird/"
fi
