Last active
December 17, 2015 00:00
-
-
Save cacoco/5518012 to your computer and use it in GitHub Desktop.
Thor script to download lastest MaxMind (http://www.maxmind.com/en/home) database and install it into a Maven compatible repository via the passed in repository URL and repository ID.
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
# Usage: | |
# thor maxmind --version=VERSION --repositoryUrl=URL --repositoryId=ID [--temp=/tmp] | |
class Maxmind < Thor | |
include Thor::Actions | |
class_options :version => :string, | |
:repositoryUrl => :string, | |
:repositoryId => :string, | |
:temp => File.join(ENV["HOME"], "Downloads") | |
desc "install", "Installs the .dat file into a Maven-compatible repository as a Maven dependency." | |
def install | |
if (options.version && options.repositoryUrl && options.repositoryId) | |
say "Using VERSION:[#{options.version}] and download directory: #{options.temp}" | |
download(options.temp) | |
inside(options.temp) do | |
run('gunzip GeoLiteCity.dat.gz') | |
run('jar cvf geolitecity.jar GeoLiteCity.dat') | |
run("mvn -e deploy:deploy-file -DgroupId=geocitylite -DartifactId=geocitylite -Dversion=#{options.version} -DgeneratePom=true -DcreateChecksum=true -Dfile=./geolitecity.jar -Dpackaging=jar -Durl=#{options.repositoryUrl} -DrepositoryId=#{options.repositoryId}") | |
# clean up after ourselves | |
remove_file "#{options.temp}/GeoLiteCity.dat" | |
remove_file "#{options.temp}/geolitecity.jar" | |
end | |
else | |
raise "Required options must be specified. thor maxmind --version=VERSION --repositoryUrl=URL --repositoryId=ID" | |
end | |
end | |
default_task :install | |
private | |
def self.source_root | |
File.dirname(__FILE__) | |
end | |
def download(temp) | |
inside(temp) do | |
remove_file "#{temp}/GeoLiteCity.dat.gz", :verbose => false | |
remove_file "#{temp}/GeoLiteCity.dat", :verbose => false | |
remove_file "#{temp}/geolitecity.jar", :verbose => false | |
run('wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz') | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment