Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
27680382fa | ||
|
|
8ea1d6ac52 |
+25
-20
@@ -2,12 +2,13 @@ param(
|
||||
[string]$GiteaUrl = "https://gitea.digitoolsolutions.synology.me",
|
||||
[string]$Owner = "lamtruong28",
|
||||
[string]$Repo = "mini-pc-setup",
|
||||
[object]$ReleaseJson =$null,
|
||||
[pscredential]$Credential =$null
|
||||
[object]$ReleaseJson = $null,
|
||||
[pscredential]$Credential = $null
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
$GiteaUrl = $GiteaUrl.TrimEnd('/')$TargetDir = "C:\Apps\mini-pc-setup"
|
||||
$GiteaUrl = $GiteaUrl.TrimEnd('/')
|
||||
$TargetDir = "C:\Apps\mini-pc-setup"
|
||||
$TempZip = "$env:TEMP\mini-pc-setup-release.zip"
|
||||
$TempExtract = "$env:TEMP\mini-pc-release-extract"
|
||||
|
||||
@@ -15,26 +16,26 @@ Write-Host "========================================================" -Foregroun
|
||||
Write-Host " DTS TORQUE VAULT - DOWNLOADING LATEST RELEASE" -ForegroundColor Cyan
|
||||
Write-Host "========================================================" -ForegroundColor Cyan
|
||||
|
||||
if ($null -eq$ReleaseJson) {
|
||||
if ($null -eq $ReleaseJson) {
|
||||
$apiUrl = "$GiteaUrl/api/v1/repos/$Owner/$Repo/releases/latest"
|
||||
try {
|
||||
$ReleaseJson = Invoke-RestMethod -Uri$apiUrl -UseBasicParsing
|
||||
$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
|
||||
$ReleaseJson = Invoke-RestMethod -Uri $apiUrl -Credential $Credential -UseBasicParsing
|
||||
}
|
||||
}
|
||||
|
||||
$TagName =$ReleaseJson.tag_name
|
||||
$TagName = $ReleaseJson.tag_name
|
||||
Write-Host "[INFO] Latest Release Tag: $TagName ($($ReleaseJson.name))" -ForegroundColor Green
|
||||
|
||||
$ZipAsset = $ReleaseJson.assets \vert{} Where-Object {$_.name -like "*.zip" } | Select-Object -First 1
|
||||
if ($null -ne$ZipAsset) {
|
||||
$DownloadUrl =$ZipAsset.browser_download_url
|
||||
$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
|
||||
$DownloadUrl = $ReleaseJson.zipball_url
|
||||
Write-Host "[1/3] Downloading release archive ($TagName)..."
|
||||
}
|
||||
|
||||
@@ -42,19 +43,19 @@ 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
|
||||
if ($null -ne $Credential) {
|
||||
Invoke-WebRequest -Uri $DownloadUrl -OutFile $TempZip -Credential $Credential -UseBasicParsing
|
||||
} else {
|
||||
Invoke-WebRequest -Uri $DownloadUrl -OutFile$TempZip -UseBasicParsing
|
||||
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
|
||||
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) {
|
||||
$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
|
||||
@@ -71,4 +72,8 @@ if (-not (Test-Path "$TargetDir\.env") -and (Test-Path "$TargetDir\.env.template
|
||||
}
|
||||
|
||||
Write-Host "[3/3] Launching scripts\install.bat..." -ForegroundColor Green
|
||||
Start-Process -FilePath "$TargetDir\scripts\install.bat" -WorkingDirectory "$TargetDir\scripts"
|
||||
$InstallScript = "$TargetDir\scripts\install.bat"
|
||||
if (-not (Test-Path $InstallScript)) {
|
||||
throw "Cannot find $InstallScript after extraction!"
|
||||
}
|
||||
Start-Process -FilePath "cmd.exe" -ArgumentList "/c `"$InstallScript`"" -WorkingDirectory "$TargetDir\scripts"
|
||||
+1
-20
@@ -24,26 +24,7 @@ echo ===========================================================================
|
||||
echo Repository : %GITEA_URL%/%REPO_OWNER%/%REPO_NAME%
|
||||
echo.
|
||||
|
||||
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
|
||||
"$ErrorActionPreference = 'Stop';" ^
|
||||
"$base = '%GITEA_URL%'.TrimEnd('/'); $owner = '\%REPO_OWNER\%';$repo = '%REPO_NAME%';" ^
|
||||
"$apiUrl = \"$base/api/v1/repos/$owner/$repo/releases/latest\";" ^
|
||||
"$cred =$null;" ^
|
||||
"try {" ^
|
||||
" $rel = Invoke-RestMethod -Uri$apiUrl -UseBasicParsing;" ^
|
||||
"} catch {" ^
|
||||
" Write-Host '[AUTH] Private repository detected. Please sign in to Gitea:' -ForegroundColor Yellow;" ^
|
||||
" $cred = Get-Credential -Message 'Enter Gitea Credentials';" ^
|
||||
" $rel = Invoke-RestMethod -Uri $apiUrl -Credential$cred -UseBasicParsing;" ^
|
||||
"}" ^
|
||||
"$tag =$rel.tag_name;" ^
|
||||
"$rawUrl = \"$base/$owner/$repo/raw/tag/$tag/scripts/bootstrap.ps1\";" ^
|
||||
"if ($null -ne$cred) {" ^
|
||||
" $script = Invoke-RestMethod -Uri $rawUrl -Credential$cred -UseBasicParsing;" ^
|
||||
"} else {" ^
|
||||
" $script = Invoke-RestMethod -Uri$rawUrl -UseBasicParsing;" ^
|
||||
"}" ^
|
||||
"& ([scriptblock]::Create($script)) -GiteaUrl$base -Owner $owner -Repo$repo -ReleaseJson $rel -Credential$cred"
|
||||
powershell -NoProfile -ExecutionPolicy Bypass -Command "$ErrorActionPreference='Stop'; $base='%GITEA_URL%'.TrimEnd('/'); $owner='%REPO_OWNER%'; $repo='%REPO_NAME%'; $apiUrl=\"$base/api/v1/repos/$owner/$repo/releases/latest\"; $cred=$null; try { $rel=Invoke-RestMethod -Uri $apiUrl -UseBasicParsing } catch { Write-Host '[AUTH] Private repository detected. Please sign in to Gitea:' -ForegroundColor Yellow; $cred=Get-Credential -Message 'Enter Gitea Credentials'; $rel=Invoke-RestMethod -Uri $apiUrl -Credential $cred -UseBasicParsing }; $tag=$rel.tag_name; $rawUrl=\"$base/$owner/$repo/raw/tag/$tag/scripts/bootstrap.ps1\"; if ($null -ne $cred) { $script=Invoke-RestMethod -Uri $rawUrl -Credential $cred -UseBasicParsing } else { $script=Invoke-RestMethod -Uri $rawUrl -UseBasicParsing }; & ([scriptblock]::Create($script)) -GiteaUrl $base -Owner $owner -Repo $repo -ReleaseJson $rel -Credential $cred"
|
||||
|
||||
if %errorLevel% neq 0 (
|
||||
echo.
|
||||
|
||||
Reference in New Issue
Block a user