summaryrefslogtreecommitdiffstats
path: root/w3watch
blob: 02d97e4dd5046da92850a3b3b5461fd61fa2ac0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash

mkdir -p ~/.w3watch/cache || exit 1

if [ ! -f ~/.w3watch/urls ]; then
	echo "~/.w3watch/urls not found!"
	exit 1
fi

if [ -f ~/.w3watch/lock ]; then
	echo "w3watch already running"
	exit 1
fi

touch ~/.w3watch/lock || exit 1


for i in $(cat ~/.w3watch/urls); do
	dump=$(lynx -dump "$i")
	if [ $? -ne 0 ]; then
		rm -f ~/.w3watch/lock
		exit 1
	fi

	sum=$(echo "$i" | sha1sum | awk '{print $1;}')
	cachefile=~/.w3watch/cache/${sum}

	if [ -f "$cachefile" ]; then
		echo "$dump" | diff -u --label "$i" "$cachefile" -
	fi

	echo "$dump" > "$cachefile"
done

# remove old cache entries
for i in ~/.w3watch/cache/*; do
	sumi=$(basename "$i")

	for j in $(cat ~/.w3watch/urls); do
		sumj=$(echo "$j" | sha1sum | awk '{print $1;}')

		if [ "$sumi" == "$sumj" ]; then
			continue 2
		fi
	done

	rm -f $i
done

rm -f touch ~/.w3watch/lock