75 lines
3.2 KiB
PowerShell
75 lines
3.2 KiB
PowerShell
param(
|
|
[string]$GiteaUrl = "https://gitea.digitoolsolutions.synology.me",
|
|
[string]$Owner = "lamtruong28",
|
|
[string]$Repo = "mini-pc-setup",
|
|
[object]$ReleaseJson = $null,
|
|
[pscredential]$Credential = $null
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
$GiteaUrl = $GiteaUrl.TrimEnd('/')
|
|
$TargetDir = "C:\Apps\mini-pc-setup"
|
|
$TempZip = "$env:TEMP\mini-pc-setup-release.zip"
|
|
$TempExtract = "$env:TEMP\mini-pc-release-extract"
|
|
|
|
Write-Host "========================================================" -ForegroundColor Cyan
|
|
Write-Host " DTS TORQUE VAULT - DOWNLOADING LATEST RELEASE" -ForegroundColor Cyan
|
|
Write-Host "========================================================" -ForegroundColor Cyan
|
|
|
|
if ($null -eq $ReleaseJson) {
|
|
$apiUrl = "$GiteaUrl/api/v1/repos/$Owner/$Repo/releases/latest"
|
|
try {
|
|
$ReleaseJson = Invoke-RestMethod -Uri $apiUrl -UseBasicParsing
|
|
} catch {
|
|
Write-Host "[AUTH] Private repository detected. Please sign in to Gitea:" -ForegroundColor Yellow
|
|
$Credential = Get-Credential -Message "Enter Gitea Credentials"
|
|
$ReleaseJson = Invoke-RestMethod -Uri $apiUrl -Credential $Credential -UseBasicParsing
|
|
}
|
|
}
|
|
|
|
$TagName = $ReleaseJson.tag_name
|
|
Write-Host "[INFO] Latest Release Tag: $TagName ($($ReleaseJson.name))" -ForegroundColor Green
|
|
|
|
$ZipAsset = $ReleaseJson.assets | Where-Object { $_.name -like "*.zip" } | Select-Object -First 1
|
|
if ($null -ne $ZipAsset) {
|
|
$DownloadUrl = $ZipAsset.browser_download_url
|
|
Write-Host "[1/3] Downloading attached release asset: $($ZipAsset.name)..."
|
|
} else {
|
|
$DownloadUrl = $ReleaseJson.zipball_url
|
|
Write-Host "[1/3] Downloading release archive ($TagName)..."
|
|
}
|
|
|
|
if (-not (Test-Path $TargetDir)) {
|
|
New-Item -ItemType Directory -Path $TargetDir -Force | Out-Null
|
|
}
|
|
|
|
if ($null -ne $Credential) {
|
|
Invoke-WebRequest -Uri $DownloadUrl -OutFile $TempZip -Credential $Credential -UseBasicParsing
|
|
} else {
|
|
Invoke-WebRequest -Uri $DownloadUrl -OutFile $TempZip -UseBasicParsing
|
|
}
|
|
|
|
Write-Host "[2/3] Extracting files to $TargetDir..."
|
|
if (Test-Path $TempExtract) { Remove-Item $TempExtract -Recurse -Force }
|
|
Expand-Archive -Path $TempZip -DestinationPath $TempExtract -Force
|
|
|
|
$TopDirs = Get-ChildItem -Path $TempExtract -Directory
|
|
$TopFiles = Get-ChildItem -Path $TempExtract -File
|
|
if ($TopFiles.Count -eq 0 -and $TopDirs.Count -eq 1) {
|
|
Copy-Item -Path "$($TopDirs[0].FullName)\*" -Destination $TargetDir -Recurse -Force
|
|
} else {
|
|
Copy-Item -Path "$TempExtract\*" -Destination $TargetDir -Recurse -Force
|
|
}
|
|
|
|
Remove-Item $TempZip -Force -ErrorAction SilentlyContinue
|
|
Remove-Item $TempExtract -Recurse -Force -ErrorAction SilentlyContinue
|
|
|
|
# Auto-create .env from .env.template if .env does not exist yet
|
|
if (-not (Test-Path "$TargetDir\.env") -and (Test-Path "$TargetDir\.env.template")) {
|
|
Copy-Item "$TargetDir\.env.template" "$TargetDir\.env"
|
|
Write-Host "[ACTION REQUIRED] Please configure '.env' in Notepad, save, and close it to continue..." -ForegroundColor Yellow
|
|
Start-Process notepad.exe "$TargetDir\.env" -Wait
|
|
}
|
|
|
|
Write-Host "[3/3] Launching scripts\install.bat..." -ForegroundColor Green
|
|
Start-Process -FilePath "$TargetDir\scripts\install.bat" -WorkingDirectory "$TargetDir\scripts" |