chocolateyInstall.ps1 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. $ErrorActionPreference = 'Stop'
  2. $packageName = 'nexus-oss'
  3. $url = 'https://sonatype-download.global.ssl.fastly.net/nexus/oss/nexus-2.13.0-01-bundle.zip'
  4. $checksum = '76E2A2904FF0341A5FB646F615E3724F6C54E8A71759A7F8F06F702339D0767B'
  5. $installDir = 'c:\nexus'
  6. $packageArgs = @{
  7. packageName = $packageName
  8. url = $url
  9. url64Bit = $url #url includes both 32-bit and 64-bit
  10. checksum = $checksum
  11. checksum64 = $checksum
  12. checksumType = 'sha256'
  13. checksumType64 = 'sha256'
  14. unzipLocation = $installDir
  15. }
  16. if ($Env:ChocolateyPackageParameters -match '/InstallDir:\s*(.+)') {
  17. $installDir = $Matches[1]
  18. if ($installDir.StartsWith("'") -or $installDir.StartsWith('"')){ $installDir = $installDir -replace '^.|.$' }
  19. $parent = Split-Path $installDir
  20. mkdir -force $parent -ea 0 | out-null
  21. }
  22. if (gcm nexus -ea 0) {
  23. Write-Host "Detected existing installation, uninstalling service"
  24. 0 | nexus stop
  25. 0 | nexus uninstall
  26. }
  27. Write-Host "Installing to '$installDir'"
  28. Install-ChocolateyZipPackage @packageArgs
  29. $nexusDir = ls $installDir\nexus-* | sort -Descending | select -First 1
  30. $nexus = "$nexusDir\bin\nexus.bat"
  31. if (!(Test-Path $nexus)) { throw "Can not find nexus.bat" }
  32. Install-BinFile nexus $nexus
  33. 0 | nexus install
  34. 0 | nexus start
  35. $s = gsv nexus-webapp -ea 0
  36. if (!$s) { throw "Nexus service 'nexus-webapp' is not installed" }
  37. if ($s.Status -ne 'Running') { Write-Warning "Nexus service 'nexus-webapp' is installed but not running" }
  38. $ok = $false
  39. try {
  40. $request = [System.Net.HttpWebRequest]::Create("http://localhost:8081/nexus")
  41. $response = $request.GetResponse()
  42. $ok = $response.StatusCode -eq 'OK'
  43. } catch {}
  44. if (!$ok) { Write-Warning "Nexus should be available at http://localhost:8081/nexus but can't be reached" }
  45. else { Write-Host "Nexus is available at http://localhost:8081/nexus" }