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

post_install () {
	if [[ ! ${DISABLE_POSTINSTALL} ]]; then
		post_install_message
		gtk-update-icon-cache -q -f "${PREFIX}"/share/icons/hicolor
	fi
}

post_remove () {
	echo -n
}

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}/${ICONDIR}"
	mkdir -p "${DESTDIR}/${PCDIR}"
	mkdir -p "${DESTDIR}/${DOCDIR}"
	mkdir -p "${DESTDIR}/${DESKTOPDIR}"
	mkdir -p "${DESTDIR}/${MANDIR}"
}

inst ()
{
	case ${1} in
		bin )	MODE=755 ;;
		* )	MODE=644 ;;
	esac

	FILE=${2/:*}
	DEST=${2/*:}

	if [[ ${1} == man ]]; then
		install -m"${MODE}" ${FILE}.gz "${DESTDIR}/${DEST}"
	else
		install -m"${MODE}" ${FILE} "${DESTDIR}/${DEST}"
	fi

	unset TYPE FILE DEST
}

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

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

	echo -e "\t${WHITE}+${CYAN} documentation and manual pages"
	for file in "${DOC_FILES[@]}"; do
		inst doc "${file}"
	done
	for file in "${MAN_FILES[@]}"; do
		inst man "${file}"
	done
}

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