#! /bin/bash

set -e

case "$1" in
configure)
	if [ -e /usr/sbin/grub-mkconfig ] ; then
		GRUBDEFAULT="/etc/default/grub.d/blorand.cfg"
		if [ -e "$GRUBDEFAULT" ] ; then
			if (grep '^GRUB_BACKGROUND' "$GRUBDEFAULT" > /dev/null 2>&1) ; then
				sed -i 's@^GRUB_BACKGROUND.*$@GRUB_BACKGROUND="/usr/share/blorand/blorand.png"@g' "$GRUBDEFAULT"
			else
				echo 'GRUB_BACKGROUND="/usr/share/blorand/blorand.png"' >> "$GRUBDEFAULT"
			fi
		else
			echo 'GRUB_BACKGROUND="/usr/share/blorand/blorand.png"' >> "$GRUBDEFAULT"
		fi
		/usr/sbin/grub-mkconfig -o /boot/grub/grub.cfg
	fi

	cat /usr/share/blorand/vimrc.blorand | while read line ; do
		if ! grep "$line" /etc/vim/vimrc.local > /dev/null 2>&1 ; then
			echo "$line" >> /etc/vim/vimrc.local
		fi
	done

	install -Dvm 0644 /usr/share/blorand/BLORAND-CA_Root.crt /usr/local/share/ca-certificates/extra/BLORAND-CA_Root.crt
	install -Dvm 0755 /usr/share/blorand/blorand.profile /etc/profile.d/blorand.sh
	/usr/sbin/update-ca-certificates

	;;

	abort-upgrade|abort-remove|abort-deconfigure)
	
	;;

	*)
	echo "postinst called with unknown argument \`$1'" >&2
	exit 0
	;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.



exit 0
