memecache-insert - annna - Annna the nice friendly bot. | |
git clone git://bitreich.org/annna/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws6… | |
Log | |
Files | |
Refs | |
Tags | |
README | |
--- | |
memecache-insert (786B) | |
--- | |
1 #!/bin/sh | |
2 set -e | |
3 | |
4 usage() { | |
5 printf "usage: %s old.meme new.meme\n" "$(basename "$0")" | |
6 exit 1 | |
7 } | |
8 | |
9 memesanity() { | |
10 if ! [ -e "$1" ]; then | |
11 printf "%s not found\n" "$1" | |
12 usage | |
13 fi | |
14 | |
15 if [ "$(sed 1q "$1")" != "meme2" ]; then | |
16 printf "we can only work with the meme2 format\n" | |
17 usage | |
18 fi | |
19 } | |
20 | |
21 if [ -z "$1" ] || [ -z "$2" ]; then | |
22 usage | |
23 fi | |
24 | |
25 oldmemes="$1" | |
26 newmemes="$2" | |
27 | |
28 memesanity "$oldmemes" | |
29 memesanity "$newmemes" | |
30 | |
31 t="$(mktemp)" | |
32 | |
33 tail -n+2 "$newmemes" | while read -r tag uri sum; do | |
34 if grep -q " ${sum}\$" "$oldmemes"; then | |
35 printf "%s already here\n" "$tag" >&2 | |
36 continue | |
37 fi | |
38 | |
39 printf "%s %s %s\n" "$tag" "$uri" "$sum" | |
40 printf "downloading %s ...\n" "$tag" >&2 | |
41 curl -s "$uri" > "$(basename "$uri")" | |
42 done > "$t" | |
43 | |
44 tail -n+2 "$oldmemes" >> "$t" | |
45 | |
46 printf "meme2\n" | |
47 sort "$t" | |
48 | |
49 rm -f "$t" |