aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xlitterbox64
1 files changed, 50 insertions, 14 deletions
diff --git a/litterbox b/litterbox
index 826619a..cf2b209 100755
--- a/litterbox
+++ b/litterbox
@@ -6,8 +6,7 @@
# time can be 1h, 12h, 24h, or 72h
# The following file types are currently not allowed:
# .exe, .scr, .cpl, .doc*, .jar
-# ...so this script will gzip those automatically. otherwise, use -z
-# to gzip and -Z to zip.
+# ...so this script will gzip those automatically.
SELF="$( basename $0 )"
APIURL="https://litterbox.catbox.moe/resources/internals/api.php"
@@ -34,6 +33,7 @@ usage() {
$SELF: upload files to litterbox.catbox.moe
Usage: $SELF [-e hours] [-g] [-z] [-c] [-v] file <file ...>
+ $SELF -d [-o output] url <url ...?
Each file can be a filename, a directory name, or "-" for standard
input. If no files are given, $SELF reads from standard input.
@@ -62,12 +62,25 @@ Options:
-c Upload encrypted file. Currently this means the file
is encrypted with 'openssl enc -pbkdf2 -aes-256-cbc', and
you're prompted for an encryption key. Whoever downloads
- the encrypted file will have to decrypt it manually,
- e.g. with:
- openssl enc -d -pbkdf2 -aes-256-cbc < file.encrypted > file.decrypt
+ the encrypted file will have to decrypt it with the -d
+ option, or else do it manually.
+
+ -d Download and decrypt previously uploaded file(s) from URL(s).
+ Equivalent to downloading the file normally, then piping it
+ through:
+ openssl enc -d -pbkdf2 -aes-256-cbc
+ ...which means the file will be printed to your terminal,
+ unless you use shell redirection or the -o option. The options
+ above (-e -g -z -t -c) have no effect in download mode.
+
+ -o Set output file for -d option. Note that giving multiple URLs
+ will result in all the data being written to the same file.
-v Verbose operation.
+Note: With the -c and -d option, you will be prompted interactively
+for the encryption key (password), on the process's controlling tty.
+
Author: B. Watson <urchlay@slackware.uk>
License: WTFPL (Do WTF you want with this)
EOF
@@ -143,7 +156,7 @@ upload_file() {
local url
local use_compression
- info "preparing to upload $FILE"
+ info "checking $FILE"
case "$FILE" in
*.exe|*.scr|*.cpl|*.doc*|*.jar)
@@ -201,28 +214,51 @@ upload_file() {
esac
}
+download_and_decrypt() {
+ local url="$1"
+ info "downloading and decrypting $url"
+ curl --silent "$url" | openssl enc -d -pbkdf2 -aes-256-cbc
+ [ "$?" != 0 ] && warn "download/decrypt failed"
+}
+
# main()
if [ "$1" = "--help" ]; then
usage ; exit 0
fi
-while getopts ":e:gzcv" OPT; do
+while getopts ":e:gzcvdo:" OPT; do
case "$OPT" in
- e) set_expiration "$OPTARG" ;;
- g) GZIP=1 ;;
- z) ZIP=1 ;;
- c) ENC=1 ;;
- v) VERBOSE=1 ;;
+ e) set_expiration "$OPTARG"; opt_e=1 ;;
+ o) DLOUT="$OPTARG" ;;
+ g) GZIP=1 ;;
+ z) ZIP=1 ;;
+ c) ENC=1 ;;
+ v) VERBOSE=1 ;;
+ d) DOWNLOAD=1 ;;
*) die "invalid option -$OPTARG, try --help" ;;
esac
done
+shift $(($OPTIND - 1))
+
[ "$GZIP" = 1 -a "$ZIP" = 1 ] && die "can't give both -g and -z"
[ "$GZIP" = 1 -o "$ZIP" = 1 ] && COMPRESS=1
-info "expire time set to $EXPIRE hour(s)"
+if [ "$DOWNLOAD" = 1 ]; then
+ [ "$GZIP" = 1 ] && warn "-g option ignored when using -d"
+ [ "$ZIP" = 1 ] && warn "-z option ignored when using -d"
+ [ "$ENC" = 1 ] && warn "-c option ignored when using -d"
+ [ "$opt_e" = 1 ] && warn "-e option ignored when using -d"
+ [ "$DLOUT" != "" ] && exec 1>"$DLOUT" || die "can't redirect stdout"
+ for arg; do
+ download_and_decrypt "$arg"
+ done
+ exit 0
+else
+ [ "$DLOUT" != "" ] && warn "-o option ignored when not using -d"
+fi
-shift $(($OPTIND - 1))
+info "expire time set to $EXPIRE hour(s)"
[ "$1" = "" ] && set -- -
for arg; do