#!/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&st=2iob3gRLvakNtiybUjFbkSmNGSJz3iuLkCz1Gi48kftLUfwZ2xsbvQnlySmb6iTr&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&st=2iob3gRLvakNtiybUjFbkSmNGSJz3iuLkCz1Gi48kftLUfwZ2xsbvQnlySmb6iTr&file=http://$host/$hell/$nbase.$fext\" /></object>"
}
}
;;
esac
}
ssh -p $port $host "$phys_path/$hell/gen_index.sh"