~dricottone/my-utils

f6232fc54d726bd833ef93af792aa6c9a2db1633 — Dominic Ricottone 2 years ago 96238ab
Full support of age encryption

mktar-batch now supports non-interactive age calls, though I've added a
dependency on expect.

tarcat, tarls, and untar now know what to do with .age files. They also
now know what to do with Zstandard compressed files that use .zstd
(instead of .zst).
M archives/Makefile => archives/Makefile +2 -0
@@ 7,6 7,7 @@ COMP_DIR?=/usr/local/etc/bash_completion.d
install:
	install -m755 epub $(BIN_DIR)/epub
	install -m755 mktar $(BIN_DIR)/mktar
	install -m755 mktar-batch $(BIN_DIR)/mktar-batch
	install -m755 rmtar $(BIN_DIR)/rmtar
	install -m755 rmzip $(BIN_DIR)/rmzip
	install -m755 tarcat $(BIN_DIR)/tarcat


@@ 19,6 20,7 @@ install:
uninstall:
	rm $(BIN_DIR)/epub
	rm $(BIN_DIR)/mktar
	rm $(BIN_DIR)/mktar-batch
	rm $(BIN_DIR)/rmtar
	rm $(BIN_DIR)/rmzip
	rm $(BIN_DIR)/tarcat

M archives/README.md => archives/README.md +2 -1
@@ 11,7 11,8 @@ expect `tar` to support Zstandard, which isn't necessarily POSIX standard.*
Executable      |Description                                                   |Extra Dependencies
:---------------|:-------------------------------------------------------------|:------------------------------------------
epub            |Dumps HTML from an 'epub' e-book archive                      |`bash`, `zipinfo`, `unzip`, `w3m`
mktar           |Wrapper around `tar` for easier compression                   |`bash`
mktar           |Archive utility                                               |`bash`
mktar-batch     |Archive utility for scripting                                 |`bash`, `expect`
rmtar           |Delete 'tar' archive files                                    |
rmzip           |Delete 'zip' archive files                                    |
tarcat          |Print contents of `tar` archive file(s)                       |

M archives/completion.bash => archives/completion.bash +5 -5
@@ 27,9 27,9 @@ complete -o default -f -X '!*.@(zip|cbr|epub)' rmzip
complete -o default -f -X '!*.@(zip|cbr|epub)' zipls

# rmtar, tarcat, tarls, untar
# complete with filenames like '*.@(tar|tar.@(gz|xz|zst|bz2)|tar.@(gz|xz|zst|bz2).gpg)'
complete -o default -f -X '!*.@(tar|tar.@(gz|xz|zst|bz2)|tar.@(gz|xz|zst|bz2).gpg)' rmtar
complete -o default -f -X '!*.@(tar|tar.@(gz|xz|zst|bz2)|tar.@(gz|xz|zst|bz2).gpg)' tarcat
complete -o default -f -X '!*.@(tar|tar.@(gz|xz|zst|bz2)|tar.@(gz|xz|zst|bz2).gpg)' tarls
complete -o default -f -X '!*.@(tar|tar.@(gz|xz|zst|bz2)|tar.@(gz|xz|zst|bz2).gpg)' untar
# complete with filenames like '*.@(tar|tar.@(gz|xz|zst|bz2)|tar.@(gz|xz|zst|bz2).(gpg|age))'
complete -o default -f -X '!*.@(tar|tar.@(gz|xz|zst|zstd|bz2)|tar.@(gz|xz|zst|bz2).(gpg|age))' rmtar
complete -o default -f -X '!*.@(tar|tar.@(gz|xz|zst|zstd|bz2)|tar.@(gz|xz|zst|bz2).(gpg|age))' tarcat
complete -o default -f -X '!*.@(tar|tar.@(gz|xz|zst|zstd|bz2)|tar.@(gz|xz|zst|bz2).(gpg|age))' tarls
complete -o default -f -X '!*.@(tar|tar.@(gz|xz|zst|zstd|bz2)|tar.@(gz|xz|zst|bz2).(gpg|age))' untar


M archives/mktar-batch => archives/mktar-batch +60 -5
@@ 214,7 214,18 @@ tar.gpg)
  ;;

tar.age)
  if ! /usr/bin/tar -c "${positional[@]}" | /usr/bin/age --encrypt --passphrase --output "$archive_fn"; then
  /usr/bin/expect <<EOF
spawn sh -c "/usr/bin/tar -c \"${positional[@]}\" | /usr/bin/age --encrypt --passphrase --output \"$archive_fn\""
expect "*:"
send "$passphrase\r"
expect "*:"
send "$passphrase\r"
expect eof

foreach {pid spawnid os_error_flag value} [wait] break
exit $value
EOF
  if [[ $? -ne 0 ]]; then
    code=1
  fi
  ;;


@@ 232,7 243,18 @@ tar.gz.gpg)
  ;;

tar.gz.age)
  if ! /usr/bin/tar -cz "${positional[@]}" | /usr/bin/age --encrypt --passphrase --output "$archive_fn"; then
  /usr/bin/expect <<EOF
spawn sh -c "/usr/bin/tar -cz \"${positional[@]}\" | /usr/bin/age --encrypt --passphrase --output \"$archive_fn\""
expect "*:"
send "$passphrase\r"
expect "*:"
send "$passphrase\r"
expect eof

foreach {pid spawnid os_error_flag value} [wait] break
exit $value
EOF
  if [[ $? -ne 0 ]]; then
    code=1
  fi
  ;;


@@ 250,7 272,18 @@ tar.xz.gpg)
  ;;

tar.xz.age)
  if ! /usr/bin/tar -cJ "${positional[@]}" | /usr/bin/age --encrypt --passphrase --output "$archive_fn"; then
  /usr/bin/expect <<EOF
spawn sh -c "/usr/bin/tar -cJ \"${positional[@]}\" | /usr/bin/age --encrypt --passphrase --output \"$archive_fn\""
expect "*:"
send "$passphrase\r"
expect "*:"
send "$passphrase\r"
expect eof

foreach {pid spawnid os_error_flag value} [wait] break
exit $value
EOF
  if [[ $? -ne 0 ]]; then
    code=1
  fi
  ;;


@@ 268,7 301,18 @@ tar.zst.gpg)
  ;;

tar.zst.age)
  if ! /usr/bin/tar --zstd -c "${positional[@]}" | /usr/bin/age --encrypt --passphrase --output "$archive_fn"; then
  /usr/bin/expect <<EOF
spawn sh -c "/usr/bin/tar --zstd -c \"${positional[@]}\" | /usr/bin/age --encrypt --passphrase --output \"$archive_fn\""
expect "*:"
send "$passphrase\r"
expect "*:"
send "$passphrase\r"
expect eof

foreach {pid spawnid os_error_flag value} [wait] break
exit $value
EOF
  if [[ $? -ne 0 ]]; then
    code=1
  fi
  ;;


@@ 286,7 330,18 @@ tar.bz2.gpg)
  ;;

tar.bz2.age)
  if ! /usr/bin/tar -cj "${positional[@]}" | /usr/bin/age --encrypt --passphrase --output "$archive_fn"; then
  /usr/bin/expect <<EOF
spawn sh -c "/usr/bin/tar -cj \"${positional[@]}\" | /usr/bin/age --encrypt --passphrase --output \"$archive_fn\""
expect "*:"
send "$passphrase\r"
expect "*:"
send "$passphrase\r"
expect eof

foreach {pid spawnid os_error_flag value} [wait] break
exit $value
EOF
  if [[ $? -ne 0 ]]; then
    code=1
  fi
  ;;

M archives/tarcat => archives/tarcat +46 -16
@@ 1,7 1,7 @@
#!/bin/sh

name="tarcat"
version="1.0"
version="1.1"
help_message=$(/usr/bin/cat <<-EOF
	Print contents of target archive file(s)
	Usage: tarcat [TARGET ..] [OPTIONS]


@@ 24,62 24,92 @@ for target; do
    code=1
  else
    case "$target" in
    *tar)
    *.tar)
      if ! /usr/bin/tar -xOf "$target"; then
        code=1
      fi
      ;;

    *tar.gpg)
      if ! /usr/bin/gpg -d "$target" | /usr/bin/tar -xO; then
    *.tar.gpg)
      if ! /usr/bin/gpg --decrypt "$target" | /usr/bin/tar -xO; then
        code=1
      fi
      ;;

    *tar.gz)
    *.tar.age)
      if ! /usr/bin/age --decrypt "$target" | /usr/bin/tar -xO; then
        code=1
      fi
      ;;

    *.tar.gz)
      if ! /usr/bin/tar -xzOf "$target"; then
        code=1
      fi
      ;;

    *tar.gz.gpg)
      if ! /usr/bin/gpg -d "$target" | /usr/bin/tar -xzO; then
    *.tar.gz.gpg)
      if ! /usr/bin/gpg --decrypt "$target" | /usr/bin/tar -xzO; then
        code=1
      fi
      ;;

    *.tar.gz.age)
      if ! /usr/bin/age --decrypt "$target" | /usr/bin/tar -xzO; then
        code=1
      fi
      ;;

    *tar.xz)
    *.tar.xz)
      if ! /usr/bin/tar -xJOf "$target"; then
        code=1
      fi
      ;;

    *tar.xz.gpg)
      if ! /usr/bin/gpg -d "$target" | /usr/bin/tar -xJO; then
    *.tar.xz.gpg)
      if ! /usr/bin/gpg --decrypt "$target" | /usr/bin/tar -xJO; then
        code=1
      fi
      ;;

    *.tar.xz.age)
      if ! /usr/bin/age --decrypt "$target" | /usr/bin/tar -xJO; then
        code=1
      fi
      ;;

    *tar.zst)
    *.tar.zst|*.tar.zstd)
      if ! /usr/bin/tar --zstd -xOf "$target"; then
        code=1
      fi
      ;;

    *tar.zst.gpg)
      if ! /usr/bin/gpg -d "$target" | /usr/bin/tar --zstd -xO; then
    *.tar.zst.gpg|*.tar.zstd.gpg)
      if ! /usr/bin/gpg --decrypt "$target" | /usr/bin/tar --zstd -xO; then
        code=1
      fi
      ;;

    *.tar.zst.age|*.tar.zstd.age)
      if ! /usr/bin/age --decrypt "$target" | /usr/bin/tar --zstd -xO; then
        code=1
      fi
      ;;

    *tar.bz2)
    *.tar.bz2)
      if ! /usr/bin/tar -xjOf "$target"; then
        code=1
      fi
      ;;

    *tar.bz2.gpg)
      if ! /usr/bin/gpg -d "$target" | /usr/bin/tar -xjO; then
    *.tar.bz2.gpg)
      if ! /usr/bin/gpg --decrypt "$target" | /usr/bin/tar -xjO; then
        code=1
      fi
      ;;

    *.tar.bz2.age)
      if ! /usr/bin/age --decrypt "$target" | /usr/bin/tar -xjO; then
        code=1
      fi
      ;;

M archives/tarls => archives/tarls +46 -16
@@ 1,7 1,7 @@
#!/bin/sh

name="tarls"
version="1.0"
version="1.1"
help_message=$(/usr/bin/cat <<-EOF
	List files within 'tar' archive file(s)
	Usage: tarls TARGET [..] [OPTIONS]


@@ 32,62 32,92 @@ for target; do
    code=1
  else
    case "$target" in
    *tar)
    *.tar)
      if ! /usr/bin/tar -tf "$target"; then
        code=1
      fi
      ;;

    *tar.gpg)
      if ! /usr/bin/gpg -d "$target" | /usr/bin/tar -t; then
    *.tar.gpg)
      if ! /usr/bin/gpg --decrypt "$target" | /usr/bin/tar -t; then
        code=1
      fi
      ;;

    *tar.gz)
    *.tar.age)
      if ! /usr/bin/age --decrypt "$target" | /usr/bin/tar -t; then
        code=1
      fi
      ;;

    *.tar.gz)
      if ! /usr/bin/tar -tzf "$target"; then
        code=1
      fi
      ;;

    *tar.gz.gpg)
      if ! /usr/bin/gpg -d "$target" | /usr/bin/tar -tz; then
    *.tar.gz.gpg)
      if ! /usr/bin/gpg --decrypt "$target" | /usr/bin/tar -tz; then
        code=1
      fi
      ;;

    *.tar.gz.age)
      if ! /usr/bin/age --decrypt "$target" | /usr/bin/tar -tz; then
        code=1
      fi
      ;;

    *tar.xz)
    *.tar.xz)
      if ! /usr/bin/tar -tJf "$target"; then
        code=1
      fi
      ;;

    *tar.xz.gpg)
      if ! /usr/bin/gpg -d "$target" | /usr/bin/tar -tJ; then
    *.tar.xz.gpg)
      if ! /usr/bin/gpg --decrypt "$target" | /usr/bin/tar -tJ; then
        code=1
      fi
      ;;

    *.tar.xz.age)
      if ! /usr/bin/age --decrypt "$target" | /usr/bin/tar -tJ; then
        code=1
      fi
      ;;

    *tar.zst)
    *.tar.zst|*.tar.zstd)
      if ! /usr/bin/tar --zstd -tf "$target"; then
        code=1
      fi
      ;;

    *tar.zst.gpg)
      if ! /usr/bin/gpg -d "$target" | /usr/bin/tar --zstd -t; then
    *.tar.zst.gpg|*.tar.zstd.gpg)
      if ! /usr/bin/gpg --decrypt "$target" | /usr/bin/tar --zstd -t; then
        code=1
      fi
      ;;

    *.tar.zst.age|*.tar.zstd.age)
      if ! /usr/bin/age --decrypt "$target" | /usr/bin/tar --zstd -t; then
        code=1
      fi
      ;;

    *tar.bz2)
    *.tar.bz2)
      if ! /usr/bin/tar -tjf "$target"; then
        code=1
      fi
      ;;

    *tar.bz2.gpg)
      if ! /usr/bin/gpg -d "$target" | /usr/bin/tar -tj; then
    *.tar.bz2.gpg)
      if ! /usr/bin/gpg --decrypt "$target" | /usr/bin/tar -tj; then
        code=1
      fi
      ;;

    *.tar.bz2.age)
      if ! /usr/bin/age --decrypt "$target" | /usr/bin/tar -tj; then
        code=1
      fi
      ;;

M archives/untar => archives/untar +46 -16
@@ 1,7 1,7 @@
#!/bin/sh

name="untar"
version="1.0"
version="1.1"
help_message=$(/usr/bin/cat <<-EOF
	Wrapper around 'tar' for easier decompression
	Usage: untar TARGET [..] [OPTIONS]


@@ 32,62 32,92 @@ for target; do
    code=1
  else
    case "$target" in
    *tar)
    *.tar)
      if ! /usr/bin/tar -xf "$target"; then
        code=1
      fi
      ;;

    *tar.gpg)
      if ! /usr/bin/gpg -d "$target" | /usr/bin/tar -x; then
    *.tar.gpg)
      if ! /usr/bin/gpg --decrypt "$target" | /usr/bin/tar -x; then
        code=1
      fi
      ;;

    *tar.gz)
    *.tar.age)
      if ! /usr/bin/age --decrypt "$target" | /usr/bin/tar -x; then
        code=1
      fi
      ;;

    *.tar.gz)
      if ! /usr/bin/tar -xzf "$target"; then
        code=1
      fi
      ;;

    *tar.gz.gpg)
      if ! /usr/bin/gpg -d "$target" | /usr/bin/tar -xz; then
    *.tar.gz.gpg)
      if ! /usr/bin/gpg --decrypt "$target" | /usr/bin/tar -xz; then
        code=1
      fi
      ;;

    *.tar.gz.age)
      if ! /usr/bin/age --decrypt "$target" | /usr/bin/tar -xz; then
        code=1
      fi
      ;;

    *tar.xz)
    *.tar.xz)
      if ! /usr/bin/tar -xJf "$target"; then
        code=1
      fi
      ;;

    *tar.xz.gpg)
      if ! /usr/bin/gpg -d "$target" | /usr/bin/tar -xJ; then
    *.tar.xz.gpg)
      if ! /usr/bin/gpg --decrypt "$target" | /usr/bin/tar -xJ; then
        code=1
      fi
      ;;

    *.tar.xz.age)
      if ! /usr/bin/age --decrypt "$target" | /usr/bin/tar -xJ; then
        code=1
      fi
      ;;

    *tar.zst)
    *.tar.zst|*.tar.zstd)
      if ! /usr/bin/tar --zstd -xf "$target"; then
        code=1
      fi
      ;;

    *tar.zst.gpg)
      if ! /usr/bin/gpg -d "$target" | /usr/bin/tar --zstd -x; then
    *.tar.zst.gpg|*.tar.zstd.gpg)
      if ! /usr/bin/gpg --decrypt "$target" | /usr/bin/tar --zstd -x; then
        code=1
      fi
      ;;

    *.tar.zst.age|*.tar.zstd.age)
      if ! /usr/bin/age --decrypt "$target" | /usr/bin/tar --zstd -x; then
        code=1
      fi
      ;;

    *tar.bz2)
    *.tar.bz2)
      if ! /usr/bin/tar -xjf "$target"; then
        code=1
      fi
      ;;

    *tar.bz2.gpg)
      if ! /usr/bin/gpg -d "$target" | /usr/bin/tar -xj; then
    *.tar.bz2.gpg)
      if ! /usr/bin/gpg --decrypt "$target" | /usr/bin/tar -xj; then
        code=1
      fi
      ;;

    *.tar.bz2.age)
      if ! /usr/bin/age --decrypt "$target" | /usr/bin/tar -xj; then
        code=1
      fi
      ;;