Permalink
Browse files

+ zerofiles.org free file hosting upload script

Doesn't allow plaintext files :(
Obtained from http://zerofiles.org/static/sup
  • Loading branch information...
l29ah committed Nov 21, 2011
1 parent 7244c4a commit e6a6f8b4057800f7b72cb2a57e28785fa7e39ce6
Showing with 76 additions and 0 deletions.
  1. +76 −0 zerofiles.org/sup
@@ -0,0 +1,76 @@
#!/bin/bash
# Defaults
url_regex='^[a-z]+://[0-9a-z.]+/[a-zA-Z0-9_-.&?=%]+'
tmp_dir='/tmp'
tmp_file="$tmp_dir/sup_tmp_$RANDOM"
script_url='http://zerofiles.org/upload.sh'
default_tags='sup'
# /Defaults
[[ -f $HOME/.suprc ]] && { source $HOME/.suprc; }
while getopts "c:t:D:sF" option; do
arg="$OPTARG"
case $option in
c) comment="$arg";;
t) tagstr="$arg";;
s) scn='1';;
F) scn_fs='1';;
D) scn_delay="$arg";;
esac
done
[[ "$OPTIND" ]] && { shift $(($OPTIND-1)); }
cleanup() {
[[ -f "$tmp_file" ]] && {
rm "$tmp_file"
}
}
upload() {
[[ "$tagstr" ]] || { tagstr="sup"; }
curl -b "$HOME/cookies.txt" -F file="@$file" \
-F comment="$comment" \
-F tags="$tagstr" \
-F submit="" \
"$script_url" -s -L -A 'Sup Phost'
}
check_if_url() {
echo "$1" | grep -oE "$url_regex" &>/dev/null && { return 0; }; return 1
}
trap "cleanup" EXIT
[[ "$scn" ]] && {
scn_cmd='scrot'
[[ "$scn_fs" ]] || { scn_cmd="${scn_cmd} -s"; }
[[ "$scn_delay" ]] && { scn_cmd="${scn_cmd} -d"; }
${scn_cmd} "${tmp_file}.png"; file="$tmp_file.png"
} || {
[[ "$1" ]] || { echo "No file specified"; exit 1; }
check_if_url "$1" && {
[[ "$comment" ]] || { comment="Source: $1, uploaded: `date +%Y.%m.%d\ at\ %H:%M:%S`"; }
curl -s "$1" > "$tmp_file"; file="$tmp_file"
} || {
[[ "$comment" ]] || { comment="Filename: ${1##*/}, uploaded: `date +%Y.%m.%d\ at\ %H:%M:%S`"; }
file="$1"
}
}
file_type=`file -ib "$file" | cut -d';' -f1`
[[ "$file_type" == "text/html" ]] || [[ "$file_type" == "application/x-empty" ]] && { exit 1; }
# DEBUG
upload

0 comments on commit e6a6f8b

Please sign in to comment.