#!/bin/bash
name="tarcat"
version="1.2"
help_message=$(/usr/bin/cat <<-EOF
Unarchive utility for scripting
Usage: tarcat [TARGET ..] [OPTIONS]
Options:
-h, --help print this message and exit
-p PASS, --passphrase PASS passphrase for decryption
-q, --quiet suppress error messages
-v, --version print version number and exit
EOF
)
source /usr/local/lib/mylib.bash
source /usr/local/lib/unarchive.bash
quiet=0
passphrase=""
positional=()
verbose=0
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
help_msg
shift
;;
-q|--quiet)
debug_msg "Setting quiet option to 1 (was ${quiet})"
quiet=1
shift
;;
-p|--passphrase)
passphrase="$2"
shift; shift
;;
-v|--verbose)
debug_msg "Setting verbose option to 1 (was ${verbose})"
verbose=1
shift
;;
-V|--version)
version_msg
;;
*)
debug_msg "Argument '${1}' added to positional array"
positional+=("$1")
shift
;;
esac
done
code=0
for archive_fn in "${positional[@]}"; do
archive_action="$(archive_extension "$archive_fn" | tee >(>&2 /usr/bin/head -n -1) | /usr/bin/tail -n 1)"
if ! unarchive --archive=$archive_action --stdout "$archive_fn" ${passphrase:+--passphrase "$passphrase"}; then
code=1
fi
done
exit "$code"