/usr/share/ipv6calc/tools/DBIP-update.sh is in ipv6calc 0.99.1-1+b1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | #!/bin/bash
#
# Simple shell script to update db-ip.com database files
#
# Project : ipv6calc/DBIP
# File : DBIP-update.sh
# Version : $Id: DBIP-update.sh.in,v 1.4 2015/04/30 19:55:54 ds6peter Exp $
# Copyright : 2014-2015 by Peter Bieringer <pb (at) bieringer.de>
# License : GNU GPL version 2
DBIP_DAT_DIR_DEFAULT="/usr/share/DBIP"
[ -z "$DBIP_DAT_DIR" ] && DBIP_DAT_DIR="$DBIP_DAT_DIR_DEFAULT"
DBIP_DAT_URL_BASE="http://download.db-ip.com/free/"
DBIP_DAT_FILES="dbip-country-%Y-%m.csv.gz dbip-city-%Y-%m.csv.gz"
DBIP_GENERATOR_LIST="./DBIP-generate-db.pl /usr/share/ipv6calc/tools/DBIP-generate-db.pl"
help() {
cat <<END
Usage: $(basename "$0") [-s] [-D <dir>]
-s skip download
-D <dir> database directory (optional)
database directory: $DBIP_DAT_DIR (default: $DBIP_DAT_DIR_DEFAULT)
it honors externally defined environment value: DBIP_DAT_DIR
this script (and its helper scripts) will download data from
DB-IP.com (free versions) and generate Berkeley DB files for ipv6calc
"DBIP" database support
DBIP_DAT_URL_BASE=$DBIP_DAT_URL_BASE
DBIP_DAT_FILES=$DBIP_DAT_FILES
END
}
while getopts "D:sh\?" opt; do
case $opt in
s)
skip_download=1
;;
D)
DBIP_DAT_DIR=$OPTARG
;;
*)
help
exit 1
;;
esac
done
for entry in $DBIP_GENERATOR_LIST; do
if [ -e "$entry" -a -x "$entry" ]; then
generate_db="$entry"
break
fi
done
if [ -z "$generate_db" ]; then
echo "ERROR : no DBIP database generator found from list: $DBIP_GENERATOR_LIST"
exit 1
else
echo "INFO : selected DBIP database generator: $generate_db"
fi
if [ ! -t 0 ]; then
options_generate="-q"
fi
if [ ! -d "$DBIP_DAT_DIR" ]; then
echo "ERROR : missing directory: $DBIP_DAT_DIR"
exit 1
fi
if [ ! -w "$DBIP_DAT_DIR" ]; then
echo "ERROR : missing write permissions on directory: $DBIP_DAT_DIR"
exit 1
fi
# Download files
download_result=1
if [ "$skip_download" != "1" ]; then
for file in $DBIP_DAT_FILES; do
# convert tokens
year=$(date +%Y)
month=$(date +%m)
file=${file//%Y/$year}
file=${file//%m/$month}
file_dest="$DBIP_DAT_DIR/`basename "$file"`"
echo "INFO : try to download file: $file ($file_dest)"
wget -q -O "$file_dest" "$DBIP_DAT_URL_BASE$file"
if [ $? -ne 0 ]; then
echo "ERROR : download of file not successful: $file ($file_dest)"
continue
download_result=0
fi
echo "INFO : download of file successful: $file ($file_dest)"
done
fi
# create db files from downloaded files
if [ "$download_result" = "1" ]; then
for file in $DBIP_DAT_FILES; do
time_begin=$(date '+%s')
echo "INFO : begin $(date '+%Y%m%d-%H%M%S')"
# convert tokens
year=$(date +%Y)
month=$(date +%m)
file=${file//%Y/$year}
file=${file//%m/$month}
file_input="$DBIP_DAT_DIR/`basename "$file"`"
nice -n 19 $generate_db $options_generate -I "$file_input" -O "$DBIP_DAT_DIR" -A
result=$?
echo "INFO : end $(date '+%Y%m%d-%H%M%S')"
time_end=$(date '+%s')
time_delta=$[ $time_end - $time_begin ]
time_delta_min=$[ ($time_delta + 59) / 60 ]
if [ $result -ne 0 ]; then
echo "ERROR : processing of file was not successful"
fi
echo "INFO : processing time for $file: $time_delta sec ($time_delta_min min) (remove downloaded file now)"
rm -f "$file_input"
done
fi
|