bin bash set -eu usage cat EOF simple uploader for me by myself Usage

  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
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/bin/bash
set -eu
usage()
{
cat << EOF
A simple "uploader" for me by myself.
Usage: $0 -f file [-h host] [-p port] [-s tumbnail_size] [-nct]
Options:
-f File
-d delete the file
-H Host
-P Port
-n Do not recode mp3 to ogg
-c Show various html codes.
-u Uppod player commentary.
-t Create a thumbnail of an image file
-s Tumbnail size
-h Show this message
EOF
}
scn=""
scn_mode="fullscreen"
del=""
url=""
file=""
thumb=""
gen_html=""
comment="no comment given"
norecode=""
# Modify these to your needs:
host="localhost"
port="22"
phys_path=""
img_hell=""
audio_hell=""
video_hell=""
thumb_size="300"
[ -f "$HOME/.fuploadrc" ] && { source "$HOME/.fuploadrc"; }
while getopts "tcnhf:U:SH:P:s:u:d" option
do
case $option in
d) del="1";;
f) file="$OPTARG" ;;
U) url="$OPTARG";;
S) scn="1";;
H) host="$OPTAPRG";;
P) port="$OPTARG";;
t) [ -z "$thumb" ] && { thumb="1"; } || { thumb=""; } ;;
s) thumb_size="$OPTARG" ;;
c) [ -z "$gen_html" ] && { gen_html="1"; } || { gen_html=""; } ;;
u) comment="$OPTARG" ;;
n) norecode="1" ;;
h) usage; exit 0;;
esac
done
[ -n "$del" ] && {
ftype="$(file -ib "$file" | cut -d'/' -f1)"
fext="${file##*.}"
fbase="$(basename "$file" .$fext)"
case $fext in
png|jpg|jpeg|gif) hell="$img_hell";;
mp3|ogg) hell="$audio_hell";;
*) echo "Unknown file type"; exit 1;;
esac
ssh -p $port $host "rm $phys_path/$hell/$fbase*; $phys_path/$hell/gen_index.sh";
exit 0;
}
[ -n "$scn" ] && {
case "$scn_mode" in
fullscreen) scrot /tmp/scn.png;;
select) scrot -s /tmp/scn.png;;
esac
file="/tmp/scn.png"
}
[ ! -d "/tmp/fupload-$USER" ] && { mkdir "/tmp/fupload-$USER"; }
[ -n "$url" ] && {
fname="$(basename "$(echo "$url")")"
wget --quiet "$url" -O "/tmp/fupload-$USER/$fname"
file="/tmp/fupload-$USER/$(basename "$(echo $url)")"
}
[ -z "$file" ] && { file="$(cat)"; }
[ ! -f "$file" ] && { echo "No such file"; exit 1; }
ftype="$(file -ib "$file" | cut -d'/' -f1)"
ftype_ext="$(file -ib "$file" | cut -d';' -f1)"
case $ftype in
image) hell="$img_hell";;
audio) hell="$audio_hell";;
video)
hell="$video_hell"
echo "Why the fuck would you want to upload a video? This is not implemented yet!"
;;
*) echo "Unknown file type"; exit 1;;
esac
fpath="$(ap "$file")"
fext="${file##*.}"
fbase="$(basename "$file" ."$fext")"
nbase="$(echo $(cksum "$file") | awk '{print $1}')$(date +%d%m%Y)"
[ "$fext" == "mp3" ] && [ -z $norecode ] && {
mp32ogg "$fpath"
scp -q -P $port "$fbase.ogg" "$host:$phys_path/$hell/$nbase.ogg"
rm "$fbase.ogg"
echo "URL: http://$host/$hell/$nbase.ogg"
}
[ "$fext" == "avi" ] && [ -z $norecode ] && {
ffmpeg2theora "$fpath" -o $nbase.ogv
scp -q -P $port "$nbase.ogv" "$host:$phys_path/$hell"
rm "$nbase.ogv"
echo "URL: http://$host/$hell/$nbase.ogv"
}
[ "$ftype" == "image" ] && [ ! -z $thumb ] && {
convert "$fpath" -resize "${thumb_size}x${thumb_size}" "$fbase-thumb.$fext"
scp -q -P $port "$fbase-thumb.$fext" "$host:$phys_path/$hell/$nbase-thumb.$fext"
rm "$fbase-thumb.$fext"
echo "URL: http://$host/$hell/$nbase-thumb.$fext"
}
scp -q -P $port "$file" "$host:$phys_path/$hell/$nbase.$fext"
echo "URL: http://$host/$hell/$nbase.$fext"
[ -n "$gen_html" ] && {
echo ""
echo "HTML codes:"
case $ftype in
image)
[ -z $thumb ] && {
echo "<img src=\"http://$host/$hell/$nbase.$fext\" title=\"$nbase\" alt=\"image\" />"
} || {
echo "<a target=\"_blank\" href=\"http://$host/$hell/$nbase.$fext\"><img src=\"http://$host/$hell/$nbase-thumb.$fext\" title=\"$nbase-thumb\" alt=\"image\" /></a>"
}
;;
audio)
[ "$fext" == "ogg" ] && {
echo "<audio controls=\"true\" src=\"http://$host/$hell/$nbase.$fext\">Sorry, your browser doesn't support the html5 \"audio\" tag</audio>"
} || [ "$fext" == "mp3" ] && {
[ -z $norecode ] && {
echo "<audio controls=\"true\" src=\"http://$host/$hell/$nbase.ogg\"><object id=\"audioplayer$nbase\" type=\"application/x-shockwave-flash\" data=\"http://fr0stb1te.ru/uppod.swf\" width=\"350\" height=\"35\"><param name=\"bgcolor\" value=\"#ffffff\" /><param name=\"allowScriptAccess\" value=\"always\" /><param name=\"movie\" value=\"http://fr0stb1te.ru/uppod.swf\" /><param name=\"flashvars\" value=\"comment=$comment&amp;st=2iob3gRLvakNtiybUjFbkSmNGSJz3iuLkCz1Gi48kftLUfwZ2xsbvQnlySmb6iTr&amp;file=http://$host/$hell/$nbase.$fext\" /></object></audio>"
} || {
echo "<object id=\"audioplayer$nbase\" type=\"application/x-shockwave-flash\" data=\"http://fr0stb1te.ru/uppod.swf\" width=\"350\" height=\"35\"><param name=\"bgcolor\" value=\"#ffffff\" /><param name=\"allowScriptAccess\" value=\"always\" /><param name=\"movie\" value=\"http://fr0stb1te.ru/uppod.swf\" /><param name=\"flashvars\" value=\"comment=$comment&amp;st=2iob3gRLvakNtiybUjFbkSmNGSJz3iuLkCz1Gi48kftLUfwZ2xsbvQnlySmb6iTr&amp;file=http://$host/$hell/$nbase.$fext\" /></object>"
}
}
;;
esac
}
ssh -p $port $host "$phys_path/$hell/gen_index.sh"