updated on Wed Jan 11 08:01:35 UTC 2012
[aur-mirror.git] / updcheck / updcheck
blob0d867234e2bfb150b84a62cdd7e30e7580e2bec8
1 #!/bin/bash
2 # v. 0.7.1
3 # Description: Tells you which websites have changed since last run/mirroring.
5 # set colors
6 OLD=$(tput setaf 1) # red
7 SAMELINE=$(tput setaf 4) # blue
8 NEW=$(tput setaf 2) # green
10 INFO=$(tput setaf 3) #yellow
11 NORMAL=$(tput setaf 7) #gray
13 #how wide is your terminal or how much text in width would you like to include in the output? see echo $COLUMNS for how many letters you can show on one line, it doesn't work inside a script for some reason..
14 TERMWIDTH=180
15 #BLUE="\033[1;34m"
16 # $colour{cyan} = "\033[1;36m";
17 # $colour{red} = "\033[1;31m";
19 function _show_help() {
20 echo -e "\nupdcheck 0.7.1\n\nusage: updcheck [--no-colors] [-h|--help] \n\nTells you which webpages of the ones in \`${HOME}/.updcheck/urls' have changed since last mirroring. The first time you run with a new entry it will mirror the entry, the second time it will check for differences, and tell you if it finds any discrepancies.\n\n --no-colors Turn off colors\n"
21 exit 0
24 if [ "$1" = "-h" -o "$1" = "--help" ]
25 then
26 _show_help
29 function _diff() {
30 #git diff --color x y...
31 diff -w -W $TERMWIDTH -y --suppress-common-lines mirrors/$_url2 $_url2|sed "s#\(.*|.*\)#`echo $SAMELINE`&#"|sed "s#\(.*>.*\)#`echo $NEW`&#"|sed "s#\(.*<.*\)#`echo $OLD`&#"
32 if [ $PIPESTATUS -eq 1 ]
33 then
34 echo $INFO && echo -n $_url2|sed 's|,|/|g' && echo " have updated." && echo $NORMAL
36 # mv new copy over the old one
37 mv $_url2 mirrors/
40 function _diff_no_colors() {
41 diff -w -W $TERMWIDTH -y --suppress-common-lines mirrors/${_url2} ${_url2}
42 if [ $? -eq 1 ]
43 then
44 echo "`echo $_url2|sed 's|,|/|g'` have updated."
46 # mv new copy over the old one
47 mv ${_url2} mirrors/
50 # create needed directories upon first run
51 if [ ! -d "${HOME}/.updcheck/mirrors" ]
52 then
53 mkdir -p ${HOME}/.updcheck/mirrors
54 touch ${HOME}/.updcheck/urls
55 echo "Creating ´~/.updcheck/mirrors...urls. Fill in ´~/.updcheck/urls´"
56 echo -e "# Works best with pages that doesn't look different\n# each time you refresh it(because of ads, a clock/date script etc)\n# but perhaps the download page or the news page for example.\n# Example:\n# http://en.wikipedia.org/wiki/Linux\n# " > ${HOME}/.updcheck/urls
59 # cd into standard dir
60 cd ${HOME}/.updcheck
62 #start file-reading loop
63 while read _url; do
64 # set _url to use , instead of / for processing
65 _url2=`echo ${_url}|sed 's|/|,|g'`
66 elinks -dump -no-numbering -no-references -no-connect 0 -no-home 1 "${_url}" > "$_url2"
68 #is it already mirrored? in that case diff it against the new file!
69 if [ -f mirrors/${_url2} -a -f ${_url2} ]
70 then
71 if [ "$1" = "--no-colors" ]
72 then
73 _diff_no_colors
74 else
75 _diff
79 #mirror doesn't exist. create mirror
80 if [ ! -f mirrors/${_url2} ];
81 then
82 mv ${_url2} mirrors/
83 if [ "$1" = "--no-colors" ]
84 then
85 echo "Making mirror of" `echo $_url2|sed 's|,|/|g'`
86 else
87 echo $INFO && echo "Making mirror of $_url2"|sed 's|,|/|g' && echo $NORMAL
90 done < <(egrep -v "^$|#" urls)