-
Notifications
You must be signed in to change notification settings - Fork 2
/
maxmindupdater.sh
executable file
·51 lines (36 loc) · 1.55 KB
/
maxmindupdater.sh
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
#!/bin/sh
# maxmind-s3-updater
# - Uploads latest maxmind databases to an s3 bucket.
# - You can run this script in an AWS DataPipeline to update a bucket with latest maxmind files on a schedule.
#requires wget and aws-cli
#set these to match your env
AWS_ACCESS_KEY_ID=""
AWS_SECRET_ACCESS_KEY=""
AWS_DEFAULT_REGION="us-east-1"
MAXMIND_LICENSE_KEY=""
#example DEST_BUCKET_PATH="s3://my-proprietary-assets/third-party/com.maxmind/"
DEST_BUCKET_PATH=""
#Product IDs are in the download URL in maxmind web portal
# * 173 - GeoIPDomain.dat
# * 121 - GeoIPISP.dat
# * 111 - GeoIPOrg.dat
MAXMIND_PRODUCT_IDS=("173" "121" "111")
#SNS notification topic ARN
#SNS_NOTIFICATION_TOPIC="arn:aws:sns:us-west-2:123456789012:MyTopic"
SNS_NOTIFICATION_TOPIC=""
#script starts below
for i in "${MAXMIND_PRODUCT_IDS[@]}"
do
wget --content-disposition "https://www.maxmind.com/app/geoip_download?edition_id=$i&suffix=tar.gz&license_key=$MAXMIND_LICENSE_KEY"
done
#create the databases dir if it doesn't exist
mkdir -p databases
#extracts the tar files into the databases directory
find . -name '*.tar.gz' -print0 | xargs -0 -I {} tar -zxvf {} --strip-components=1 -C databases --exclude=README.txt
#remove the source files
rm -f *.tar.gz
#sync to aws bucket
AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY aws s3 sync databases $DEST_BUCKET_PATH
#send SNS notification
AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY aws sns publish --topic-arn $SNS_NOTIFICATION_TOPIC --message "Maxmind update complete!"
exit 0