#!/bin/bash
#########################################################
# 							#
# This is BashStyle-NG  				#
#							#
# Licensed under GNU GENERAL PUBLIC LICENSE v3    	#
#							#
# Copyright 2007 - 2015 Christopher Bratusek		#
#							#
#########################################################

post_install () {

	if [[ ! ${DISABLE_POSTINSTALL} ]]; then
		post_install_message
		gtk-update-icon-cache -f ${DATADIR}/icons/hicolor 2>/dev/null

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

	thanks_message

}

post_remove () {

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

}

installdirs_create ()
{

	echo -e "\t${WHITE}+${MAGENTA} directories"
	mkdir -p ${DESTDIR}/${DATADIR}
	for directory in ${DATADIR_LIST[@]}; do
		mkdir -p ${DESTDIR}/${DATADIR}/${directory}
	done

	mkdir -p ${DESTDIR}/${LOCALEDIR}
	for directory in ${LOCALEDIR_LIST[@]}; do
		mkdir -p ${DESTDIR}/${LOCALEDIR}/${directory}/
	done

	mkdir -p ${DESTDIR}/${BINDIR}
	mkdir -p ${DESTDIR}/${PROFILEDIR}
	mkdir -p ${DESTDIR}/${ICONDIR}
	mkdir -p ${DESTDIR}/${PCDIR}

}

inst ()
{

	case ${1} in
		data )	MODE=644 ;;
		bin )	MODE=755 ;;
	esac

	shift
	FILE=${1/:*}
	DEST=${1/*:}

	install -m${MODE} ${FILE} ${DESTDIR}${DEST}
	unset FILE DEST

}

install_bsng () {

	echo -e "\t${WHITE}+${YELLOW} data files"
	for file in ${DATA_FILES[@]} ${LOCALE_FILES[@]} \
	${PC_FILES[@]} ${ICON_FILES[@]} ${PROFILE_FILES[@]}; do
		inst data ${file}
	done

	echo -e "\t${WHITE}+${GREEN} executable files"
	for file in ${BIN_FILES[@]}; do
		inst bin ${file}
	done

}

remove_bsng () {

	echo -e "\t${WHITE}+${RED} all files"
	for file in ${REMOVE_FILES[@]}; do
		rm -rf ${file}
	done

}
