initial commit
This commit is contained in:
commit
cac59ddf59
2 changed files with 81 additions and 0 deletions
2
README.md
Normal file
2
README.md
Normal file
|
@ -0,0 +1,2 @@
|
|||
# agetar
|
||||
actual description and development pending... I am lazy
|
79
agetar
Executable file
79
agetar
Executable file
|
@ -0,0 +1,79 @@
|
|||
#!/bin/sh
|
||||
|
||||
# I can't believe I'm making this
|
||||
|
||||
RED="$(tput setaf 9)" || RED="$(tput setf 4)"
|
||||
GREEN="$(tput setaf 10)" || GREEN="$(tput setf 2)"
|
||||
YELLOW="$(tput setaf 11)" || YELLOW="$(tput setf 6)"
|
||||
RESET="$(tput sgr0)"
|
||||
set -euf
|
||||
BN="${0##*/}"
|
||||
export POSIXLY_CORRECT=1
|
||||
|
||||
if [ "${NO_COLOR:-}" ]; then
|
||||
RED="" GREEN="" YELLOW="" RESET=""
|
||||
fi
|
||||
|
||||
errecho() {
|
||||
>&2 echo "$*$RESET"
|
||||
}
|
||||
|
||||
fail() {
|
||||
errecho "${RED}error: $BN: $RESET$*"
|
||||
exit 1
|
||||
}
|
||||
|
||||
usage() {
|
||||
cat >&2 <<-EOF
|
||||
usage:
|
||||
$BN
|
||||
EOF
|
||||
}
|
||||
|
||||
AGEOPTS=
|
||||
RECIPIENTS=
|
||||
RECIPIENTS_FILES=
|
||||
IDENTITIES=
|
||||
while getopts :hedo:apr:R:i: OPT; do
|
||||
case $OPT in
|
||||
h) usage && exit 0 ;;
|
||||
e) TYPE=e; AGEOPTS="$AGEOPTS -e" ;;
|
||||
d) TYPE=d; AGEOPTS="$AGEOPTS -d" ;;
|
||||
o) [ ! "${OUTPUT:-}" ] && OUTPUT="$OPTARG" || fail "don't specify output twice D:" ;;
|
||||
a) AGEOPTS="$AGEOPTS -a" ;;
|
||||
p) AGEOPTS="$AGEOPTS -p" ;;
|
||||
r) RECIPIENTS="$RECIPIENTS -r '$(printf '%s' "$OPTARG" | sed -e "s/'/'\\\\''/g")'" ;;
|
||||
R) RECIPIENTS_FILES="$RECIPIENTS_FILES -R '$(printf '%s' "$OPTARG" | sed -e "s/'/'\\\\''/g")'" ;;
|
||||
i) IDENTITIES="$IDENTITIES -i '$(printf '%s' "$OPTARG" | sed -e "s/'/'\\\\''/g")'" ;;
|
||||
*) ;;
|
||||
esac
|
||||
done
|
||||
shift $((OPTIND - 1))
|
||||
|
||||
[ "$#" -lt 1 ] && usage && exit 1
|
||||
[ ! "${TYPE:-}" ] && fail 'specify one of -e or -d'
|
||||
|
||||
TAR="$(mktemp)"
|
||||
trap 'rm "$TAR"' INT HUP QUIT EXIT
|
||||
if [ "$TYPE" = "e" ]; then
|
||||
{ type bsdtar && CMD="bsdtar -rL -f"; } || \
|
||||
{ type tar && CMD="tar -rh -f"; } || \
|
||||
fail "can't find tar command!"
|
||||
for f; do
|
||||
if [ -f "$f" ] || [ -d "$f" ]; then
|
||||
$CMD "$TAR" "$f" >/dev/null 2>&1
|
||||
else
|
||||
errecho "$f is not a regular file or directory! skipping..."
|
||||
fi
|
||||
done
|
||||
eval 'age $AGEOPTS ${OUTPUT:+-o "$OUTPUT"} '"$RECIPIENTS $RECIPIENTS_FILES $IDENTITIES"' "$TAR"'
|
||||
else
|
||||
{ type bsdtar && CMD="bsdtar -x -f"; } || \
|
||||
{ type tar && CMD="tar -x -f"; } || \
|
||||
fail "can't find tar command!"
|
||||
for f; do
|
||||
eval 'age $AGEOPTS -o "$TAR" '"$RECIPIENTS $RECIPIENTS_FILES $IDENTITIES"' "$f"'
|
||||
[ ! -d "${OUTPUT:=$PWD}" ] && mkdir -p "$OUTPUT"
|
||||
$CMD "$TAR" -C "$OUTPUT"
|
||||
done
|
||||
fi
|
Loading…
Reference in a new issue