gophcheck (2399B)
1 #!/bin/sh 2 # 3 # gophcheck.sh 4 # Created by Hayden Hamilton 5 # 6 # hayden@haydenvh.com 7 # Copyright (c) 2020 Hayden Hamilton 8 # 9 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 10 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 11 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 12 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 13 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 14 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 15 # SOFTWARE. 16 # 17 # This work is free. You can redistribute it and/or modify it under the 18 # terms of the Do What The Fuck You Want To Public License, Version 2, 19 # as published by Sam Hocevar. See http://www.wtfpl.net/ for more details. 20 21 # downloads & caches gophermaps 22 # compares later updates 23 # usage: gophcheck (compares the "current" files and "old") 24 # gophcheck update (moves the "current" files to "old", and pulls in new 25 # "current" files) 26 27 # configuration: 28 uris="gopher://1436.ninja/1/Phlog 29 gopher://nebulacentre.net/1 30 gopher://go-beyond.org/ 31 gopher://bitreich.org/1/news.gph 32 gopher://baud.baby/1/phlog 33 gopher://dataswamp.org/1/~solene 34 gopher://codevoid.de/1" 35 readcmd="cgo -f" 36 37 cache=${XDG_CACHE_HOME:=$HOME/.cache} 38 old=$cache/gophcheck/old 39 current=$cache/gophcheck/current 40 mkdir -p $old $current 41 42 echo(){ 43 printf "%s\n" "$@" 44 } 45 46 [ ! -z $1 ] && { 47 [ "$1" = "update" ] && { 48 rm -rf $old/* 49 mv $current/* $old 50 for u in $uris 51 do 52 name=$(echo "$u" | tr '/' '%') 53 curl -qs $u > $current/$name && echo "[$(tput setaf 40)OKAY$(tput sgr0)] $u" || echo "[$(tput setaf 88)FAIL$(tput sgr0)] $u" 54 done 55 } || { 56 echo "No such command, edit/read script for configuration/usage" 57 exit 1 58 } 59 } 60 61 tmp=$HOME/net/gophcheck.tmp 62 for f in $(ls $current) 63 do 64 f2="$old/$f" 65 f3="$current/$f" 66 [ -f $f2 ] && { 67 diff=$(diff $f2 $f3 | grep '^>' | sed -E 's/> (.*)/\1/') 68 echo "$diff" | grep '[[:alnum:]]' >/dev/null && { 69 echo "[$(tput setaf 40) DIFF$(tput sgr0)] $(echo "$f" | tr '%' '/')" 70 echo "i$f null null null" | tr '%' '/' >> $tmp 71 echo "$diff" >> $tmp 72 echo "i null null null" >> $tmp 73 ydiff="y" 74 } || echo "[$(tput setaf 88)NODIFF$(tput sgr0)] $(echo "$f" | tr '%' '/')" 75 } || cp $f3 $f2 76 done 77 78 trap "rm $tmp; exit 0" 2 79 [ "$ydiff" = "y" ] && clear && cgo haydenvh.com/1/gophcheck.tmp