Skip to content

Instantly share code, notes, and snippets.

@wildone
Last active June 15, 2020 12:19
Show Gist options
  • Save wildone/8b2d4e1cca81ff9fc3c6eb4f587d1465 to your computer and use it in GitHub Desktop.
Save wildone/8b2d4e1cca81ff9fc3c6eb4f587d1465 to your computer and use it in GitHub Desktop.

Revisions

  1. wildone renamed this gist Jun 15, 2020. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. wildone renamed this gist Jun 15, 2020. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. wildone created this gist Jun 15, 2020.
    91 changes: 91 additions & 0 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,91 @@

    function WaitForUrlContent {
    [CmdletBinding()]
    Param (
    [Parameter(Mandatory=$true)]
    [string]$ResponseContentNoPresent,

    [Parameter(Mandatory=$false)]
    [string]$Url="http://localhost:4502",

    [Parameter(Mandatory=$false,
    HelpMessage="Provide Basic Auth Credentials in following format: <user>:<pass>")]
    [string]$BasicAuthCreds="",

    [Parameter(Mandatory=$false)]
    [string]$UserAgent="",

    [Parameter(Mandatory=$false)]
    [string]$Referer="",

    [Parameter(Mandatory=$false)]
    [string]$Timeout="5"

    )



    $HEADERS = @{
    }

    if (-not([string]::IsNullOrEmpty($UserAgent))) {
    $HEADERS.add("User-Agent",$UserAgent)
    }

    if (-not([string]::IsNullOrEmpty($Referer))) {
    $HEADERS.add("Referer",$Referer)
    }


    if (-not([string]::IsNullOrEmpty($BasicAuthCreds))) {
    $BASICAUTH = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($BasicAuthCreds))
    $HEADERS.add("Authorization","Basic $BASICAUTH")
    }


    Write-Host -NoNewline "Waiting for: $Url"

    $FirstError=$true
    $LastError=""


    while ($true) {
    try {
    $response = Invoke-WebRequest -Headers $HEADERS -TimeoutSec $Timeout -Uri "$Url"
    $StatusCode = $Response.StatusCode
    } catch {
    $StatusCode = $_.Exception.Response.StatusCode.value__
    $LastError = $StatusCode
    if ($FirstError -Or $LastError -ne $StatusCode) {
    Write-Host -NoNewline " (Error: $StatusCode)"
    $FirstError=$false
    }
    }

    if( $StatusCode -ne 200 -Or $response.content.contains($ResponseContentNoPresent)) {
    sleep 1
    Write-Host -NoNewline "."
    } else {
    break
    }

    }

    }



    $SERVER_PATH = "/system/console/bundles.json"

    $LOGIN = "admin:admin"
    $SERVER_HOST = "localhost"
    $PROTOCOL = "http"
    $PORT = 4502
    $TIMEOUT = 5

    $ADDRESS = "${PROTOCOL}://${SERVER_HOST}:${PORT}"

    WaitForUrlContent -ResponseContentNoPresent '"state":"Installed"' -Referer $ADDRESS -UserAgent "curl" -Url ${ADDRESS}${SERVER_PATH} -BasicAuthCreds $LOGIN -Timeout $TIMEOUT