#! /bin/sh

set -e

[ "$DEBIAN_FRONTEND" = "gtk" ] || exit 0

THEME="$1"
CONFFILE="/etc/gtk-2.0/gtkrc"

[ -n "$THEME" ] || exit 1
[ -f "$CONFFILE" ] || exit 1

#TODO: test that theme actually exists

logger -t gtk-set-theme "Switching to theme '$THEME'"
if grep -q "^gtk-theme-name" $CONFFILE ; then
	sed -i "s/^gtk-theme-name.*$/gtk-theme-name = \"$THEME\"/" $CONFFILE
else
	echo "gtk-theme-name = \"$THEME\"" >>$CONFFILE
fi

# For the accessibility theme the font size is increased
gtk-set-font || true

exit 0
