[Fix] Auto start WSL

This commit is contained in:
2026-11-15 18:15:00 +07:00
parent f23e85f348
commit 62100913ae
2 changed files with 28 additions and 45 deletions
+7 -43
View File
@@ -7,7 +7,7 @@ setlocal EnableDelayedExpansion
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%"
set "EXTRACT_DIR=C:\Apps\%REPO_NAME%"
:: ============================================================================
:: 0. AUTO-ELEVATE TO ADMINISTRATOR
@@ -22,17 +22,15 @@ if %errorLevel% neq 0 (
echo ============================================================================
echo DTS TORQUE VAULT - ONE-CLICK LATEST RELEASE BOOTSTRAPPER
echo ============================================================================
echo Repository : %GITEA_URL%/%REPO_OWNER%/%REPO_NAME%
echo Repository : %GITEA_URL%/%REPO_OWNER%/%REPO_NAME%
echo Destination : %EXTRACT_DIR%
echo.
:: ============================================================================
:: 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 }"
powershell -NoProfile -ExecutionPolicy Bypass -Command "$h=([System.Uri]'%GITEA_URL%').Host; try { [System.Net.Dns]::GetHostAddresses($h) | Out-Null; exit 0 } catch { Write-Host '[ERROR] Cannot resolve DNS for' $h '- Check Internet.' -ForegroundColor Red; exit 1 }"
if %errorLevel% neq 0 (
pause
exit /b 1
@@ -45,33 +43,7 @@ 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"
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.
@@ -86,18 +58,10 @@ 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"
powershell -NoProfile -ExecutionPolicy Bypass -Command "$tmp = Join-Path $env:TEMP 'dts_release_extract'; if (Test-Path $tmp) { Remove-Item $tmp -Recurse -Force }; Expand-Archive -Path '%ZIP_FILE%' -DestinationPath $tmp -Force; $inner = Get-ChildItem -Path $tmp -Directory | Select-Object -First 1; if ($inner) { Get-ChildItem -Path $inner.FullName -Force | Copy-Item -Destination '%EXTRACT_DIR%' -Recurse -Force } else { Get-ChildItem -Path $tmp -Force | Copy-Item -Destination '%EXTRACT_DIR%' -Recurse -Force }; Remove-Item $tmp -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!
echo [ERROR] scripts\install.bat not found inside %EXTRACT_DIR%!
pause
exit /b 1
)