#!/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 "\"image\"" } || { echo "\"image\"" } ;; audio) [ "$fext" == "ogg" ] && { echo "" } || [ "$fext" == "mp3" ] && { [ -z $norecode ] && { echo "" } || { echo "" } } ;; esac } ssh -p $port $host "$phys_path/$hell/gen_index.sh"