up (780B)
1 #!/bin/sh 2 set -eu 3 4 readonly Host='tmp.dalliard.ch' 5 readonly Root='/var/www/tmp' 6 7 temp= 8 temp() { 9 temp=$(mktemp -d) 10 trap 'rm -r "$temp"' EXIT 11 } 12 13 upload() { 14 src=$1 15 ext=${src##*.} 16 name=$(printf '%x%s' "$(date +%s)" "$(openssl rand -hex 4)") 17 url="${Host}/${name}.${ext}" 18 scp -q "$src" "${Host}:${Root}/${name}.${ext}" 19 echo "https://${url}" 20 } 21 22 uploadText() { 23 temp 24 cat >"${temp}/input.txt" 25 upload "${temp}/input.txt" 26 } 27 28 uploadScreen() { 29 temp 30 scrot -s "$@" "${temp}/capture.png" 31 pngo "${temp}/capture.png" 32 upload "${temp}/capture.png" 33 } 34 35 while getopts 's' opt; do 36 case $opt in 37 (s) fn=uploadScreen;; 38 (?) exit 1;; 39 esac 40 done 41 shift $((OPTIND - 1)) 42 [ $# -eq 0 ] && : "${fn:=uploadText}" 43 : "${fn:=upload}" 44 45 url=$($fn "$@") 46 printf '%s' "$url" | xsel -bi || true 47 echo "$url"