#!/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 "\"image\"" else echo "\"image\"" fi ;; audio) if [[ $fext == "ogg" ]]; then echo "" elif [[ $fext == "mp3" ]]; then if [ -z $norecode ]; then echo "" else echo "" fi fi ;; esac fi