This repository was archived by the owner on Mar 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpastebin
More file actions
executable file
·58 lines (51 loc) · 1.26 KB
/
pastebin
File metadata and controls
executable file
·58 lines (51 loc) · 1.26 KB
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
#!/bin/bash
#pastebin 0.4.1, script by Zash
if [ -z "$(which curl)" ]; then
echo "no curl" >&2
exit 1
fi
if [ -z "$RECEIVER_URL" ]; then
RECEIVER_URL="http://pastebin.example.net/catch.php"
if test -f "$HOME/.$(basename $(readlink -f "$0"))rc"; then
source "$HOME/.$(basename $(readlink -f "$0"))rc"
fi
fi
SRC="$1"
if [ -z "$SRC" ]; then
SRC=-
fi
if [ "$SRC" != "-" ]; then
if [ ! -f "$SRC" ]; then
echo "$SRC is not a regular file" >&2
exit 1
fi
if [ ! -r "$SRC" ]; then
echo "$SRC is not readable" >&2
exit 1
fi
TYPE="$(file --brief --mime-type --dereference "$SRC" 2>/dev/null || file --brief --mime --dereference "$SRC")"
if ! ( grep -q -F -x "##${TYPE%[/]*}/*" $0 || \
grep -q -F -x "##${TYPE%[;, ]*}" $0 )
then
read -p "$SRC is of type $TYPE, really pastebin it? [y/N] " answer
case "$answer" in
y) ;;
*) exit 1;;
esac
fi
fi
TPX=$(basename $0)-$$
OUTPUT=$(tempfile --prefix=$TPX)
HEAD=$(tempfile --prefix=$TPX)
curl --header "Expect:" --dump-header "$HEAD" --form text=\<"$SRC" $RECEIVER_URL > $OUTPUT 2>/dev/null
if [[ $(grep 201 $HEAD 2> /dev/null | wc -l) -ge 1 ]]; then
head -n 1 $OUTPUT
else
head -n 1 $OUTPUT
fi
rm $OUTPUT $HEAD
# Acceptable MIME-types.
##text/*
##application/x-shellscript
##application/x-perl
##application/xml