Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8ea1d6ac52 |
+20
-19
@@ -2,12 +2,13 @@ param(
|
|||||||
[string]$GiteaUrl = "https://gitea.digitoolsolutions.synology.me",
|
[string]$GiteaUrl = "https://gitea.digitoolsolutions.synology.me",
|
||||||
[string]$Owner = "lamtruong28",
|
[string]$Owner = "lamtruong28",
|
||||||
[string]$Repo = "mini-pc-setup",
|
[string]$Repo = "mini-pc-setup",
|
||||||
[object]$ReleaseJson =$null,
|
[object]$ReleaseJson = $null,
|
||||||
[pscredential]$Credential =$null
|
[pscredential]$Credential = $null
|
||||||
)
|
)
|
||||||
|
|
||||||
$ErrorActionPreference = "Stop"
|
$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"
|
$TempZip = "$env:TEMP\mini-pc-setup-release.zip"
|
||||||
$TempExtract = "$env:TEMP\mini-pc-release-extract"
|
$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 " DTS TORQUE VAULT - DOWNLOADING LATEST RELEASE" -ForegroundColor Cyan
|
||||||
Write-Host "========================================================" -ForegroundColor Cyan
|
Write-Host "========================================================" -ForegroundColor Cyan
|
||||||
|
|
||||||
if ($null -eq$ReleaseJson) {
|
if ($null -eq $ReleaseJson) {
|
||||||
$apiUrl = "$GiteaUrl/api/v1/repos/$Owner/$Repo/releases/latest"
|
$apiUrl = "$GiteaUrl/api/v1/repos/$Owner/$Repo/releases/latest"
|
||||||
try {
|
try {
|
||||||
$ReleaseJson = Invoke-RestMethod -Uri$apiUrl -UseBasicParsing
|
$ReleaseJson = Invoke-RestMethod -Uri $apiUrl -UseBasicParsing
|
||||||
} catch {
|
} catch {
|
||||||
Write-Host "[AUTH] Private repository detected. Please sign in to Gitea:" -ForegroundColor Yellow
|
Write-Host "[AUTH] Private repository detected. Please sign in to Gitea:" -ForegroundColor Yellow
|
||||||
$Credential = Get-Credential -Message "Enter Gitea Credentials"
|
$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
|
Write-Host "[INFO] Latest Release Tag: $TagName ($($ReleaseJson.name))" -ForegroundColor Green
|
||||||
|
|
||||||
$ZipAsset = $ReleaseJson.assets \vert{} Where-Object {$_.name -like "*.zip" } | Select-Object -First 1
|
$ZipAsset = $ReleaseJson.assets | Where-Object { $_.name -like "*.zip" } | Select-Object -First 1
|
||||||
if ($null -ne$ZipAsset) {
|
if ($null -ne $ZipAsset) {
|
||||||
$DownloadUrl =$ZipAsset.browser_download_url
|
$DownloadUrl = $ZipAsset.browser_download_url
|
||||||
Write-Host "[1/3] Downloading attached release asset: $($ZipAsset.name)..."
|
Write-Host "[1/3] Downloading attached release asset: $($ZipAsset.name)..."
|
||||||
} else {
|
} else {
|
||||||
$DownloadUrl =$ReleaseJson.zipball_url
|
$DownloadUrl = $ReleaseJson.zipball_url
|
||||||
Write-Host "[1/3] Downloading release archive ($TagName)..."
|
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
|
New-Item -ItemType Directory -Path $TargetDir -Force | Out-Null
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($null -ne$Credential) {
|
if ($null -ne $Credential) {
|
||||||
Invoke-WebRequest -Uri $DownloadUrl -OutFile $TempZip -Credential$Credential -UseBasicParsing
|
Invoke-WebRequest -Uri $DownloadUrl -OutFile $TempZip -Credential $Credential -UseBasicParsing
|
||||||
} else {
|
} else {
|
||||||
Invoke-WebRequest -Uri $DownloadUrl -OutFile$TempZip -UseBasicParsing
|
Invoke-WebRequest -Uri $DownloadUrl -OutFile $TempZip -UseBasicParsing
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "[2/3] Extracting files to $TargetDir..."
|
Write-Host "[2/3] Extracting files to $TargetDir..."
|
||||||
if (Test-Path $TempExtract) { Remove-Item$TempExtract -Recurse -Force }
|
if (Test-Path $TempExtract) { Remove-Item $TempExtract -Recurse -Force }
|
||||||
Expand-Archive -Path $TempZip -DestinationPath$TempExtract -Force
|
Expand-Archive -Path $TempZip -DestinationPath $TempExtract -Force
|
||||||
|
|
||||||
$TopDirs = Get-ChildItem -Path$TempExtract -Directory
|
$TopDirs = Get-ChildItem -Path $TempExtract -Directory
|
||||||
$TopFiles = Get-ChildItem -Path$TempExtract -File
|
$TopFiles = Get-ChildItem -Path $TempExtract -File
|
||||||
if ($TopFiles.Count -eq 0 -and$TopDirs.Count -eq 1) {
|
if ($TopFiles.Count -eq 0 -and $TopDirs.Count -eq 1) {
|
||||||
Copy-Item -Path "$($TopDirs[0].FullName)\*" -Destination $TargetDir -Recurse -Force
|
Copy-Item -Path "$($TopDirs[0].FullName)\*" -Destination $TargetDir -Recurse -Force
|
||||||
} else {
|
} else {
|
||||||
Copy-Item -Path "$TempExtract\*" -Destination $TargetDir -Recurse -Force
|
Copy-Item -Path "$TempExtract\*" -Destination $TargetDir -Recurse -Force
|
||||||
|
|||||||
+1
-20
@@ -24,26 +24,7 @@ echo ===========================================================================
|
|||||||
echo Repository : %GITEA_URL%/%REPO_OWNER%/%REPO_NAME%
|
echo Repository : %GITEA_URL%/%REPO_OWNER%/%REPO_NAME%
|
||||||
echo.
|
echo.
|
||||||
|
|
||||||
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
|
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"
|
||||||
"$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 (
|
if %errorLevel% neq 0 (
|
||||||
echo.
|
echo.
|
||||||
|
|||||||
Reference in New Issue
Block a user