Skip to content

Commit

Permalink
Fix #1273 - Update GeoLite2-City extraction for new directory structu…
Browse files Browse the repository at this point in the history
…re (#1274)

* Fix GeoLite2-City extraction

* Fail on missing license and fix test condition
  • Loading branch information
acmiyaguchi authored Apr 29, 2020
1 parent 04d0ac7 commit 83be734
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions ingestion-beam/bin/download-geolite2
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,31 @@

# This script downloads and extracts the free GeoLite2 city database
# from MaxMind for use in development.
set -e

: ${MM_LICENSE_KEY?"maxmind license must be set, see decoder docs for more details"}
BASE_DIR="$(dirname "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )")"
DOWNLOAD_URL="https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&license_key=${MM_LICENSE_KEY}&suffix=tar.gz"
LOCAL_ARCHIVE=/tmp/GeoLite2-City.mmdb.gz
LOCAL_EXTRACTED=/tmp/GeoLite2-City.mmdb
DB_NAME="GeoLite2-City.mmdb"

set -e
# The GeoLite2-City archive is structured as follows:
#
# x GeoLite2-City_20200428/
# x GeoLite2-City_20200428/README.txt
# x GeoLite2-City_20200428/COPYRIGHT.txt
# x GeoLite2-City_20200428/GeoLite2-City.mmdb
# x GeoLite2-City_20200428/LICENSE.txt
#
# Download and extract the mmdb into the current directory if it doesn't exist.
test -f "$BASE_DIR/$DB_NAME" || (
working=$(mktemp -d)
cd "$working"

archive=GeoLite2-City.mmdb.gz
curl -o "$archive" "$DOWNLOAD_URL"
tar -zxvf "$archive"
extracted=$(find "$working" -name "$DB_NAME")

test -f "$BASE_DIR/$(basename "$LOCAL_EXTRACTED")" || (
curl -o "$LOCAL_ARCHIVE" "$DOWNLOAD_URL"
gunzip -f "$LOCAL_ARCHIVE"
mv "$LOCAL_EXTRACTED" "$BASE_DIR"
cd -
mv "$extracted" "$BASE_DIR"
)

0 comments on commit 83be734

Please sign in to comment.