tRewrite autoup. - scripts - random scripts (HTM) git clone https://git.parazyd.org/scripts (DIR) Log (DIR) Files (DIR) Refs --- (DIR) commit 42e2b007e32d6a716f00f36fa15516827fdbafb6 (DIR) parent 0c1b24ac7fdbfdd272644ba47cfe8fdd973868e9 (HTM) Author: parazyd <parazyd@dyne.org> Date: Tue, 19 May 2020 02:28:16 +0200 Rewrite autoup. Diffstat: M autoup | 84 +++++++++++++++++++------------ A memecache | 2 ++ 2 files changed, 53 insertions(+), 33 deletions(-) --- (DIR) diff --git a/autoup b/autoup t@@ -1,58 +1,76 @@ #!/bin/sh -server=parazyd.org -webroot=/home/parazyd/public_html/parazyd.org/pub -webdir=dev/random + +usage() { + printf "usage: %s [-p|-f|-t] file" "$(basename "$0")" + exit 1 +} + +server="parazyd.org" +webroot="/home/parazyd/public_html/parazyd.org/pub" +webdir="dev/random" + +case "$(basename "$0")" in +memecache) + webdir="memecache" + ;; +esac case "$1" in -p) + webdir="tmp/priv" shift - webdir=tmp/priv - ;; --n) - shift - webdir=dev/null ;; -f) + webdir="tmp/photo" shift - webdir=tmp/photo ;; -t) + webdir="tmp" shift - webdir=tmp ;; esac +[ -n "$1" ] || usage -test -z "$1" && exit 1 -filename=$(basename $1) +filename="$(basename "$1")" case "$filename" in -*_scrot.*|mpv-shot*.*) - webdir=tmp/screenshots - num=$(echo $(lynx -dump http://$server/pub/tmp/screenshots \ - | tail -n1 | tr -d '[a-z]./:' | awk '{print $2}') + 1 | bc) +*scrot*|mpv-shot*) + webdir="tmp/screenshots" + num="$(ssh "$server" find "$webroot/$webdir" -type f | sort | tail -n1)" + num="$(printf "%s" "$num" | tr -d '[a-z]./_')" + num="$(e "${num}+1")" + if [ "$num" -lt 100 ]; then - num="00$num" + num="000${num}" elif [ "$num" -lt 1000 ]; then - num="0$num" + num="00${num}" + elif [ "$num" -lt 10000 ]; then + num="0${num}" fi + filename="screenshot${num}.${filename##*.}" - goph=I - ;; -*.png|*.jpg|*.jpeg|*.JPG|*.JPEG) - goph=I - ;; -*.txt|*.html|*.css|*.sh|*.c) - goph=0 - ;; -*.gif) - goph=g - ;; -*) - goph=9 ;; esac scp "$1" "${server}:${webroot}/${webdir}/${filename}" || exit 1 -echo "https://$server/pub/$webdir/$filename" -echo "gopher://$server/$goph/pub/$webdir/$filename" + +if [ "$webdir" = memecache ]; then + memes="$(ssh "$server" find "$webroot/$webdir" -type f -exec basename {} \\';')" + memes="$(printf "$memes" | grep -v memes.meme | sort)" + memefile="$(mktemp)" + echo "meme" > "$memefile" + for meme in $memes; do + printf "#%s gopher://%s/%s/pub/%s/%s\n" \ + "$(printf "%s" "$meme" | cut -d. -f1)" \ + "$server" "$(ext2gopher "$meme")" \ + "$webdir" "$meme" >> "$memefile" + done + + scp "$memefile" "${server}:${webroot}/${webdir}/memes.meme" + rm -f "$memefile" +fi + +printf "https://%s/pub/%s/%s\n" "$server" "$webdir" "$filename" +printf "gopher://%s/%s/pub/%s/%s\n" "$server" "$(ext2gopher "$filename")" \ + "$webdir" "$filename" (DIR) diff --git a/memecache b/memecache t@@ -0,0 +1 @@ +autoup +\ No newline at end of file