aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2026-08-26 06:55:56 -0400
committerB. Watson <urchlay@slackware.uk>2026-08-26 06:55:56 -0400
commit847ec251941a7f0d0e699c37ee45cacedb8839bf (patch)
tree0addbe41f7e4c7fc748c5547a15499deec5ca985
parentf3f4df7e752ed0696cd401f7ff7fb5ced3ef58ea (diff)
downloadmisc-scripts-847ec251941a7f0d0e699c37ee45cacedb8839bf.tar.gz
litterbox: convert usage to POD, add --man option.
-rwxr-xr-xlitterbox200
1 files changed, 140 insertions, 60 deletions
diff --git a/litterbox b/litterbox
index cf2b209..a5e3c1d 100755
--- a/litterbox
+++ b/litterbox
@@ -1,13 +1,8 @@
#!/bin/bash
-# API spec: https://litterbox.catbox.moe/tools.php
-# curl -F "reqtype=fileupload" -F "time=1h" -F "fileToUpload=@filename" \
-# https://litterbox.catbox.moe/resources/internals/api.php
-# 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.
+# based on the API spec: https://litterbox.catbox.moe/tools.php
+VERSION="0.0.1"
SELF="$( basename $0 )"
APIURL="https://litterbox.catbox.moe/resources/internals/api.php"
URLS=""
@@ -29,61 +24,16 @@ info() {
}
usage() {
- cat <<EOF
-$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.
-
-Once a file is uploaded, its URL is printed on stdout.
-If xsel is installed, it's also copied to the X paste buffer.
-
-When uploading multiple files, all the URLs are copied to
-the X buffer (separated by spaces). Also, a delay of $DELAY
-seconds is added between uploads, to avoid hammering the site.
-
-Options:
- -e Set expiration time in hours. Allowed values are 1, 12,
- 24, or 72. Default is $EXPIRE.
-
- -g Upload gzipped files. This is automatically enabled
- when uploading files whose names end in .exe, .scr,
- .cpl, .doc*, .jar (unless -z is given). Also, directories
- are automatically tarred/gzipped (unless -z is given).
-
- -z Upload zipped files or dirs.
-
- -t Upload tarred and gzipped directory. Won't work with
- single files (use -g or -z for those).
-
- -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 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.
+ if ! type -p perldoc &>/dev/null; then
+ echo "$SELF: can't find perldoc on PATH, printing raw POD." 1>&2
+ exec sed -n '/^=pod/,/^=cut/p' $0
+ fi
-Note: With the -c and -d option, you will be prompted interactively
-for the encryption key (password), on the process's controlling tty.
+ exec perldoc "$0"
+}
-Author: B. Watson <urchlay@slackware.uk>
-License: WTFPL (Do WTF you want with this)
-EOF
+manpage() {
+ exec pod2man --stderr -s1 -c"UrchlaysStuff" -r$VERSION "$0"
}
set_expiration() {
@@ -222,6 +172,10 @@ download_and_decrypt() {
}
# main()
+if [ "$1" = "--man" ]; then
+ manpage ; exit 0
+fi
+
if [ "$1" = "--help" ]; then
usage ; exit 0
fi
@@ -298,3 +252,129 @@ copy_urls
info "$UPLOAD_COUNT file(s) uploaded"
exit 0
+
+# Rest of the file is perldoc.
+: <<EOF
+=pod
+
+=head1 NAME
+
+B<litterbox> - upload files to litterbox.catbox.moe
+
+=head1 SYNOPSIS
+
+B<litterbox> [-e I<hours>] [-g] [-z] [-c] [-v] I<file> <I<file ...>>
+
+B<litterbox> -d [-o I<output>] I<url> <I<url ...>>
+
+=head1 DESCRIPTION
+
+B<litterbox> uploads files to (or downloads files from) the temporary
+file storage site B<https://litterbox.catbox.moe>. The site is
+similar to a "pastebin" site, except that it allows any type of
+file (not just text), and uploads can be up to 1GB in size.
+
+=head2 Uploading
+
+Each I<file> can be a filename, a directory name, or "-" for standard
+input. If no files are given, litterbox reads from standard input.
+Directories are uploaded as B<.tar.gz> archives, by default. Files
+can be optionally encrypted with AES-256.
+
+Once a file is uploaded, its URL is printed on stdout. If B<xsel>(1)
+is installed, URLs are also copied to the X paste buffer (separated
+by spaces).
+
+When uploading multiple files, a delay of 2 seconds is added between
+uploads, to avoid hammering the site.
+
+=head2 Downloading
+
+Download mode is only for downloading AES-256 encrypted files that
+were previously uploaded with B<litterbox>. Non-encrypted files can
+simply be downloaded with B<wget>(1), B<curl>(1), a web browser, etc.
+You will, of course, have to provide the correct decryption key
+(password).
+
+=head1 OPTIONS
+
+=head2 Upload Options
+
+=over 4
+
+=item B<-e> I<hours>
+
+Set expiration time in hours. Allowed values are B<1>, B<12>,
+B<24>, or B<72>. Default is B<1>.
+
+=item B<-g>
+
+Upload gzipped files. This is automatically enabled
+when uploading files whose names end in .exe, .scr,
+.cpl, .doc*, .jar (unless B<-z> is given). Also, directories
+are automatically tarred/gzipped (unless B<-z> is given).
+
+=item B<-z>
+
+Upload zipped files or dirs, rather than .tar.gz.
+
+=item B<-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 with the B<-d>
+option, or else do it manually.
+
+=back
+
+=head2 Download Options
+
+=over 4
+
+=item B<-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 upload options above (-e
+B<-g> B<-z> B<-t> B<-c>) are ignored in download mode.
+
+=item B<-o> I<file>
+
+Set output file for B<-d> option. Note that giving multiple URLs
+will result in all the data being written to the same file. If you need
+separate files, run B<litterbox> multiple times.
+
+The B<-o> option is ignored in upload mode (when B<-d> is not used).
+
+=back
+
+=head2 General Options
+
+=over 4
+
+=item B<-v>
+
+Verbose operation.
+
+=back
+
+Note: With the -c and -d option, you will be prompted interactively
+for the encryption key (password), on the process's controlling tty.
+
+=head1 AUTHOR
+
+B. Watson <urchlay@slackware.uk>
+
+=head1 COPYRIGHT
+
+B<litterbox> is licensed under the WTFPL: do WTF you want to with this.
+See http://www.wtfpl.net/txt/copying/ for details.
+
+=cut
+EOF