Created
August 20, 2015 10:14
-
-
Save ix9/cd1fa5bde12de3f917dc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Powershell script for updating geoip databases (106) | |
# Usage UpdateGeoIP.ps1 | |
# Enter the following data | |
$MyEditionID = "106" | |
$MyFileType = "*.dat" | |
$MyLicenseKey = "(LICENSE KEY HERE)" | |
$MyOutputFolder = "D:\Webfarm\Data\Maxmind" | |
Function UnExtractFile($compressedfile, $outputpath) | |
{ | |
$7zlocation = "C:\Progra~1\7-Zip" | |
#$FileLocation = Split-Path -parent $PSCommandPath | |
#$FullFilePath = $FileLocation + "\" + $compressedfile | |
write-host "Unextracting " $compressedfile | |
$x = "cmd" | |
$y = "/C `"^`"$7zlocation\7z.exe^`" x ^`"$compressedfile^`" -so | ^`"$7zlocation\7z.exe^`" e -y -si -ttar -o^`"$outputpath^`"" | |
write-host $y | |
& $x $y | |
} | |
Function CopytoOutputandCleanup($workpath) | |
{ | |
#write-host $workpath$MyFileType | |
Copy-Item $workpath$MyFileType $MyOutputFolder | |
Remove-Item $workpath* -recurse | |
} | |
#construct the URL to download it. | |
$FileURI = "https://www.maxmind.com/app/geoip_download?edition_id=" + $MyEditionID + "&suffix=tar.gz&license_key=" + $MyLicenseKey | |
write-host "Getting... " $FileURI | |
#get the filename (from the response header) | |
$WebResponse = (Invoke-WebRequest -uri $FileURI -Method Head) | |
# did we get a 200 OK? | |
# $WebResponse.StatusCode | |
if ($WebResponse.StatusCode -eq "200") | |
{ | |
write-host "Got a 200 Response, continuing..." | |
$PSPath = Split-Path -parent $PSCommandPath # path of the powershell script | |
$FileBasePath = $PSPath + "\work\" | |
New-Item -ItemType Directory -Force -Path $FileBasePath | |
$OutputFilename = $WebResponse.Headers["Content-Disposition"] -Replace "attachment; filename=", "" | |
$FileFullPath = $FileBasePath + $OutputFilename | |
write-host "Downloading..." $FileFullPath | |
#actually save it now | |
$DownloadResult = (Invoke-WebRequest -uri $FileURI -Outfile $FileFullPath) | |
UnExtractFile $FileFullPath $FileBasePath | |
CopytoOutputandCleanup $FileBasePath | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment