Test and update scripts on mini pc
This commit is contained in:
+78
-7
@@ -1,5 +1,5 @@
|
||||
@echo off
|
||||
setlocal
|
||||
setlocal EnableDelayedExpansion
|
||||
|
||||
:: ============================================================================
|
||||
:: CONFIGURATION
|
||||
@@ -7,9 +7,10 @@ setlocal
|
||||
set "GITEA_URL=https://gitea.digitoolsolutions.synology.me"
|
||||
set "REPO_OWNER=lamtruong28"
|
||||
set "REPO_NAME=mini-pc-setup"
|
||||
set "EXTRACT_DIR=%USERPROFILE%\Apps\%REPO_NAME%"
|
||||
|
||||
:: ============================================================================
|
||||
:: AUTO-ELEVATE TO ADMINISTRATOR
|
||||
:: 0. AUTO-ELEVATE TO ADMINISTRATOR
|
||||
:: ============================================================================
|
||||
net session >nul 2>&1
|
||||
if %errorLevel% neq 0 (
|
||||
@@ -24,11 +25,81 @@ 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"
|
||||
|
||||
:: ============================================================================
|
||||
:: 1. PRE-CHECK DNS & INTERNET CONNECTIVITY
|
||||
:: ============================================================================
|
||||
echo [1/3] Checking network and DNS resolution for %GITEA_URL%...
|
||||
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
|
||||
"$hostName = ([System.Uri]'%GITEA_URL%').Host;" ^
|
||||
"try { [System.Net.Dns]::GetHostAddresses($hostName) | Out-Null; exit 0 }" ^
|
||||
"catch { Write-Host '[ERROR] Cannot resolve DNS for' $hostName '- Check Internet.' -ForegroundColor Red; exit 1 }"
|
||||
if %errorLevel% neq 0 (
|
||||
echo.
|
||||
echo [ERROR] Bootstrap failed. Verify that at least one Release exists on Gitea.
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
)
|
||||
|
||||
:: ============================================================================
|
||||
:: 2. FETCH LATEST RELEASE (PUBLIC FIRST, AUTH ONLY ON HTTP 401/403/404)
|
||||
:: ============================================================================
|
||||
echo [2/3] Fetching latest release package...
|
||||
set "ZIP_FILE=%TEMP%\%REPO_NAME%-latest.zip"
|
||||
if exist "%ZIP_FILE%" del /f /q "%ZIP_FILE%" >nul 2>&1
|
||||
|
||||
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
|
||||
"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;" ^
|
||||
"$apiUrl = '%GITEA_URL%/api/v1/repos/%REPO_OWNER%/%REPO_NAME%/releases/latest';" ^
|
||||
"$outZip = '%ZIP_FILE%';" ^
|
||||
"$headers = @{ 'User-Agent' = 'DTS-Bootstrapper' };" ^
|
||||
"$needAuth = $false;" ^
|
||||
"try {" ^
|
||||
" $rel = Invoke-RestMethod -Uri $apiUrl -Headers $headers -ErrorAction Stop;" ^
|
||||
"} catch {" ^
|
||||
" $status = $null;" ^
|
||||
" if ($_.Exception.Response) { $status = [int]$_.Exception.Response.StatusCode }" ^
|
||||
" if ($status -in @(401, 403, 404)) { $needAuth = $true }" ^
|
||||
" else { Write-Host ('[ERROR] Network/SSL error connecting to Gitea: ' + $_.Exception.Message) -ForegroundColor Red; exit 1 }" ^
|
||||
"}" ^
|
||||
"if ($needAuth) {" ^
|
||||
" Write-Host '[AUTH] Private repository or restricted release. Please sign in to Gitea:';" ^
|
||||
" $cred = Get-Credential -UserName '%REPO_OWNER%' -Message 'Enter Gitea credentials';" ^
|
||||
" if (-not $cred) { exit 1 }" ^
|
||||
" $pair = '{0}:{1}' -f $cred.UserName, $cred.GetNetworkCredential().Password;" ^
|
||||
" $headers['Authorization'] = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes($pair));" ^
|
||||
" try { $rel = Invoke-RestMethod -Uri $apiUrl -Headers $headers -ErrorAction Stop }" ^
|
||||
" catch { Write-Host ('[ERROR] Gitea authentication or release lookup failed: ' + $_.Exception.Message) -ForegroundColor Red; exit 1 }" ^
|
||||
"}" ^
|
||||
"$zipUrl = $rel.zipball_url;" ^
|
||||
"if (-not $zipUrl) { Write-Host '[ERROR] No release zipball found. Ensure at least one Release is published on Gitea.' -ForegroundColor Red; exit 1 }" ^
|
||||
"Write-Host (' - Downloading release ' + $rel.tag_name + '...');" ^
|
||||
"Invoke-WebRequest -Uri $zipUrl -Headers $headers -OutFile $outZip -UseBasicParsing -ErrorAction Stop"
|
||||
|
||||
if %errorLevel% neq 0 (
|
||||
echo [ERROR] Bootstrap failed.
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
:: ============================================================================
|
||||
:: 3. EXTRACT & LAUNCH INSTALLER
|
||||
:: ============================================================================
|
||||
echo [3/3] Extracting to %EXTRACT_DIR% and launching install.bat...
|
||||
if exist "%EXTRACT_DIR%" rmdir /s /q "%EXTRACT_DIR%" >nul 2>&1
|
||||
mkdir "%EXTRACT_DIR%" >nul 2>&1
|
||||
|
||||
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
|
||||
"$tmpExtract = Join-Path $env:TEMP 'dts_release_extract';" ^
|
||||
"if (Test-Path $tmpExtract) { Remove-Item $tmpExtract -Recurse -Force }" ^
|
||||
"Expand-Archive -Path '%ZIP_FILE%' -DestinationPath $tmpExtract -Force;" ^
|
||||
"$inner = Get-ChildItem -Path $tmpExtract -Directory | Select-Object -First 1;" ^
|
||||
"if ($inner) { Copy-Item -Path (Join-Path $inner.FullName '*') -Destination '%EXTRACT_DIR%' -Recurse -Force }" ^
|
||||
"else { Copy-Item -Path (Join-Path $tmpExtract '*') -Destination '%EXTRACT_DIR%' -Recurse -Force }" ^
|
||||
"Remove-Item $tmpExtract -Recurse -Force;" ^
|
||||
"Remove-Item '%ZIP_FILE%' -Force"
|
||||
|
||||
if not exist "%EXTRACT_DIR%\scripts\install.bat" (
|
||||
echo [ERROR] scripts\install.bat not found inside the extracted release!
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
call "%EXTRACT_DIR%\scripts\install.bat"
|
||||
Reference in New Issue
Block a user