#!/bin/bash

inst ()
{

	case $1 in
		data )
			MODE=644
		;;

		bin )
			MODE=755
		;;
	esac

	shift

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

	if [[ $VERBOSE == "true" ]]; then
		echo -e "\t${WHITE}  * ${SMOOTHBLUE}[$2/$3]${WHITE} ${FILE}"
	fi
	install -m${MODE} ${FILE} ${DESTDIR}${DEST}

	unset FILE DEST

}

uninst ()
{

	xFILE=${1/:*}
	FILE=${xFILE/*\/}
	DEST=${1/*:}

	rm -rf ${DESTDIR}${DEST}/${FILE}

	unset FILE DEST

}

install_bsng () {

	if [[ $VERBOSE == "true" ]]; then
		DATA_NUM=0
		for num in ${#DATA_FILES[@]} ${#LOCALE_FILES[@]} ${#DOC_FILES[@]} \
		${#PC_FILES[@]} ${#ICON_FILES[@]}; do
			DATA_NUM=$(($DATA_NUM+$num))
		done
		local CUR_NUM=1
	fi

	echo -e "\t${WHITE}+ ${WHITE} data files"
	for file in ${DATA_FILES[@]} ${LOCALE_FILES[@]} ${DOC_FILES[@]} \
	${PC_FILES[@]} ${ICON_FILES[@]}; do
		if [[ $VERBOSE == "true" ]]; then
			inst data "$file" $CUR_NUM $DATA_NUM
			local CUR_NUM=$(($CUR_NUM+1))
		else 	inst data "$file"
		fi
	done

	if [[ $VERBOSE == "true" ]]; then
		BIN_NUM=0
		for num in ${#PROFILE_FILES[@]} ${#BIN_FILES[@]}; do
			BIN_NUM=$(($BIN_NUM+$num))
		done
		local CUR_NUM=1
	fi

	echo -e "\t${WHITE}+ ${WHITE} bin files"
	for file in ${PROFILE_FILES[@]} ${BIN_FILES[@]}; do
		if [[ $VERBOSE == "true" ]]; then
			inst bin "$file" $CUR_NUM $BIN_NUM
			local CUR_NUM=$(($CUR_NUM+1))
		else	inst bin "$file"
		fi
	done

}

remove_bsng () {

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

}
