Add memecache-insert tool from parazyd. - annna - Annna the nice friendly bot. HTML git clone git://bitreich.org/annna/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/annna/ DIR Log DIR Files DIR Refs DIR Tags DIR README --- DIR commit 895e102dec02452a50a26be15ba5b1c619a26b38 DIR parent 12b3538f748cacc02d2b34b6efd4c74fa79bcd8e HTML Author: Annna Robert-Houdin <annna@bitreich.org> Date: Tue, 19 May 2020 19:57:39 +0200 Add memecache-insert tool from parazyd. Hvala! Diffstat: A memecache-insert | 49 +++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+), 0 deletions(-) --- DIR diff --git a/memecache-insert b/memecache-insert @@ -0,0 +1,49 @@ +#!/bin/sh +set -e + +usage() { + printf "usage: %s old.meme new.meme\n" "$(basename "$0")" + exit 1 +} + +memesanity() { + if ! [ -e "$1" ]; then + printf "%s not found\n" "$1" + usage + fi + + if [ "$(sed 1q "$1")" != "meme2" ]; then + printf "we can only work with the meme2 format\n" + usage + fi +} + +if [ -z "$1" ] || [ -z "$2" ]; then + usage +fi + +oldmemes="$1" +newmemes="$2" + +memesanity "$oldmemes" +memesanity "$newmemes" + +t="$(mktemp)" + +tail -n+2 "$newmemes" | while read -r tag uri sum; do + if grep -q " ${sum}\$" "$oldmemes"; then + printf "%s already here\n" "$tag" >&2 + continue + fi + + printf "%s %s %s\n" "$tag" "$uri" "$sum" + printf "downloading %s ...\n" "$tag" >&2 + curl -s "$uri" > "$(basename "$uri")" +done > "$t" + +tail -n+2 "$oldmemes" >> "$t" + +printf "meme2\n" +sort "$t" + +rm -f "$t"