#!/bin/bash

update_cache () {

	gtk-update-icon-cache -f $PREFIX/share/icons/hicolor 2>/dev/null

}

remove_cruft () {

	rm -rf $DESTDIR/$PREFIX/share/bashstyle-ng/rc/bin/

	if [[ -e /etc/profile.d/bashstyle.sh ]]; then
		rm /etc/profile.d/bashstyle.sh
	fi

}

add_bsng_init () {

	if [[ ! $BASHFILE ]]; then
		if [[ -e /etc/bash.bashrc ]]; then
			BASHFILE=/etc/bash.bashrc
		else
			BASHFILE=/etc/bashrc
		fi
	fi

	if [[ $(grep "bashstyle.sh" ${BASHFILE}) == "" ]]; then
		echo "source ${PROFILEDIR}/bashstyle.sh" | sed -e 's,//,/,g' >> ${BASHFILE}
	fi

}

post_remove () {

	if [[ ! $BASHFILE ]]; then
		if [[ -e /etc/bash.bashrc ]]; then
			BASHFILE=/etc/bash.bashrc
		else
			BASHFILE=/etc/bashrc
		fi
	fi

	if [[ $(grep "bashstyle.sh" ${BASHFILE}) != "" ]]; then
		sed -e '/bashstyle.sh/d' -i ${BASHFILE}
	fi

}

post_install () {

	if [[ ! $DISABLE_POSTINSTALL ]]; then

		echo -e "\t${WHITE}+ ${WHITE} post-installation tasks"
		update_cache
		remove_cruft
		add_bsng_init
		echo -e "\n${CYAN}Thanks for choosing BashStyle-NG!\n"

	fi

}
