]> git.sesse.net Git - videoredirector/blob - update.sh
Initial commit.
[videoredirector] / update.sh
1 #!/bin/sh
2
3 ####################
4 #    Copyright (C) 2011, 2012 by Raphael Geissert <geissert@debian.org>
5 #
6 #    This file is free software: you can redistribute it and/or modify
7 #    it under the terms of the GNU General Public License as published by
8 #    the Free Software Foundation, either version 3 of the License, or
9 #    (at your option) any later version.
10 #
11 #    This file is distributed in the hope that it will be useful,
12 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 #    GNU General Public License for more details.
15 #
16 #    You should have received a copy of the GNU General Public License
17 #    along with this file  If not, see <http://www.gnu.org/licenses/>.
18 #
19 #    On Debian systems, the complete text of the GNU General
20 #    Public License 3 can be found in '/usr/share/common-licenses/GPL-3'.
21 ####################
22
23 set -eu
24
25 compression=gz
26 if which unxz >/dev/null; then
27     compression=xz
28 fi
29
30 mkdir -p geoip
31 cd geoip
32 for db in asnum/GeoIPASNum.dat.gz GeoLiteCity.dat.$compression asnum/GeoIPASNumv6.dat.gz GeoLiteCityv6-beta/GeoLiteCityv6.dat.gz; do
33     wget -U '' -N http://geolite.maxmind.com/download/geoip/database/$db
34     db="$(basename "$db")"
35     case "$db" in
36         *.gz|*.xz)
37         file_comp="${db##*.}"
38         ;;
39         *)
40         echo "error: unknown compression of file $db" >&2
41         exit 1
42         ;;
43     esac
44
45     decomp_db="${db%.$file_comp}"
46     if [ -f $decomp_db ]; then
47         [ $db -nt $decomp_db ] || continue
48     fi
49     rm -f new.$db
50     ln $db new.$db
51     case "$file_comp" in
52         gz)
53         gunzip -f new.$db
54         ;;
55         xz)
56         unxz -f new.$db
57         ;;
58         *)
59         echo "error: unknown decompressor for .$file_comp" >&2
60         exit 1
61         ;;
62     esac
63     mv new.$decomp_db $decomp_db
64     touch -r $db $decomp_db
65 done
66 cd - >/dev/null