Skip to content

Instantly share code, notes, and snippets.

@nicerobot
Last active August 9, 2019 04:13
Show Gist options
  • Save nicerobot/e329552210cf9729220ee048cd674326 to your computer and use it in GitHub Desktop.
Save nicerobot/e329552210cf9729220ee048cd674326 to your computer and use it in GitHub Desktop.
Self-extracting, encrypted tarballs. Much simpler than https://www.linuxjournal.com/node/1005818
#!/usr/bin/env bash
tgzx() {
(( ${#} >= 2 )) || { echo 'usage: tgzx archive-file [files | directories]'; return 1; }
printf '#!/usr/bin/env bash\ntail -n+3 ${0} | openssl enc -aes-256-cbc -d -a | tar ${1:-xv}z; exit\n' >${1}
tar zc "${@:2}" | openssl enc -aes-256-cbc -a -salt >>${1} && chmod +x ${1}
}

Archive and Secure

Usage is similar to tar.

tgzx archive-file [files | directories]

Extract

./archive-file

Example

Create secure archive

tgzx ssh.tgzx .ssh

Extract

./ssh.tgzx

List

./ssh.tgzx t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment