check-changes-website.sh (1442B) - raw


      1 #!/bin/sh
      2 # Copyright (C) 2020 Oscar Benedito <oscar@oscarbenedito.com>
      3 #
      4 # This program is free software: you can redistribute it and/or modify
      5 # it under the terms of the GNU Affero General Public License as
      6 # published by the Free Software Foundation, either version 3 of the
      7 # License, or (at your option) any later version.
      8 #
      9 # This program is distributed in the hope that it will be useful,
     10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12 # GNU Affero General Public License for more details.
     13 #
     14 # You should have received a copy of the GNU Affero General Public License
     15 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
     16 
     17 # Script that notifies through Gotify when a website has changed.
     18 
     19 # This scripts assumes there is an executable called "notify" in your PATH that
     20 # takes two arguments (the first one is the notification title and the second
     21 # one is the message).
     22 
     23 URLS="${XDG_CONFIG_HOME:-$HOME/.config}/osf/urls-check-changes.txt"
     24 
     25 [ ! -f "$URLS" ] && echo "Error: $URLS is not a file." && exit 1
     26 
     27 check_and_notify() {
     28   newhash="$(curl "$1" 2>/dev/null | sha256sum | cut -f 1 -d " ")"
     29   [ "$2" != "$newhash" ] && notify "$3" "$1"
     30 }
     31 
     32 while read -r url hash title
     33 do
     34   check_and_notify "$url" "$hash" "$title"
     35 done < "$URLS"
     36 
     37 # Can also be used by calling check_and_notify directly. Example:
     38 # check_and_notify url hash title