-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from DiceTechnology/feature/issue-12/maxmind-d…
…atabase-downloader Feature/issue 12/maxmind database downloader
- Loading branch information
Showing
13 changed files
with
191 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/env bash | ||
|
||
download_maxmind_db () { | ||
zip_url=$1 | ||
zip_file_destination=$2 | ||
unzip_destination_directory=$3 | ||
|
||
echo "Will download ${zip_url} to ${zip_file_destination}" | ||
wget -O ${zip_file_destination} ${zip_url} | ||
echo "Finished downloading ${zip_url}" | ||
echo "" | ||
|
||
inzip_path="$(unzip -l ${zip_file_destination} | sed -n 4p | awk '{split($4,path,"/"); print path[1]}')" | ||
db_ts="$(unzip -l ${zip_file_destination} | sed -n 4p | awk '{split($4,path,"/"); print path[1]}' | awk '{ split($1,ts,"_"); print ts[2]}')" | ||
|
||
echo "Will unzip ${zip_file_destination} into ${unzip_destination_directory}" | ||
unzip -q -o ${zip_file_destination} -d ${unzip_destination_directory} | ||
mv -f ${unzip_destination_directory}/${inzip_path}/* ${unzip_destination_directory} | ||
rm -fr ${unzip_destination_directory}/${inzip_path} | ||
echo ${db_ts} > ${unzip_destination_directory}/timestamp | ||
echo "Finished unzipping database" | ||
|
||
rm -f ${zip_file_destination} | ||
echo "Deleted the downloaded zip" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
maxmind_anonymous_licence_key="<CHANGE_ME>" | ||
maxmind_anonymous_product="GeoIP2" | ||
maxmind_anonymous_content="Anonymous" | ||
maxmind_anonymous_zip_destination="/Users/stan/www/maxmind" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/usr/bin/env bash | ||
|
||
source $(dirname $0)/../functions.sh | ||
|
||
init_maxmind_anonymous_download_arguments () { | ||
if [ $# -eq 1 ]; then | ||
if [ -f $1 ]; then | ||
. $1 | ||
else | ||
echo "ERROR: passed argument is not a valid file" | ||
exit 1; | ||
fi | ||
elif [ $# -eq 4 ]; then | ||
maxmind_anonymous_product=$1; | ||
maxmind_anonymous_content=$2; | ||
maxmind_anonymous_licence_key=$3; | ||
maxmind_anonymous_zip_destination=$4; | ||
else | ||
echo "ERROR: Improper usage"; | ||
echo "Usage 1)"; | ||
echo "./location_donwloader.sh config.sh"; | ||
echo "Usage 2)"; | ||
echo "./location_donwloader.sh <product> <content> <licence_key> <zip_destination>"; | ||
exit 1; | ||
fi | ||
|
||
if [ -z "$maxmind_anonymous_product" ]; then | ||
echo "ERROR: maxmind_anonymous_product is not defined" | ||
exit 1; | ||
fi; | ||
|
||
if [ -z "$maxmind_anonymous_content" ]; then | ||
echo "ERROR: maxmind_anonymous_content is not defined" | ||
exit 1; | ||
fi; | ||
|
||
if [ -z "$maxmind_anonymous_licence_key" ]; then | ||
echo "ERROR: maxmind_anonymous_licence_key is not defined" | ||
exit 1; | ||
fi; | ||
|
||
if [ -z "$maxmind_anonymous_zip_destination" ] || [ ! -d "$maxmind_anonymous_zip_destination" ]; then | ||
echo "ERROR: maxmind_anonymous_zip_destination needs to be a valid directory" | ||
exit 1; | ||
fi; | ||
} | ||
|
||
init_maxmind_anonymous_download_arguments $@ | ||
|
||
zip_url="https://download.maxmind.com/app/geoip_download?edition_id=${maxmind_anonymous_product}-${maxmind_anonymous_content}-CSV&license_key=${maxmind_anonymous_licence_key}&suffix=zip" | ||
zip_file_destination="${maxmind_anonymous_zip_destination}/${maxmind_anonymous_product}-${maxmind_anonymous_content}-CSV-latest.zip" | ||
unzip_destination_directory="${maxmind_anonymous_zip_destination}/${maxmind_anonymous_product}-${maxmind_anonymous_content}-CSV-latest" | ||
|
||
|
||
download_maxmind_db ${zip_url} ${zip_file_destination} ${unzip_destination_directory} | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
maxmind_location_licence_key="<CHANGE_ME>" | ||
maxmind_location_product="GeoIP2" | ||
maxmind_location_content="City" | ||
maxmind_location_zip_destination="./" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/usr/bin/env bash | ||
|
||
source $(dirname $0)/../functions.sh | ||
|
||
init_maxmind_location_download_arguments () { | ||
if [ $# -eq 1 ]; then | ||
if [ -f $1 ]; then | ||
. $1 | ||
else | ||
echo "ERROR: passed argument is not a valid file" | ||
exit 1; | ||
fi | ||
elif [ $# -eq 4 ]; then | ||
maxmind_location_product=$1; | ||
maxmind_location_content=$2; | ||
maxmind_location_licence_key=$3; | ||
maxmind_location_zip_destination=$4; | ||
else | ||
echo "ERROR: Improper usage"; | ||
echo "Usage 1)"; | ||
echo "./location_donwloader.sh config.sh"; | ||
echo "Usage 2)"; | ||
echo "./location_donwloader.sh <product> <content> <licence_key> <zip_destination>"; | ||
exit 1; | ||
fi | ||
|
||
if [ -z "$maxmind_location_product" ]; then | ||
echo "ERROR: maxmind_location_product is not defined" | ||
exit 1; | ||
fi; | ||
|
||
if [ -z "$maxmind_location_content" ]; then | ||
echo "ERROR: maxmind_location_content is not defined" | ||
exit 1; | ||
fi; | ||
|
||
if [ -z "$maxmind_location_licence_key" ]; then | ||
echo "ERROR: maxmind_location_licence_key is not defined" | ||
exit 1; | ||
fi; | ||
|
||
if [ -z "$maxmind_location_zip_destination" ] || [ ! -d "$maxmind_location_zip_destination" ]; then | ||
echo "ERROR: maxmind_location_zip_destination needs to be a valid directory" | ||
exit 1; | ||
fi; | ||
} | ||
|
||
init_maxmind_location_download_arguments $@ | ||
|
||
zip_url="https://download.maxmind.com/app/geoip_download?edition_id=${maxmind_location_product}-${maxmind_location_content}-CSV&license_key=${maxmind_location_licence_key}&suffix=zip" | ||
zip_file_destination="${maxmind_location_zip_destination}/${maxmind_location_product}-${maxmind_location_content}-CSV-latest.zip" | ||
unzip_destination_directory="${maxmind_location_zip_destination}/${maxmind_location_product}-${maxmind_location_content}-CSV-latest" | ||
|
||
|
||
download_maxmind_db ${zip_url} ${zip_file_destination} ${unzip_destination_directory} | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters