#!/bin/sh

. "${HOME}/.mac_scripts"

die () {

    echo An error has occured.
    exit $1

}

while [[ ${#*} -ne 0 ]] ; do
    d="${1}"
    shift
    [[ "${d:((${#d}-1))}" == "/" ]] && d="${d:0:((${#d}-1))}"
    [[ "$d" == "" ]] && continue
    [[ ! -d "$d" ]] && continue
    echo $d
    mdls -name kMDItemContentTypeTree "$d" | grep "com.apple.package">/dev/null && t="${d%.*}" || t="$d"
    tar -cvzf "$t.tgz" "$d" || die $?
    tar -tzf "$t.tgz" || die $?
    rm -rf "$d" || die $?
done