-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathcatbox.sh
executable file
·96 lines (72 loc) · 2.28 KB
/
catbox.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env bash
# vim:ts=4:sts=4:sw=4:et
#
# Author: Hari Sekhon
# Date: 2024-11-07 06:57:02 +0400 (Thu, 07 Nov 2024)
#
# https///github.com/HariSekhon/DevOps-Bash-tools
#
# License: see accompanying Hari Sekhon LICENSE file
#
# If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish
#
# https://www.linkedin.com/in/HariSekhon
#
set -euo pipefail
[ -n "${DEBUG:-}" ] && set -x
srcdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck disable=SC1090,SC1091
. "$srcdir/lib/utils.sh"
# shellcheck disable=SC2034,SC2154
usage_description="
Uploads a file to https://catbox.moe/ and copies the resulting URL to your clipboard
Slow, use 0x0.sh instead
If the content is ASCII then prompts to confirm the content before uploading for your safe review as this is PUBLIC
Does not do this for non-ASCII files since we can't print media content to the terminal
Retention is PERMANENT. Use litterbox.sh if you want temporary upload
Recommended: for text use anonymize.py or anonymize.pl from the adjacent DevOps-Python-tools or DevOps-Perl-tools repos
Optional: for code - decomment.sh
Knowledge Base page: https://github.com/HariSekhon/Knowledge-Base/blob/main/upload-sites.md
"
# used by usage() in lib/utils.sh
# shellcheck disable=SC2034
usage_args="<filename>"
help_usage "$@"
min_args 1 "$@"
url="https://catbox.moe/user/api.php"
file="$1"
# Do not allow reading from stdin because it does not allow the prompt safety
#if [ "$file" = '-' ]; then
# timestamp "reading from stdin"
#file="/dev/stdin"
#else
# timestamp "reading from file: $file"
#fi
if file "$file" | grep -q ASCII; then
content="$(cat "$file")"
echo
cat <<EOF
Here is what will be pasted to https://catbox.moe/:
$content
EOF
read -r -p "Continue? [y/N] " answer
echo
check_yes "$answer"
echo
fi
{
command curl -sSlf "$url" \
-F "reqtype=fileupload" \
-F "fileToUpload=@$file" ||
{
timestamp "FAILED: repeating without the curl -f switch to get the error from the API:"
command curl -sSl "$url" \
-F "reqtype=fileupload" \
-F "fileToUpload=@$file"
echo
exit 1
}
} |
tee /dev/stderr |
"$srcdir/../bin/copy_to_clipboard.sh"
echo