Files
gomag-vending/update.ps1
Claude Agent 27af22d241 update
2026-03-16 17:56:09 +00:00

80 lines
2.2 KiB
PowerShell

# GoMag Vending - Update Script
# Ruleaza interactiv: .\update.ps1
# Ruleaza din scheduler: .\update.ps1 -Silent
param(
[switch]$Silent
)
$RepoPath = "C:\gomag-vending"
$TokenFile = Join-Path $RepoPath ".gittoken"
$LogFile = Join-Path $RepoPath "update.log"
function Log($msg, $color = "White") {
$ts = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
if ($Silent) {
Add-Content -Path $LogFile -Value "$ts $msg"
} else {
Write-Host $msg -ForegroundColor $color
}
}
# Citire token
if (-not (Test-Path $TokenFile)) {
Log "EROARE: $TokenFile nu exista!" "Red"
exit 1
}
$token = (Get-Content $TokenFile -Raw).Trim()
# Safe directory (necesar cand ruleaza ca SYSTEM)
git config --global --add safe.directory $RepoPath 2>$null
# Fetch remote
Set-Location $RepoPath
$fetchUrl = "https://gomag-vending:$token@gitea.romfast.ro/romfast/gomag-vending.git"
$env:GIT_TERMINAL_PROMPT = "0"
$fetchOutput = & git -c credential.helper="" fetch $fetchUrl main 2>&1
$fetchExit = $LASTEXITCODE
if ($fetchExit -ne 0) {
Log "EROARE: git fetch esuat (exit=$fetchExit): $fetchOutput" "Red"
exit 1
}
# Compara local vs remote
$local = git rev-parse HEAD
$remote = git rev-parse FETCH_HEAD
if ($local -eq $remote) {
Log "Nicio actualizare disponibila." "Gray"
exit 0
}
# Exista update-uri
$commits = git log --oneline "$local..$remote"
Log "==> Update disponibil ($($commits.Count) commit-uri noi)" "Cyan"
if (-not $Silent) {
$commits | ForEach-Object { Write-Host " $_" -ForegroundColor DarkGray }
}
# Git pull
Log "==> Git pull..." "Cyan"
$pullOutput = & git -c credential.helper="" pull $fetchUrl 2>&1
$pullExit = $LASTEXITCODE
if ($pullExit -ne 0) {
Log "EROARE: git pull esuat (exit=$pullExit): $pullOutput" "Red"
exit 1
}
# Pip install (daca s-au schimbat dependintele)
Log "==> Verificare dependinte..." "Cyan"
& "$RepoPath\venv\Scripts\pip.exe" install -r "$RepoPath\api\requirements.txt" --quiet 2>&1 | Out-Null
# Restart serviciu
Log "==> Restart GoMagVending..." "Cyan"
nssm restart GoMagVending 2>&1 | Out-Null
Start-Sleep -Seconds 3
$status = (nssm status GoMagVending 2>&1) -replace '\0',''
Log "Serviciu: $status" "Green"
Log "Update complet!" "Green"