#!/bin/bash
# 
# this saves things relative to the dir the files are in. (i hope)
# gotta do some of this since you don't want to be storing the full
# path from / in the tarballs.
#
# if i could get some kind of feed back while is working, this would
# be steller. (window with progress bar.  but i think i need something
# other then bash to do that.)
#
# michael conrad tilstra (tadpol@tadpol.org) Sun Feb 23 17:30:26 CST 2003

# uncomment the set, and comment the exec to debug.
#set -vxe
exec &>/dev/null

# list of files (and dirs)
if [ $# -gt 1 ] ;then
    # assume first item identifes location of all.
    dir=`dirname "$1"`
    #gotta call the archive something...
    base=`basename "$1"`
    #then add all relative to the base
    cd "$dir"
    # must create tarball before appending to it
    file=`basename "$1"`
    tar cpf "${base}.tar" "$file"
    shift
    for f in "$@"
    do
        file=`basename "$f"`
        tar rpf "${base}.tar" "${file}"
    done
    gzip --best "${base}.tar"
else
    # easier to handle one item
    if [ -d "$1" ] ;then
        # still gotta strip the path down to relative.
        dir=`dirname "$1"`
        base=`basename "$1"`
        cd "$dir"
        tar cpf "${base}.tar" "$base"
        gzip --best "${base}.tar"
    else
        # if it isn't a directory, just zip it.
        gzip --best -c "$1" > "${1}.gz"
    fi
fi
