1 Commits
Author SHA1 Message Date
lamtruong28 62100913ae [Fix] Auto start WSL 2026-11-15 18:15:00 +07:00
2 changed files with 28 additions and 45 deletions
+21 -2
View File
@@ -305,13 +305,32 @@ if %errorLevel% neq 0 (
wmic useraccount where name="%KIOSK_USER%" set PasswordExpires=False >nul 2>&1 wmic useraccount where name="%KIOSK_USER%" set PasswordExpires=False >nul 2>&1
net user "%KIOSK_USER%" /logonpasswordchg:no >nul 2>&1 net user "%KIOSK_USER%" /logonpasswordchg:no >nul 2>&1
echo [6/7] Applying Kiosk Shell, Auto-Logon and Persistent Browser Profile... echo [6/7] Applying Kiosk Shell, Auto-Logon, WSL Boot Task and Browser Profile...
if not exist "%KIOSK_DATA_DIR%" mkdir "%KIOSK_DATA_DIR%" if not exist "%KIOSK_DATA_DIR%" mkdir "%KIOSK_DATA_DIR%"
if not exist "%KIOSK_APP_DIR%" mkdir "%KIOSK_APP_DIR%" if not exist "%KIOSK_APP_DIR%" mkdir "%KIOSK_APP_DIR%"
copy /Y "%ROOT_DIR%templates\startup.html" "%KIOSK_APP_DIR%\startup.html" >nul copy /Y "%ROOT_DIR%templates\startup.html" "%KIOSK_APP_DIR%\startup.html" >nul
icacls "%KIOSK_DATA_DIR%" /grant "%KIOSK_USER%:(OI)(CI)F" /T >nul icacls "%KIOSK_DATA_DIR%" /grant "%KIOSK_USER%:(OI)(CI)F" /T >nul
icacls "%KIOSK_APP_DIR%" /grant "Users:(OI)(CI)RX" /T >nul icacls "%KIOSK_APP_DIR%" /grant "Users:(OI)(CI)RX" /T >nul
:: Create WSL2 + Docker 24/7 Auto-Start Script and System Startup Task
> "%KIOSK_APP_DIR%\start_wsl_docker.bat" echo @echo off
>> "%KIOSK_APP_DIR%\start_wsl_docker.bat" echo wsl -d %WSL_DISTRO% -u root bash -c "systemctl is-active --quiet docker || service docker start; cd '%PROJECT_DIR%' && docker compose -p '%PROJECT_NAME%' up -d"
>> "%KIOSK_APP_DIR%\start_wsl_docker.bat" echo start "" /b wsl -d %WSL_DISTRO% -u root sleep infinity
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
"$u = \"$env:USERDOMAIN\$env:USERNAME\";" ^
"$act = New-ScheduledTaskAction -Execute '%KIOSK_APP_DIR%\start_wsl_docker.bat';" ^
"$trig = New-ScheduledTaskTrigger -AtStartup;" ^
"$prin = New-ScheduledTaskPrincipal -UserId $u -LogonType S4U -RunLevel Highest;" ^
"$set = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -StartWhenAvailable -ExecutionTimeLimit ([TimeSpan]::Zero) -RestartCount 5 -RestartInterval (New-TimeSpan -Minutes 1) -MultipleInstances IgnoreNew;" ^
"Register-ScheduledTask -TaskName 'WSL Docker Startup' -Action $act -Trigger $trig -Principal $prin -Settings $set -Force | Out-Null"
if %errorLevel% neq 0 (
echo [WARNING] Failed to create Task Scheduler entry DTS_WSL_Docker_AutoStart!
) else (
echo - Registered 24/7 startup task: WSL Docker Startup (User: %USERDOMAIN%\%USERNAME%)
)
set "WINLOGON_KEY=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" set "WINLOGON_KEY=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
reg add "%WINLOGON_KEY%" /v "AutoAdminLogon" /t REG_SZ /d "1" /f >nul reg add "%WINLOGON_KEY%" /v "AutoAdminLogon" /t REG_SZ /d "1" /f >nul
reg add "%WINLOGON_KEY%" /v "DefaultDomainName" /t REG_SZ /d "%COMPUTERNAME%" /f >nul reg add "%WINLOGON_KEY%" /v "DefaultDomainName" /t REG_SZ /d "%COMPUTERNAME%" /f >nul
@@ -385,7 +404,7 @@ reg add "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" /v "AUOption
echo. echo.
echo ============================================================================ echo ============================================================================
echo ALL-IN-ONE 24/7 KIOSK DEPLOYMENT COMPLETED! echo ALL-IN-ONE 24/7 KIOSK DEPLOYMENT COMPLETED!
echo - WSL2 + Docker : %DOCKER_VERSION% (Auto-Starting at Boot) echo - WSL2 + Docker : %DOCKER_VERSION% (Auto-Starting via DTS_WSL_Docker_AutoStart)
echo - Walmart Containers : Online and Verified on Port %HEALTH_PORT% in %PROJECT_DIR% echo - Walmart Containers : Online and Verified on Port %HEALTH_PORT% in %PROJECT_DIR%
echo - Kiosk User : %KIOSK_USER% (Auto-Logon + Persistent Data) echo - Kiosk User : %KIOSK_USER% (Auto-Logon + Persistent Data)
echo - Power and Updates : 24/7 Always-On (No Sleep / No Auto-Reboot) echo - Power and Updates : 24/7 Always-On (No Sleep / No Auto-Reboot)
+6 -42
View File
@@ -7,7 +7,7 @@ setlocal EnableDelayedExpansion
set "GITEA_URL=https://gitea.digitoolsolutions.synology.me" set "GITEA_URL=https://gitea.digitoolsolutions.synology.me"
set "REPO_OWNER=lamtruong28" set "REPO_OWNER=lamtruong28"
set "REPO_NAME=mini-pc-setup" 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 :: 0. AUTO-ELEVATE TO ADMINISTRATOR
@@ -23,16 +23,14 @@ echo ===========================================================================
echo DTS TORQUE VAULT - ONE-CLICK LATEST RELEASE BOOTSTRAPPER echo DTS TORQUE VAULT - ONE-CLICK LATEST RELEASE BOOTSTRAPPER
echo ============================================================================ echo ============================================================================
echo Repository : %GITEA_URL%/%REPO_OWNER%/%REPO_NAME% echo Repository : %GITEA_URL%/%REPO_OWNER%/%REPO_NAME%
echo Destination : %EXTRACT_DIR%
echo. echo.
:: ============================================================================ :: ============================================================================
:: 1. PRE-CHECK DNS & INTERNET CONNECTIVITY :: 1. PRE-CHECK DNS & INTERNET CONNECTIVITY
:: ============================================================================ :: ============================================================================
echo [1/3] Checking network and DNS resolution for %GITEA_URL%... echo [1/3] Checking network and DNS resolution for %GITEA_URL%...
powershell -NoProfile -ExecutionPolicy Bypass -Command ^ 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 }"
"$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 ( if %errorLevel% neq 0 (
pause pause
exit /b 1 exit /b 1
@@ -45,33 +43,7 @@ echo [2/3] Fetching latest release package...
set "ZIP_FILE=%TEMP%\%REPO_NAME%-latest.zip" set "ZIP_FILE=%TEMP%\%REPO_NAME%-latest.zip"
if exist "%ZIP_FILE%" del /f /q "%ZIP_FILE%" >nul 2>&1 if exist "%ZIP_FILE%" del /f /q "%ZIP_FILE%" >nul 2>&1
powershell -NoProfile -ExecutionPolicy Bypass -Command ^ 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"
"[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 ( if %errorLevel% neq 0 (
echo [ERROR] Bootstrap failed. 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 if exist "%EXTRACT_DIR%" rmdir /s /q "%EXTRACT_DIR%" >nul 2>&1
mkdir "%EXTRACT_DIR%" >nul 2>&1 mkdir "%EXTRACT_DIR%" >nul 2>&1
powershell -NoProfile -ExecutionPolicy Bypass -Command ^ 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"
"$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" ( 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 pause
exit /b 1 exit /b 1
) )