tautoup - scripts - random scripts (HTM) git clone https://git.parazyd.org/scripts (DIR) Log (DIR) Files (DIR) Refs --- tautoup (1648B) --- 1 #!/bin/sh 2 3 usage() { 4 printf "usage: %s [-p|-f|-t] file" "$(basename "$0")" 5 exit 1 6 } 7 8 server="parazyd.org" 9 webroot="/home/parazyd/public_html/parazyd.org/pub" 10 webdir="dev/random" 11 12 case "$(basename "$0")" in 13 memecache) 14 webdir="memecache" 15 ;; 16 esac 17 18 case "$1" in 19 -p) 20 webdir="tmp/priv" 21 shift 22 ;; 23 -f) 24 webdir="tmp/photo" 25 shift 26 ;; 27 -t) 28 webdir="tmp" 29 shift 30 ;; 31 esac 32 33 [ -n "$1" ] || usage 34 35 filename="$(basename "$1")" 36 37 case "$filename" in 38 *scrot*|mpv-shot*) 39 webdir="tmp/screenshots" 40 num="$(ssh "$server" find "$webroot/$webdir" -type f | sort | tail -n1)" 41 num="$(printf "%s" "$num" | tr -d '[a-z]./_')" 42 num="$(e "${num}+1")" 43 44 if [ "$num" -lt 100 ]; then 45 num="000${num}" 46 elif [ "$num" -lt 1000 ]; then 47 num="00${num}" 48 elif [ "$num" -lt 10000 ]; then 49 num="0${num}" 50 fi 51 52 filename="screenshot${num}.${filename##*.}" 53 ;; 54 esac 55 56 scp "$1" "${server}:${webroot}/${webdir}/${filename}" || exit 1 57 58 if [ "$webdir" = memecache ]; then 59 oldmemes="$(hurl gopher://$server/0/pub/$webdir/memes.meme)" 60 memefile="$(mktemp)" 61 t="$(mktemp)" 62 chmod 644 "$memefile" 63 64 printf "%s\n" "$oldmemes" | grep -v ^meme2 > "$t" 65 printf "#%s gopher://%s/%s/pub/%s/%s %s\n" \ 66 "$(basename "$filename" | cut -d. -f1)" \ 67 "${server}" "$(ext2gopher "$filename")" \ 68 "${webdir}" "$(basename "$filename")" \ 69 "$(sha512sum "$filename" | cut -d' ' -f1)" >> "$t" 70 71 printf "meme2\n" > "$memefile" 72 sort "$t" >> "$memefile" 73 74 scp "$memefile" "${server}:${webroot}/${webdir}/memes.meme" 75 rm -f "$memefile" "$t" 76 fi 77 78 printf "https://%s/pub/%s/%s\n" "$server" "$webdir" "$filename" 79 printf "gopher://%s/%s/pub/%s/%s\n" "$server" "$(ext2gopher "$filename")" \ 80 "$webdir" "$filename"