OSVauco/scripts/osv-startup.ps1

133 lines
5.9 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# OSVauco · OPAX — VS Code Windows Startup
# settings.json: "args": ["-NoExit","-File","G:\\Shared drives\\OS-VAUCO-DRIVE\\OSVauco\\scripts\\osv-startup.ps1"]
$REPO = "G:\Shared drives\OS-VAUCO-DRIVE\OSVauco"
$PING = "https://opax.vauco.no/ping"
$LOG = "$REPO\docs\OSVAUCO_OPAX_SESSION_LOG.md"
$W = 52
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
Set-Location $REPO
Clear-Host
$gcOK = $adcOK = $opaxOK = $gitOK = $false
$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 {}
$allOK = $gitOK -and $opaxOK -and $gcOK
$IC = if ($allOK) { 'Green' } else { 'Gray' }
# Gradient top-border: Magenta -> DarkGreen -> Green
$G1 = 'Magenta'; $G2 = 'DarkGreen'; $G3 = 'Green'
function GlowBox($lines) {
# Top border — gradient left=purple, mid=darkgreen, right=green
$seg = [math]::Floor($W / 3)
Write-Host " " -NoNewline
Write-Host ("" * $seg) -NoNewline -ForegroundColor $G1
Write-Host ("" * $seg) -NoNewline -ForegroundColor $G2
Write-Host ("" * ($W - $seg*2)) -ForegroundColor $G3
foreach ($line in $lines) {
$pad = $W - 4 - $line.Length
if ($pad -lt 0) { $line = $line.Substring(0, $W - 5) + ""; $pad = 0 }
Write-Host " " -NoNewline
Write-Host "" -NoNewline -ForegroundColor $G1
Write-Host (" " + $line + (" " * $pad) + " ") -NoNewline -ForegroundColor Green
Write-Host "" -ForegroundColor $G3
}
# Bottom border — gradient right=purple, mid=darkgreen, left=green
Write-Host " " -NoNewline
Write-Host ("" * ($W - $seg*2)) -NoNewline -ForegroundColor $G3
Write-Host ("" * $seg) -NoNewline -ForegroundColor $G2
Write-Host ("" * $seg) -ForegroundColor $G1
}
function ThinBox($lines, $titleColor) {
Write-Host " " -NoNewline
Write-Host ("" * $W) -ForegroundColor $titleColor
foreach ($line in $lines) {
$pad = $W - 4 - $line.Length
if ($pad -lt 0) { $line = $line.Substring(0, $W - 5) + ""; $pad = 0 }
$ok = $line -match "^✅"
$col = if ($ok) { 'Green' } else { 'Gray' }
Write-Host " " -NoNewline
Write-Host "" -NoNewline -ForegroundColor $titleColor
Write-Host (" " + $line + (" " * ($pad+1))) -ForegroundColor $col
}
Write-Host " " -NoNewline
Write-Host ("" * $W) -ForegroundColor $titleColor
}
# ══ TOPP GLOW-BOKS ══════════════════════════════════════════
Write-Host ""
GlowBox @(
"",
" O S V A U C O · O P A X",
" us-central1 · gemini-2.5-pro",
" $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')",
""
)
Write-Host ""
# ══ NESTE OPPGAVE ═══════════════════════════════════════════
Write-Host " ■ NESTE OPPGAVE" -ForegroundColor Magenta
$nesteLines = @()
if (Test-Path $LOG) {
$m = [regex]::Match((Get-Content $LOG -Raw -Encoding UTF8),'(?s)## NESTE OPPGAVE\r?\n(.*?)(?=\r?\n## |$)')
if ($m.Success) {
$nesteLines = $m.Groups[1].Value.Trim() -split "`n" |
Where-Object { $_.Trim() -and $_.Trim() -ne '---' } |
Select-Object -First 2 |
ForEach-Object { $_.Trim() }
}
}
if (-not $nesteLines) { $nesteLines = @("Sjekk docs/VAUCO_OS_ROADMAP.md") }
ThinBox $nesteLines Magenta
Write-Host ""
# ══ DOCS ════════════════════════════════════════════════════
Write-Host " ■ SISTE DOCS" -ForegroundColor Magenta
$docLines = git -C $REPO log -3 --pretty=format:"%h %cd %s" --date=short -- docs 2>&1 |
ForEach-Object { ($_ -replace '[^\x00-\x7F\u00e6\u00f8\u00e5\u00c6\u00d8\u00c5\u2014\u2013]+','').Trim() }
ThinBox $docLines DarkGreen
Write-Host ""
# ══ STATUS ══════════════════════════════════════════════════
Write-Host " ■ STATUS" -ForegroundColor Magenta
$statusLines = @(
("✅ Git : " + (if ($gitOut -match 'Already') {'up to date'} else {'oppdatert'})),
((if ($gcOK) {'✅'} else {'⚠ '}) + " GCP : " + ($gcAcc -replace '@vauco.no','')),
((if ($adcOK) {'✅'} else {'⚠ '}) + " ADC : " + (if ($adcOK) {'OK'} else {'gcloud auth application-default login'})),
((if ($opaxOK) {'✅'} else {'❌'}) + " OPAX : opax.vauco.no")
)
ThinBox $statusLines Magenta
Write-Host ""
# ══ BUNN GLOW-BOKS ══════════════════════════════════════════
if ($allOK) {
GlowBox @("", " ▶▶ ALL SYSTEMS GREEN ◀◀", "")
} else {
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 ""
# ══ CUSTOM PROMPT ═══════════════════════════════════════════
function prompt {
Write-Host " G:\Shared-drives\" -NoNewline -ForegroundColor Magenta
Write-Host "OS" -NoNewline -ForegroundColor White
Write-Host "Vauco" -NoNewline -ForegroundColor Green
Write-Host " " -NoNewline -ForegroundColor Green
return " "
}