From 43f05b0c93cca06e26482f32b1f18f901f3d621b Mon Sep 17 00:00:00 2001 From: yosh Date: Thu, 4 May 2023 19:45:28 -0400 Subject: [PATCH] hehe --- README.md | 35 ++++++++++++++++++++++++++++++++++- agetar | 45 ++++++++++++++++++++++++++++++++------------- 2 files changed, 66 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index c84e67f..32e7315 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,35 @@ # agetar -actual description and development pending... I am lazy +`agetar` is a simple wrapper around `tar` and `age` to easily pack files into an encrypted tar archive or extract files from an encrypted tar archive. + +## dependencies +- a posix-compliant shell +- either `bsdtar` or `tar` (`bsdtar` takes priority) +- [age](https://github.com/FiloSottile/age) + +# usage +``` +usage: + agetar -e (-r RECIPIENT | -R PATH)... [-a] [-o OUTPUT] [--] FILES... + agetar -e -p [-a] [-o OUTPUT] [--] FILES... + agetar -d [-i PATH]... [-o OUTPUT] [--] FILES... + +options: + -e encrypt the input files to an output tar + -d decrypt the input tar to output files + -o OUTPUT encrypting: write output tar to OUTPUT. stdout if omitted + decrypting: directory to extract to. PWD if omitted + -a encrypt to a PEM encoded format + -p encrypt with a passphrase + -r RECIPIENT encrypt to the specified RECIPIENT. can be repeated + -R PATH encrypt to the recipients listed at PATH. can be repeated + -i PATH decrypt using the identity file at PATH. can be repeated + +at least one FILE is required for both encrypting and decrypting +if multiple are present, each will be processed with the same identities + +you probably want an OUTPUT when encrypting, even if it's not required +(age will yet at you for that anyway unless you also use -a) + +most of these options are passed directly to age(1). see its man page for +more details. +``` diff --git a/agetar b/agetar index 606075c..2308ed7 100755 --- a/agetar +++ b/agetar @@ -1,17 +1,13 @@ #!/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)" +RED="$(printf '\033[38;5;9m')" +RESET="$(printf '\033[m')" set -euf BN="${0##*/}" export POSIXLY_CORRECT=1 if [ "${NO_COLOR:-}" ]; then - RED="" GREEN="" YELLOW="" RESET="" + RED="" RESET="" fi errecho() { @@ -22,11 +18,34 @@ fail() { errecho "${RED}error: $BN: $RESET$*" exit 1 } +_type() { type >/dev/null 2>&1 ; } usage() { cat >&2 <<-EOF usage: - $BN + $BN -e (-r RECIPIENT | -R PATH)... [-a] [-o OUTPUT] [--] FILES... + $BN -e -p [-a] [-o OUTPUT] [--] FILES... + $BN -d [-i PATH]... [-o OUTPUT] [--] FILES... + + options: + -e encrypt the input files to an output tar + -d decrypt the input tar to output files + -o OUTPUT encrypting: write output tar to OUTPUT. stdout if omitted + decrypting: directory to extract to. PWD if omitted + -a encrypt to a PEM encoded format + -p encrypt with a passphrase + -r RECIPIENT encrypt to the specified RECIPIENT. can be repeated + -R PATH encrypt to the recipients listed at PATH. can be repeated + -i PATH decrypt using the identity file at PATH. can be repeated + + at least one FILE is required for both encrypting and decrypting + if multiple are present, each will be processed with the same identities + + you probably want an OUTPUT when encrypting, even if it's not required + (age will yet at you for that anyway unless you also use -a) + + most of these options are passed directly to age(1). see its man page for + more details. EOF } @@ -56,8 +75,8 @@ shift $((OPTIND - 1)) 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"; } || \ + { _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 @@ -68,12 +87,12 @@ if [ "$TYPE" = "e" ]; then 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"; } || \ + { _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" + [ ! -d "${OUTPUT:="$PWD"}" ] && mkdir -p "$OUTPUT" $CMD "$TAR" -C "$OUTPUT" done fi