Skip to content

Instantly share code, notes, and snippets.

@orymate
Created January 13, 2011 17:34
Show Gist options
  • Save orymate/778227 to your computer and use it in GitHub Desktop.
Save orymate/778227 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Copyright 2009 ORY Mate <[email protected]> http://maat.orgo2002.hu
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
function cleanup() {
rm -f /tmp/wl*
}
trap cleanup EXIT
case "$1" in
+) # hozzaadas
echo URL:
read A1
echo Parameterek:
read A2
echo Komment:
read A5
echo "$A1|$A2|||$A5" >> ~/.watchlist
exit 2
;;
-l) # listazas
cat ~/.watchlist | awk 'BEGIN {FS="|";}
{i++; printf("[%d]\t%s\t%s\n\t\t%s\n", i, $1, $2, $5);}'
exit 2
;;
-d) # inaktivalas
if [ ! "x$2" = 'x' ]
then
ed ~/.watchlist <<E &>/dev/null
$2 s/^/#/
w
E
fi
exit 2
;;
-a) # aktivalas
if [ ! "x$2" = 'x' ]
then
ed ~/.watchlist <<E &>/dev/null
$2 s/^#//
w
E
fi
exit 2
;;
-c) # frissites
TMP="/tmp/wl$$"
rm -f $TMP ${TMP}2 || ( echo "Atmeneti allomany nem hozhato letre" >&2 && exit 1 )
cat ~/.watchlist | grep -v '^$' | (
while read A; [ ! "x$A" = x ]
do
echo $A | grep '^#' >> $TMP && continue
A1="`echo "$A" | cut -d'|' -f1`" # URL
A2="`echo "$A" | cut -d'|' -f2`" # parameterek
A3="`echo "$A" | cut -d'|' -f3`" # allapot
A4="`echo "$A" | cut -d'|' -f4`" # hash
A5="`echo "$A" | cut -d'|' -f5`" # komment
curl -Lf $A2 "$A1" > ${TMP}2 2>/dev/null
B3=$?
B4="`cat "${TMP}2" | md5sum - | sed 's/ .*$//'`"
if [ \( "${A3}0" -ne 0 \) -a \( "${B3}0" -ne "${A3}0" \) ]
then
echo "$A1 allapota valtozott: $A3 -> $B3" >&2
elif [ ! "$A4" '=' "$B4" ]
then
echo "$A1 megvaltozott" >&2
fi
echo "$A1|$A2|$B3|$B4|$A5" >> $TMP
done
)
cp "$TMP" ~/.watchlist || ( echo ~/.watchlist nem irhato >&2 && exit 1 )
rm "$TMP"
;;
* ) # segitseg
cat <<-. >&2
$0 -c frissites
$0 -l listazas
$0 + uj bejegyzes (interaktiv)
$0 -a N N. bejegyzes aktivalasa
$0 -d N N. bejegyzes deaktivalasa
.
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment