#!/bin/bash

if [ $# -ne 1 ]; then
    cat<<EOF
Usage:	$(basename $0) <version>
EOF
    exit 1
fi

VERSION=$1

if [ $(egrep -m 1 $VERSION /var/lib/emacsen-common/installed-flavors) ]; then
    FLAVOR=$(egrep -m 1 $VERSION /var/lib/emacsen-common/installed-flavors)
else
    exit 1
fi

[ -d /etc/${FLAVOR} ] || exit 1

ORDER="base faces"
ORDER="${ORDER} $(ls /etc/${FLAVOR}/site-start.d/*-init.el | \
    sed -e "s!.*/[0-9]*\(.*\)-init\.el!\1!g")"

LIST="$(find /usr/share/${FLAVOR}/site-lisp/ \
    -regex '.*/vine-default.*\.el')"

for pkg in $ORDER; do
    ELS=$(echo "$LIST" | egrep -e "/${pkg}")
    if [ ! -z "${ELS}" ]; then
	for el in ${ELS}; do
	    echo ";;; Begin ${el}"
	    cat ${el}
	    echo ";;; End of ${el}"
	    echo ""
	done
    fi
done

exit

