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
#!/bin/bash
set -eu
usage()
{
cat << EOF
A simple "uploader" for me by myself.
Usage: $0 file(full path) [options]
Options:
-f File to upload.
-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
-? Show this message
EOF
}
file=
thumb=1
gen_html=1
comment="no comment given"
norecode=
# Modify these to your needs:
host="fr0stb1te.ru"
port="223"
phys_path="/home/www/blog"
img_hell="img/hell"
audio_hell="music/hell"
video_hell="video/hell"
thumb_size=500
while getopts "f:c:u:t:n?" option
do
case $option in
f) file=$OPTARG ;;
t) thumb="1" && thumb_size=$OPTARG ;;
c) gen_html="1" ;;
u) comment="$OPTARG" ;;
n) norecode="1" ;;
?) usage ;;
esac
done
[ -z "$file" ] && echo "No file specified" && exit 1
[ ! -f "$file" ] && echo "No such file" && exit 1
fpath="$(ap "$file")"
fext="$(echo "$fpath" | awk -F . '{print $NF}')"
fbase="$(basename "$file" .$fext)"
ftype="$(file -ib "$file" | cut -d'/' -f1)"
ftype_ext="$(file -ib "$file" | cut -d';' -f1)"
nbase="$(echo $(cksum "$file") | awk '{print $1}')$(date +%d%m%Y)"
[ $ftype == "image" ] && hell="$img_hell"
[ $ftype == "audio" ] && hell="$audio_hell"
[ $ftype == "video" ] && hell="$video_hell"
if [ $fext == "mp3" ] && [ -z $norecode ]; then
mp32ogg "$fpath"
scp -q -P $port "$fbase.ogg" "$host:$phys_path/$hell/$nbase.ogg"
rm "$fbase.ogg"
echo "URL: http://$host/$hell/$nbase.ogg"
fi
if [ $fext == "avi" ] && [ -z $norecode ]; then
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"
fi
if [ $ftype == "image" ]; then
if [ ! -z $thumb ]; then
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"
fi
fi
scp -q -P $port "$file" "$host:$phys_path/$hell/$nbase.$fext"
echo "URL: http://$host/$hell/$nbase.$fext"
if [ -n $gen_html ]; then
echo ""
echo "HTML codes:"
case $ftype in
image)
if [ -n $thumb ]; then
echo "<a target=\"_blank\" href=\"http://$host/$hell/$nbase.$fext\"><img src=\"http://$host/$hell/$nbase-thumb.$fext\" title=\"$nbase-thumb\" alt=\"image\" /></a>"
else
echo "<img src=\"http://$host/$hell/$nbase.$fext\" title=\"$nbase\" alt=\"image\" /></a>"
fi
;;
audio)
if [[ $fext == "ogg" ]]; then
echo "<audio controls=\"true\" src=\"http://$host/$hell/$nbase.$fext\">Sorry, your browser doesn't support the html5 \"audio\" tag</audio>"
elif [[ $fext == "mp3" ]]; then
if [ -z $norecode ]; then
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>"
else
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>"
fi
fi
;;
esac
fi