#!/bin/sh _usage () { cat </dev/null 2>&1; then echo >&2 "'realpath' not found in PATH. Exiting." exit 1 fi _archive () { ## Only one input entry: use it as base name for the archive. if [ $# -eq 1 ]; then REALPATH="$(realpath "$1")" OUTFILE="${REALPATH##*/}-$(date +%F-%H%M%S).tar${ARCEXT}" else OUTFILE="${PWD##*/}-$(date +%F-%H%M%S).tar${ARCEXT}" fi REALPWD="$(realpath "$PWD")" for i; do REALPATH="$(realpath "$i")" ## Check if one of the arguments is current folder. We need to make sure the ## archive is not created in an input folder, otherwise it will include ## itself. if [ "$REALPATH" = "$REALPWD" ]; then OUTPATH="$(realpath "$REALPWD/..")" break fi done if [ ! -w "$OUTPATH" ]; then echo "[$OUTPATH] is not writable. Exiting." return fi echo "==> [$OUTPATH/$OUTFILE]" for i; do REALPATH="$(realpath "$i")" echo "${REALPATH}" >&2 echo "-C '${REALPATH%/*}'" echo "${REALPATH##*/}" done | tar $OPTIONS -${ARCOPT}cf "$OUTPATH/$OUTFILE" -T - } if $OPT_SPLIT; then for j ; do _archive "$j" done else _archive "$@" fi