summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--config.sample19
-rw-r--r--urls.sample6
-rwxr-xr-xw3watch115
3 files changed, 107 insertions, 33 deletions
diff --git a/config.sample b/config.sample
new file mode 100644
index 0000000..a6b631a
--- /dev/null
+++ b/config.sample
@@ -0,0 +1,19 @@
+# w3watch config file
+#
+# * Lines starting with a # will be ignored
+# * Every line contains one URL
+# * An optional filter can be defined by separating any command
+# from the url using whitspaces
+#
+# Example:
+#
+# Watch a complete web page:
+#http://www.archlinux.org
+#
+# You are only interested in xorg related updates?
+# Pipe the page through a grep command.
+#http://www.archlinux.org grep -i 'xorg'
+#
+# Note: You can use any command which accepts a website dump on stdin and
+# prints its filtered output to stdout
+# \ No newline at end of file
diff --git a/urls.sample b/urls.sample
deleted file mode 100644
index d1a48cf..0000000
--- a/urls.sample
+++ /dev/null
@@ -1,6 +0,0 @@
-http://www.cmake.org/cmake/resources/software.html
-http://www.hardened-php.net/suhosin/download.html
-http://pecl.php.net/package-changelog.php?package=APC
-http://delta.affinix.com/download/qca/2.0/
-http://psi-im.org/download/
-http://labs.adobe.com/downloads/flashplayer10.html
diff --git a/w3watch b/w3watch
index 02d97e4..ba8f975 100755
--- a/w3watch
+++ b/w3watch
@@ -1,50 +1,111 @@
#!/bin/bash
-mkdir -p ~/.w3watch/cache || exit 1
+ROOTDIR="${HOME}/.w3watch"
+CACHEDIR="${ROOTDIR}/cache"
+LOCKFILE="${ROOTDIR}/lock"
+CONFIGFILE="${ROOTDIR}/config"
+CONFIGSAMPLE='/usr/share/doc/w3watch/config.sample'
-if [ ! -f ~/.w3watch/urls ]; then
- echo "~/.w3watch/urls not found!"
+
+if [ ! -d "${ROOTDIR}" ]; then
+ install -D "${CONFIGSAMPLE}" "${CONFIGFILE}"
+ mkdir -p "${CACHEDIR}"
+ eval "${EDITOR} ${CONFIGFILE}"
+ exit $?
+fi
+
+if [ ! -r "${CONFIGFILE}" ]; then
+ echo "${CONFIGFILE} not found!"
exit 1
fi
-if [ -f ~/.w3watch/lock ]; then
- echo "w3watch already running"
+if [ ! -d "${CACHEDIR}" ]; then
+ mkdir -p "${CACHEDIR}"
+fi
+
+if [ -r "${LOCKFILE}" ]; then
+ echo "w3watch is locked by ${LOCKFILE}"
exit 1
fi
-touch ~/.w3watch/lock || exit 1
+if [ "${1}" == "e" ]; then
+ eval "${EDITOR} ${CONFIGFILE}"
+ exit $?
+fi
+if [ "${1}" == "l" ]; then
+ cat "${CONFIGFILE}"
+ exit $?
+fi
+
+if [ "${1}" == "d" ]; then
+ DUMP=true
+else
+ DUMP=false
-for i in $(cat ~/.w3watch/urls); do
- dump=$(lynx -dump "$i")
- if [ $? -ne 0 ]; then
- rm -f ~/.w3watch/lock
- exit 1
+ if [ "${1}" != "c" ]; then
+ echo "Usage: ${0} [e|l|d|c]"
+ echo -e "\te:\tedit config"
+ echo -e "\tl:\tlist config"
+ echo -e "\td:\tdump output and discard any changes"
+ echo -e "\tc:\tcheck for updates"
+ exit -1
fi
+fi
- sum=$(echo "$i" | sha1sum | awk '{print $1;}')
- cachefile=~/.w3watch/cache/${sum}
- if [ -f "$cachefile" ]; then
- echo "$dump" | diff -u --label "$i" "$cachefile" -
- fi
+touch "${LOCKFILE}"
- echo "$dump" > "$cachefile"
-done
+
+while read line; do
+ if echo "${line}" | grep -q -v '^#'; then
+ data=(${line})
+ url="${data[0]}"
+ filter="${data[@]:1}"
+
+ dump=$(lynx -dump "$url")
+ if [ $? -ne 0 ]; then
+ rm -f "${LOCKFILE}"
+ exit 1
+ fi
+
+ if [ "${filter}" != "" ]; then
+ dump=$(echo "${dump}" | eval "${filter}")
+ fi
+
+ if $DUMP; then
+ echo "$dump"
+ else
+ sum=$(echo "${line}" | sha1sum | awk '{print $1;}')
+ cachefile="${CACHEDIR}/${sum}"
+
+ if [ -f "$cachefile" ]; then
+ echo "$dump" | diff -u \
+ --label "local copy from $(/usr/bin/stat --printf='%y' ${cachefile})" "$cachefile" \
+ --label "${url}" - \
+ || echo
+ fi
+
+ echo "$dump" > "$cachefile"
+ fi
+ fi
+done < "${CONFIGFILE}"
# remove old cache entries
-for i in ~/.w3watch/cache/*; do
- sumi=$(basename "$i")
+for cacheEntry in "${CACHEDIR}/"*; do
+ cacheSum=$(basename "$cacheEntry")
- for j in $(cat ~/.w3watch/urls); do
- sumj=$(echo "$j" | sha1sum | awk '{print $1;}')
+ while read configEntry; do
+ if echo "${configEntry}" | grep -q -v '^#'; then
+ configSum=$(echo "$configEntry" | sha1sum | awk '{print $1;}')
- if [ "$sumi" == "$sumj" ]; then
- continue 2
+ if [ "$cacheSum" == "$configSum" ]; then
+ continue 2
+ fi
fi
- done
+ done < "${CONFIGFILE}"
- rm -f $i
+ rm -f $cacheEntry
done
-rm -f touch ~/.w3watch/lock \ No newline at end of file
+rm -f touch "${LOCKFILE}" \ No newline at end of file