diff --git a/scripts/osv-startup.ps1 b/scripts/osv-startup.ps1 index 8213dbc..81aa360 100644 --- a/scripts/osv-startup.ps1 +++ b/scripts/osv-startup.ps1 @@ -10,24 +10,61 @@ $W = 54 Set-Location $REPO Clear-Host +# ---- GCLOUD PATH DETECTION ----------------------------------- +# Finn gcloud uavhengig av om den er i PATH +$gcloudCmd = $null +$gcloudPaths = @( + "gcloud", + "$env:LOCALAPPDATA\Google\Cloud SDK\google-cloud-sdk\bin\gcloud.cmd", + "$env:PROGRAMFILES\Google\Cloud SDK\google-cloud-sdk\bin\gcloud.cmd", + "$env:USERPROFILE\AppData\Local\Google\Cloud SDK\google-cloud-sdk\bin\gcloud.cmd" +) +foreach ($p in $gcloudPaths) { + try { + $null = & $p version 2>$null + if ($LASTEXITCODE -eq 0 -or $?) { $gcloudCmd = $p; break } + } catch {} +} + # ---- SJEKKER (stille) ---------------------------------------- -$gcOK = $false; $adcOK = $false; $opaxOK = $false; $gitOK = $false; $gcAcc = "" -$gitOut = git pull 2>&1; $gitOK = ($LASTEXITCODE -eq 0) -try { $gcAcc = gcloud auth list --filter=status:ACTIVE --format="value(account)" 2>$null - if ($gcAcc) { $gcOK = $true - gcloud config set project propane-will-491900-m5 2>$null | Out-Null - gcloud config set compute/region us-central1 2>$null | Out-Null } } catch {} -try { if (gcloud auth application-default print-access-token 2>$null) { $adcOK = $true } } catch {} -try { if ((Invoke-RestMethod -Uri $PING -TimeoutSec 5).status -eq 'ok') { $opaxOK = $true } } catch {} +$gcOK = $false; $adcOK = $false; $opaxOK = $false; $gitOK = $false +$gcAcc = ""; $gcNotInstalled = ($null -eq $gcloudCmd) + +$gitOut = git pull 2>&1 +$gitOK = ($LASTEXITCODE -eq 0) + +if (-not $gcNotInstalled) { + try { + $gcAcc = & $gcloudCmd auth list --filter=status:ACTIVE --format="value(account)" 2>$null + if ($gcAcc) { + $gcOK = $true + & $gcloudCmd config set project propane-will-491900-m5 2>$null | Out-Null + & $gcloudCmd config set compute/region us-central1 2>$null | Out-Null + } + } catch {} + try { + $t = & $gcloudCmd auth application-default print-access-token 2>$null + if ($t) { $adcOK = $true } + } catch {} +} + +try { + if ((Invoke-RestMethod -Uri $PING -TimeoutSec 5).status -eq 'ok') { $opaxOK = $true } +} catch {} $allOK = $gitOK -and $opaxOK -and $gcOK # ---- STATUS STRENGER ----------------------------------------- -if ($gitOK) { $gitTxt = "✅ Git : " + $(if ($gitOut -match 'Already') {'up to date'} else {'oppdatert'}) } -else { $gitTxt = "❌ Git : FEIL" } -$gcTxt = $(if ($gcOK) { "✅ GCP : " + ($gcAcc -replace '@vauco.no','') } else { "⚠ GCP : ikke logget inn" }) -$adcTxt = $(if ($adcOK) { "✅ ADC : OK" } else { "⚠ ADC : gcloud auth application-default login" }) -$opaxTxt = $(if ($opaxOK) { "✅ OPAX : opax.vauco.no" } else { "❌ OPAX : nede - sjekk Cloud Run" }) +$gitTxt = if ($gitOK) { if ($gitOut -match 'Already') { "✅ Git : up to date" } else { "✅ Git : oppdatert" } } + else { "❌ Git : FEIL" } +$gcTxt = if ($gcNotInstalled) { "ℹ GCP : gcloud ikke funnet — bruk Cloud Shell" } + elseif ($gcOK) { "✅ GCP : " + ($gcAcc -replace '@vauco.no','') } + else { "⚠ GCP : ikke logget inn — gcloud auth login" } +$adcTxt = if ($gcNotInstalled) { "ℹ ADC : ikke tilgjengelig i dette miljøet" } + elseif ($adcOK) { "✅ ADC : OK" } + else { "⚠ ADC : gcloud auth application-default login" } +$opaxTxt = if ($opaxOK) { "✅ OPAX : opax.vauco.no" } + else { "❌ OPAX : nede — sjekk Cloud Run" } # ---- HJELPEFUNKSJONER ---------------------------------------- function Pad($text, $width) { @@ -35,21 +72,12 @@ function Pad($text, $width) { return $text + (" " * ($width - $text.Length)) } -function GlowLine($cols) { - # $cols = array of [text, color] pairs filling $W chars - foreach ($c in $cols) { Write-Host $c[0] -NoNewline -ForegroundColor $c[1] } - Write-Host "" -} - function GlowBox($lines) { - $seg = [math]::Floor($W / 3) - $r = $W - $seg * 2 - # Top + $seg = [math]::Floor($W / 3); $r = $W - $seg * 2 Write-Host " " -NoNewline Write-Host ("█" * $seg) -NoNewline -ForegroundColor Magenta Write-Host ("█" * $seg) -NoNewline -ForegroundColor DarkGreen Write-Host ("█" * $r) -ForegroundColor Green - # Lines foreach ($line in $lines) { $inner = Pad $line ($W - 4) Write-Host " " -NoNewline @@ -57,64 +85,22 @@ function GlowBox($lines) { Write-Host (" $inner ") -NoNewline -ForegroundColor Green Write-Host "█" -ForegroundColor Green } - # Bottom (reversed) Write-Host " " -NoNewline Write-Host ("█" * $r) -NoNewline -ForegroundColor Green Write-Host ("█" * $seg) -NoNewline -ForegroundColor DarkGreen Write-Host ("█" * $seg) -ForegroundColor Magenta } -function PulseBox($lines) { - # Animate border: cycle Magenta->DarkGreen->Green->DarkGreen->Magenta (3 frames) - $frames = @( - @('Magenta','DarkGreen','Green'), - @('DarkGreen','Green','Magenta'), - @('Green','Magenta','DarkGreen') - ) - $seg = [math]::Floor($W / 3); $r = $W - $seg * 2 - foreach ($f in $frames) { - # Move cursor up to overwrite (skip on first frame) - $top = " " + ($f[0] * 0) # just use colors - [System.Console]::SetCursorPosition(0, [System.Console]::CursorTop) - Write-Host " " -NoNewline - Write-Host ("█" * $seg) -NoNewline -ForegroundColor $f[0] - Write-Host ("█" * $seg) -NoNewline -ForegroundColor $f[1] - Write-Host ("█" * $r) -ForegroundColor $f[2] - foreach ($line in $lines) { - $inner = Pad $line ($W - 4) - Write-Host " " -NoNewline - Write-Host "█" -NoNewline -ForegroundColor $f[0] - Write-Host (" $inner ") -NoNewline -ForegroundColor Green - Write-Host "█" -ForegroundColor $f[2] - } - Write-Host " " -NoNewline - Write-Host ("█" * $r) -NoNewline -ForegroundColor $f[2] - Write-Host ("█" * $seg) -NoNewline -ForegroundColor $f[1] - Write-Host ("█" * $seg) -ForegroundColor $f[0] - Start-Sleep -Milliseconds 180 - # Move cursor back up - $moveUp = $lines.Count + 2 - for ($i = 0; $i -lt $moveUp; $i++) { - Write-Host "`e[1A" -NoNewline - } - } - # Final static draw - GlowBox $lines -} - function DocBox($line) { - # Each doc commit gets its own mini glow box - $hash = "" - $date = "" - $msg = $line + $hash = ""; $date = ""; $msg = $line if ($line -match '^([0-9a-f]{7}) (\d{4}-\d{2}-\d{2}) (.+)$') { $hash = $matches[1]; $date = $matches[2]; $msg = $matches[3] } - $msgPad = Pad $msg ($W - 6) Write-Host " " -NoNewline - Write-Host "┌─" -NoNewline -ForegroundColor DarkGreen + Write-Host "┌─ " -NoNewline -ForegroundColor DarkGreen Write-Host $hash -NoNewline -ForegroundColor Green - Write-Host " $date" -ForegroundColor DarkGreen + Write-Host " $date" -ForegroundColor DarkGreen + $msgPad = Pad $msg ($W - 4) Write-Host " " -NoNewline Write-Host "│ " -NoNewline -ForegroundColor DarkGreen Write-Host $msgPad -ForegroundColor Green @@ -124,18 +110,17 @@ function DocBox($line) { } function StatusLine($text) { - $col = if ($text -match "^✅") { 'Green' } elseif ($text -match "^❌") { 'Red' } else { 'Yellow' } - $glyph = if ($text -match "^✅") { "▓" } else { "░" } - Write-Host " " -NoNewline - Write-Host $glyph -NoNewline -ForegroundColor $col - Write-Host (" $text") -ForegroundColor $col + $col = if ($text -match "^✅") { 'Green' } elseif ($text -match "^❌") { 'Red' } elseif ($text -match "^⚠") { 'Yellow' } else { 'Cyan' } + $glyph = if ($text -match "^✅") { "▓" } elseif ($text -match "^❌") { "░" } else { "▒" } + Write-Host " $glyph " -NoNewline -ForegroundColor $col + Write-Host $text -ForegroundColor $col } # ============================================================== -# TOPP PULSE-BOKS +# TOPP BOKS # ============================================================== Write-Host "" -PulseBox @( +GlowBox @( "", " O S V A U C O · O P A X", " us-central1 · gemini-2.5-pro", @@ -154,19 +139,16 @@ if (Test-Path $LOG) { if ($m.Success) { $nesteLines = $m.Groups[1].Value.Trim() -split "`n" | Where-Object { $_.Trim() -and $_.Trim() -ne '---' } | - Select-Object -First 3 | - ForEach-Object { $_.Trim() } + Select-Object -First 3 | ForEach-Object { $_.Trim() } } } -# Egen boks per linje foreach ($nl in $nesteLines) { Write-Host " " -NoNewline Write-Host "┌" -NoNewline -ForegroundColor Magenta Write-Host ("─" * ($W - 2)) -ForegroundColor Magenta - $inner = Pad $nl ($W - 4) Write-Host " " -NoNewline Write-Host "│ " -NoNewline -ForegroundColor Magenta - Write-Host $inner -ForegroundColor Green + Write-Host (Pad $nl ($W - 4)) -ForegroundColor Green Write-Host " " -NoNewline Write-Host "└" -NoNewline -ForegroundColor Magenta Write-Host ("─" * ($W - 2)) -ForegroundColor Magenta @@ -174,7 +156,7 @@ foreach ($nl in $nesteLines) { Write-Host "" # ============================================================== -# SISTE DOCS — egen boks per commit +# SISTE DOCS # ============================================================== Write-Host " ■ SISTE DOCS" -ForegroundColor Magenta $docLines = git -C $REPO log -3 --pretty=format:"%h %cd %s" --date=short -- docs 2>&1 | @@ -184,7 +166,7 @@ foreach ($dl in $docLines) { DocBox $dl } Write-Host "" # ============================================================== -# STATUS — glow per linje +# STATUS # ============================================================== Write-Host " ■ STATUS" -ForegroundColor Magenta StatusLine $gitTxt @@ -194,16 +176,14 @@ StatusLine $opaxTxt Write-Host "" # ============================================================== -# BUNN PULSE-BOKS +# BUNN BOKS # ============================================================== if ($allOK) { - PulseBox @("", " ▶▶ ALL SYSTEMS GREEN ◀◀", "") + GlowBox @("", " ▶▶ ALL SYSTEMS GREEN ◀◀", "") } else { - Write-Host " " -NoNewline - Write-Host ("█" * $W) -ForegroundColor Yellow + Write-Host " " -NoNewline; Write-Host ("█" * $W) -ForegroundColor Yellow Write-Host " █ ⚠ PARTIAL — sjekk status over" -ForegroundColor Yellow - Write-Host " " -NoNewline - Write-Host ("█" * $W) -ForegroundColor Yellow + Write-Host " " -NoNewline; Write-Host ("█" * $W) -ForegroundColor Yellow } Write-Host ""