1 Commits
Author SHA1 Message Date
lamtruong28 4b9c8a87ec Update scripts 2026-11-18 14:52:16 +07:00
4 changed files with 144 additions and 138 deletions
+8
View File
@@ -0,0 +1,8 @@
# File batch Windows CRLF (\r\n)
*.bat text eol=crlf
*.ps1 text eol=crlf
# shell script Linux and compose always use LF (\n)
*.sh text eol=lf
*.yml text eol=lf
*.yaml text eol=lf
-79
View File
@@ -1,79 +0,0 @@
param(
[string]$GiteaUrl = "https://gitea.digitoolsolutions.synology.me",
[string]$Owner = "lamtruong28",
[string]$Repo = "mini-pc-setup",
[object]$ReleaseJson = $null,
[pscredential]$Credential = $null
)
$ErrorActionPreference = "Stop"
$GiteaUrl = $GiteaUrl.TrimEnd('/')
$TargetDir = "C:\Apps\mini-pc-setup"
$TempZip = "$env:TEMP\mini-pc-setup-release.zip"
$TempExtract = "$env:TEMP\mini-pc-release-extract"
Write-Host "========================================================" -ForegroundColor Cyan
Write-Host " DTS TORQUE VAULT - DOWNLOADING LATEST RELEASE" -ForegroundColor Cyan
Write-Host "========================================================" -ForegroundColor Cyan
if ($null -eq $ReleaseJson) {
$apiUrl = "$GiteaUrl/api/v1/repos/$Owner/$Repo/releases/latest"
try {
$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
}
}
$TagName = $ReleaseJson.tag_name
Write-Host "[INFO] Latest Release Tag: $TagName ($($ReleaseJson.name))" -ForegroundColor Green
$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
Write-Host "[1/3] Downloading release archive ($TagName)..."
}
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
} else {
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
$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
}
Remove-Item $TempZip -Force -ErrorAction SilentlyContinue
Remove-Item $TempExtract -Recurse -Force -ErrorAction SilentlyContinue
# Auto-create .env from .env.template if .env does not exist yet
if (-not (Test-Path "$TargetDir\.env") -and (Test-Path "$TargetDir\.env.template")) {
Copy-Item "$TargetDir\.env.template" "$TargetDir\.env"
Write-Host "[ACTION REQUIRED] Please configure '.env' in Notepad, save, and close it to continue..." -ForegroundColor Yellow
Start-Process notepad.exe "$TargetDir\.env" -Wait
}
Write-Host "[3/3] Launching scripts\install.bat..." -ForegroundColor Green
$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"
+114 -37
View File
@@ -22,10 +22,11 @@ set "HEALTH_PATH=/api/v1/system/health-check/"
set "HEALTH_INTERVAL=30"
set "HEALTH_MAX_RETRIES=10"
:: Windows Kiosk & Edge Settings
:: Windows Kiosk, Power & Edge Settings
set "DEFAULT_KIOSK_USER=Torque Vault"
set "KIOSK_APP_DIR=C:\KioskApp"
set "KIOSK_DATA_DIR=C:\KioskBrowserData"
set "DEFAULT_DISPLAY_OFF_MINUTES=15"
set "EDGE_EXE=C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
if not exist "%EDGE_EXE%" set "EDGE_EXE=C:\Program Files\Microsoft\Edge\Application\msedge.exe"
@@ -56,13 +57,26 @@ pause
exit /b 1
:EDGE_OK
if exist "%ROOT_DIR%.env" goto :ENV_OK
if exist "%ROOT_DIR%.env.template" (
copy /Y "%ROOT_DIR%.env.template" "%ROOT_DIR%.env" >nul
echo [ACTION REQUIRED] Created .env from .env.template. Configure it in Notepad, save, and close...
if exist "%ROOT_DIR%.env" goto :ENV_CLEANUP
set "ENV_SAMPLE="
if exist "%ROOT_DIR%.env.example" set "ENV_SAMPLE=%ROOT_DIR%.env.example"
if "%ENV_SAMPLE%"=="" if exist "%ROOT_DIR%.env.template" set "ENV_SAMPLE=%ROOT_DIR%.env.template"
if "%ENV_SAMPLE%"=="" goto :ENV_CLEANUP
copy /Y "%ENV_SAMPLE%" "%ROOT_DIR%.env" >nul
echo [ACTION REQUIRED] Created .env from sample. Configure it in Notepad, save, and close...
start /wait notepad.exe "%ROOT_DIR%.env"
:ENV_CLEANUP
if not exist "%ROOT_DIR%.env" (
echo [ERROR] Missing required file: "%ROOT_DIR%.env"
pause
exit /b 1
)
:ENV_OK
attrib +h "%ROOT_DIR%.env" >nul 2>&1
if exist "%ROOT_DIR%.env.example" del /f /q "%ROOT_DIR%.env.example" >nul 2>&1
if exist "%ROOT_DIR%.env.template" del /f /q "%ROOT_DIR%.env.template" >nul 2>&1
if not exist "%ROOT_DIR%templates\startup.html" (
echo [ERROR] Missing required file: "%ROOT_DIR%templates\startup.html"
@@ -74,11 +88,6 @@ if not exist "%ROOT_DIR%compose.yml" (
pause
exit /b 1
)
if not exist "%ROOT_DIR%.env" (
echo [ERROR] Missing required file: "%ROOT_DIR%.env"
pause
exit /b 1
)
:: Restrict setup directory permissions to Administrators and SYSTEM to protect .env
icacls "%CLEAN_ROOT%" /inheritance:r /grant:r "Administrators:(OI)(CI)F" "SYSTEM:(OI)(CI)F" >nul 2>&1
@@ -105,24 +114,37 @@ echo - Pre-flight checks passed!
echo.
:: ============================================================================
:: PHASE 1: CHECK & INSTALL WSL2 + UBUNTU-22.04 (ENFORCES REQUIRED REBOOT)
:: PHASE 1: CHECK & INSTALL WSL2 + UBUNTU-22.04 (ENFORCES SINGLE REBOOT)
:: ============================================================================
schtasks /delete /tn "DTS_Master_Setup_Resume" /f >nul 2>&1
wsl -d %WSL_DISTRO% -u root true >nul 2>&1
if %errorLevel% equ 0 goto :PHASE1_DONE
echo [PHASE 1] Checking WSL2 / %WSL_DISTRO% status...
powershell -NoProfile -Command "$d = wsl -l -q 2>$null; if ($d -match '%WSL_DISTRO%') { exit 0 } else { exit 1 }"
if %errorLevel% neq 0 (
wsl -l -q 2>nul | findstr /i "%WSL_DISTRO%" >nul
if !errorLevel! neq 0 (
echo [PHASE 1] WSL2 / %WSL_DISTRO% not found. Installing now...
echo - Installing %WSL_DISTRO%...
wsl --install -d %WSL_DISTRO% --no-launch
if !errorLevel! neq 0 (
echo [ERROR] WSL installation failed. Ensure Virtualization is enabled in BIOS.
pause
exit /b 1
)
) else (
echo [PHASE 1] %WSL_DISTRO% is staged, but Windows has NOT rebooted yet!
goto :PHASE1_NEED_REBOOT
)
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce" /v "DTS_Master_Setup" /t REG_SZ /d "\"%~f0\"" /f >nul
if exist "%TEMP%\dts_wsl_rebooted.flag" (
echo [ERROR] %WSL_DISTRO% is installed but failed to boot even after reboot.
echo Run "wsl -d %WSL_DISTRO%" manually to inspect the exact WSL error.
del /f /q "%TEMP%\dts_wsl_rebooted.flag" >nul 2>&1
pause
exit /b 1
)
:PHASE1_NEED_REBOOT
echo 1 > "%TEMP%\dts_wsl_rebooted.flag"
schtasks /create /tn "DTS_Master_Setup_Resume" /tr "cmd.exe /c \"\"%~f0\"\"" /sc ONLOGON /ru "%USERDOMAIN%\%USERNAME%" /rl HIGHEST /f >nul 2>&1
echo.
echo ============================================================================
@@ -133,7 +155,9 @@ if %errorLevel% neq 0 (
pause
shutdown /r /t 3
exit /b
)
:PHASE1_DONE
if exist "%TEMP%\dts_wsl_rebooted.flag" del /f /q "%TEMP%\dts_wsl_rebooted.flag" >nul 2>&1
:: ============================================================================
:: PHASE 2: INITIALIZE UBUNTU USER (WITH PASSWORD), SYSTEMD & VMIDLETIMEOUT
@@ -169,7 +193,8 @@ del /f /q "%STEP1_SH%" >nul 2>&1
if %STEP1_ERR% neq 0 goto :ERR_WSL_USER
wsl --terminate %WSL_DISTRO% >nul 2>&1
timeout /t 2 /nobreak >nul
timeout /t 3 /nobreak >nul
wsl -d %WSL_DISTRO% -u root bash -c "for i in 1 2 3 4 5 6 7 8 9 10; do systemctl is-system-running >/dev/null 2>&1 && break || sleep 1; done" >nul 2>&1
goto :PHASE2_DONE
:ERR_WSL_ROOT
@@ -193,7 +218,7 @@ set "STEP2_SH=%TEMP%\dts_step2.sh"
> "%STEP2_SH%" echo set -e
>> "%STEP2_SH%" echo DOCKER_VER="$1"
>> "%STEP2_SH%" echo WSL_USR="$2"
>> "%STEP2_SH%" echo if ! command -v docker ^>/dev/null 2^>^&1; then
>> "%STEP2_SH%" echo install_docker() {
>> "%STEP2_SH%" echo apt-get update
>> "%STEP2_SH%" echo apt-get install -y ca-certificates curl gnupg lsb-release
>> "%STEP2_SH%" echo install -m 0755 -d /etc/apt/keyrings /etc/apt/sources.list.d
@@ -202,9 +227,11 @@ set "STEP2_SH=%TEMP%\dts_step2.sh"
>> "%STEP2_SH%" echo apt-get update
>> "%STEP2_SH%" echo apt-get install -y docker-ce="$DOCKER_VER" docker-ce-cli="$DOCKER_VER" containerd.io docker-compose-plugin
>> "%STEP2_SH%" echo apt-mark hold docker-ce docker-ce-cli containerd.io
>> "%STEP2_SH%" echo fi
>> "%STEP2_SH%" echo systemctl enable docker
>> "%STEP2_SH%" echo systemctl start docker
>> "%STEP2_SH%" echo }
>> "%STEP2_SH%" echo command -v docker ^>/dev/null 2^>^&1 ^|^| install_docker
>> "%STEP2_SH%" echo systemctl daemon-reload ^>/dev/null 2^>^&1 ^|^| true
>> "%STEP2_SH%" echo systemctl enable docker ^>/dev/null 2^>^&1 ^|^| true
>> "%STEP2_SH%" echo systemctl start docker ^|^| service docker start
>> "%STEP2_SH%" echo usermod -aG docker "$WSL_USR"
for /f "delims=" %%i in ('wsl -d %WSL_DISTRO% -u root wslpath -a "%STEP2_SH%"') do set "WSL_STEP2_SH=%%i"
@@ -212,23 +239,42 @@ wsl -d %WSL_DISTRO% -u root bash -c "tr -d '\r' < '%WSL_STEP2_SH%' > /tmp/dts_st
set "STEP2_ERR=%errorLevel%"
del /f /q "%STEP2_SH%" >nul 2>&1
if %STEP2_ERR% neq 0 (
if %STEP2_ERR% neq 0 goto :ERR_DOCKER_STEP2
goto :PHASE3_DONE
:ERR_DOCKER_STEP2
echo [ERROR] Docker installation or startup failed inside WSL.
pause
exit /b 1
)
:PHASE3_DONE
:: ============================================================================
:: PHASE 4: DEPLOY CONTAINERS & VERIFY ONLINE (ONE CONTINUOUS WSL SESSION)
:: ============================================================================
echo [3/7] Deploying Walmart containers and waiting for Online status in %PROJECT_DIR%...
echo Please log in to Docker registry (%REGISTRY_URL%) if prompted:
set /a LOGIN_ATTEMPT=0
set /a LOGIN_MAX=5
:DOCKER_LOGIN_LOOP
set /a LOGIN_ATTEMPT+=1
echo Please log in to Docker registry (%REGISTRY_URL%) [Attempt %LOGIN_ATTEMPT%/%LOGIN_MAX%]:
wsl -d %WSL_DISTRO% -u root docker login %REGISTRY_URL%
if %errorLevel% neq 0 (
echo [ERROR] Docker registry login failed.
if %errorLevel% equ 0 goto :DOCKER_LOGIN_OK
if %LOGIN_ATTEMPT% geq %LOGIN_MAX% goto :DOCKER_LOGIN_FAIL
echo [WARNING] Docker registry login failed. Please check your username/password and try again...
echo.
goto :DOCKER_LOGIN_LOOP
:DOCKER_LOGIN_FAIL
echo [ERROR] Docker registry login failed after %LOGIN_MAX% attempts.
pause
exit /b 1
)
:DOCKER_LOGIN_OK
echo - Docker registry login succeeded!
for /f "delims=" %%i in ('wsl -d %WSL_DISTRO% -u root wslpath -a "%CLEAN_ROOT%"') do set "WSL_ROOT_DIR=%%i"
@@ -350,7 +396,6 @@ icacls "%KIOSK_APP_DIR%" /grant "Users:(OI)(CI)RX" /T >nul
>> "%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';" ^
@@ -359,7 +404,7 @@ powershell -NoProfile -ExecutionPolicy Bypass -Command ^
"$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!
echo [WARNING] Failed to create Task Scheduler entry WSL Docker Startup!
) else (
echo - Registered 24/7 startup task: WSL Docker Startup (User: %USERDOMAIN%\%USERNAME%)
)
@@ -414,12 +459,36 @@ schtasks /delete /tn "DTS_Torque_Vault_Kiosk" /f >nul 2>&1
:: ============================================================================
:: PHASE 6: CONFIGURE 24/7 ALWAYS-ON POWER PLAN & BLOCK AUTO-REBOOT UPDATES
:: ============================================================================
echo [7/7] Configuring 24/7 Always-On Power Plan and blocking Windows Update auto-reboots...
echo.
echo [7/7] Configuring 24/7 Power Plan and blocking Windows Update auto-reboots...
:ASK_DISPLAY_TIMEOUT
if "%DEFAULT_DISPLAY_OFF_MINUTES%"=="" set "DEFAULT_DISPLAY_OFF_MINUTES=15"
set "DISPLAY_OFF_MINUTES="
set /p DISPLAY_OFF_MINUTES="Enter display off timeout in minutes (0 = Always On) [Default: %DEFAULT_DISPLAY_OFF_MINUTES%]: "
if "%DISPLAY_OFF_MINUTES%"=="" set "DISPLAY_OFF_MINUTES=%DEFAULT_DISPLAY_OFF_MINUTES%"
powershell -NoProfile -Command "if ('%DISPLAY_OFF_MINUTES%' -match '^\d+$') { exit 0 } else { exit 1 }"
if %errorLevel% neq 0 goto :INVALID_DISPLAY_TIMEOUT
goto :VALID_DISPLAY_TIMEOUT
:INVALID_DISPLAY_TIMEOUT
echo [WARNING] Invalid number - enter 0 or a positive integer such as 15.
goto :ASK_DISPLAY_TIMEOUT
:VALID_DISPLAY_TIMEOUT
if "%DISPLAY_OFF_MINUTES%"=="0" set "DISPLAY_STATUS_MSG=Always On (0m)"
if not "%DISPLAY_OFF_MINUTES%"=="0" set "DISPLAY_STATUS_MSG=Display off %DISPLAY_OFF_MINUTES%m"
echo - Applying Power Plan (%DISPLAY_STATUS_MSG%, No Lock/Sleep)...
powercfg -setactive 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c >nul 2>&1
powercfg -h off >nul 2>&1
powercfg -change -monitor-timeout-ac 0 >nul
powercfg -change -monitor-timeout-dc 0 >nul
:: Allow display to turn off after DISPLAY_OFF_MINUTES (0 = Never) while CPU/WSL/Docker stay 100% awake
powercfg -change -monitor-timeout-ac %DISPLAY_OFF_MINUTES% >nul
powercfg -change -monitor-timeout-dc %DISPLAY_OFF_MINUTES% >nul
:: Keep system, hibernate, and disk strictly Always-On (0 = Never)
powercfg -change -standby-timeout-ac 0 >nul
powercfg -change -standby-timeout-dc 0 >nul
powercfg -change -hibernate-timeout-ac 0 >nul
@@ -427,8 +496,16 @@ powercfg -change -hibernate-timeout-dc 0 >nul
powercfg -change -disk-timeout-ac 0 >nul
powercfg -change -disk-timeout-dc 0 >nul
:: Disable USB Selective Suspend so touchscreen/peripherals wake display immediately
powercfg -setacvalueindex SCHEME_CURRENT 2a737441-1930-4402-8d77-b2bebba308a3 48e6b7a6-50f5-4782-a5d4-53bb8f07e226 0 >nul 2>&1
powercfg -setdcvalueindex SCHEME_CURRENT 2a737441-1930-4402-8d77-b2bebba308a3 48e6b7a6-50f5-4782-a5d4-53bb8f07e226 0 >nul 2>&1
:: Prevent Windows from locking Kiosk session when display turns off
reg add "HKLM\SYSTEM\CurrentControlSet\Control\Power\PowerSettings\7516b95f-f776-4464-8c53-06167f40cc99\8ec4b3a5-6868-48c2-be75-4f3044be88a7" /v "Attributes" /t REG_DWORD /d 2 /f >nul
powercfg -setacvalueindex SCHEME_CURRENT 7516b95f-f776-4464-8c53-06167f40cc99 8ec4b3a5-6868-48c2-be75-4f3044be88a7 0 >nul 2>&1
powercfg -setdcvalueindex SCHEME_CURRENT 7516b95f-f776-4464-8c53-06167f40cc99 8ec4b3a5-6868-48c2-be75-4f3044be88a7 0 >nul 2>&1
reg add "HKCU\Control Panel\Desktop" /v "ScreenSaveActive" /t REG_SZ /d "0" /f >nul
reg add "HKCU\Control Panel\Desktop" /v "ScreenSaverIsSecure" /t REG_SZ /d "0" /f >nul
powercfg -setactive SCHEME_CURRENT >nul 2>&1
reg add "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" /v "NoAutoRebootWithLoggedOnUsers" /t REG_DWORD /d 1 /f >nul
@@ -437,10 +514,10 @@ reg add "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" /v "AUOption
echo.
echo ============================================================================
echo ALL-IN-ONE 24/7 KIOSK DEPLOYMENT COMPLETED!
echo - WSL2 + Docker : %DOCKER_VERSION% (Auto-Starting via DTS_WSL_Docker_AutoStart)
echo - WSL2 + Docker : %DOCKER_VERSION% (User: %WSL_USER%, Task: WSL Docker Startup)
echo - Walmart Containers : Online and Verified on Port %HEALTH_PORT% in %PROJECT_DIR%
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 (%DISPLAY_STATUS_MSG%, No Lock/Sleep)
echo ============================================================================
echo.
set "REBOOT_FINAL="
+1 -1
View File
@@ -150,7 +150,7 @@ echo - No separate Kiosk user account needed removal.
:: 3. REMOVE SCHEDULED TASKS AND KIOSK LOCAL FILES
:: ============================================================================
echo [3/5] Removing scheduled tasks and local Kiosk app files...
schtasks /delete /tn "DTS_WSL_Docker_AutoStart" /f >nul 2>&1
schtasks /delete /tn "WSL Docker Startup" /f >nul 2>&1
schtasks /delete /tn "DTS_Torque_Vault_Kiosk" /f >nul 2>&1
reg delete "HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce" /v "DTS_Master_Setup" /f >nul 2>&1