2 Commits
Author SHA1 Message Date
lamtruong28 5bb53106da Fix some bugs runtime 2026-11-15 00:00:49 +07:00
lamtruong28 27680382fa Fix can't auto run install.bat when setup.bat done 2026-11-14 22:28:31 +07:00
4 changed files with 238 additions and 222 deletions
+5 -1
View File
@@ -72,4 +72,8 @@ if (-not (Test-Path "$TargetDir\.env") -and (Test-Path "$TargetDir\.env.template
} }
Write-Host "[3/3] Launching scripts\install.bat..." -ForegroundColor Green Write-Host "[3/3] Launching scripts\install.bat..." -ForegroundColor Green
Start-Process -FilePath "$TargetDir\scripts\install.bat" -WorkingDirectory "$TargetDir\scripts" $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"
+48 -103
View File
@@ -14,6 +14,7 @@ set "REGISTRY_URL=gitea.digitoolsolutions.synology.me"
set "DEFAULT_KIOSK_USER=Torque Vault" set "DEFAULT_KIOSK_USER=Torque Vault"
set "KIOSK_APP_DIR=C:\KioskApp" set "KIOSK_APP_DIR=C:\KioskApp"
set "KIOSK_DATA_DIR=C:\KioskBrowserData" set "KIOSK_DATA_DIR=C:\KioskBrowserData"
set "EDGE_EXE=C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" 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" if not exist "%EDGE_EXE%" set "EDGE_EXE=C:\Program Files\Microsoft\Edge\Application\msedge.exe"
@@ -37,27 +38,34 @@ echo.
:: ============================================================================ :: ============================================================================
echo [PRE-CHECK] Verifying required files, Edge, Internet and CPU Virtualization... echo [PRE-CHECK] Verifying required files, Edge, Internet and CPU Virtualization...
if not exist "%EDGE_EXE%" ( if exist "%EDGE_EXE%" goto :EDGE_OK
echo [ERROR] Microsoft Edge not found at "%EDGE_EXE%". echo [ERROR] Microsoft Edge not found at "%EDGE_EXE%".
pause pause
exit /b 1 exit /b 1
) :EDGE_OK
:: Auto-generate .env from .env.template if missing if exist "%ROOT_DIR%.env" goto :ENV_OK
if not exist "%ROOT_DIR%.env" ( if exist "%ROOT_DIR%.env.template" (
if exist "%ROOT_DIR%.env.template" (
copy /Y "%ROOT_DIR%.env.template" "%ROOT_DIR%.env" >nul 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... echo [ACTION REQUIRED] Created .env from .env.template. Configure it in Notepad, save, and close...
start /wait notepad.exe "%ROOT_DIR%.env" start /wait notepad.exe "%ROOT_DIR%.env"
)
) )
:ENV_OK
for %%F in ("templates\startup.html" "compose.yml" ".env") do ( if not exist "%ROOT_DIR%templates\startup.html" (
if not exist "%ROOT_DIR%%%~F" ( echo [ERROR] Missing required file: "%ROOT_DIR%templates\startup.html"
echo [ERROR] Missing required file: "%ROOT_DIR%%%~F" pause
exit /b 1
)
if not exist "%ROOT_DIR%compose.yml" (
echo [ERROR] Missing required file: "%ROOT_DIR%compose.yml"
pause
exit /b 1
)
if not exist "%ROOT_DIR%.env" (
echo [ERROR] Missing required file: "%ROOT_DIR%.env"
pause pause
exit /b 1 exit /b 1
)
) )
ping -n 1 8.8.8.8 >nul 2>&1 ping -n 1 8.8.8.8 >nul 2>&1
@@ -67,9 +75,9 @@ if %errorLevel% neq 0 (
exit /b 1 exit /b 1
) )
powershell -NoProfile -Command "if ((Get-CimInstance Win32_Processor).VirtualizationFirmwareEnabled -eq $false) { exit 1 }" powershell -NoProfile -Command "$cs = Get-CimInstance Win32_ComputerSystem; $cpu = Get-CimInstance Win32_Processor | Select-Object -First 1; if ($cs.HypervisorPresent -or $cpu.VirtualizationFirmwareEnabled) { exit 0 } else { exit 1 }"
if %errorLevel% neq 0 ( if %errorLevel% neq 0 (
echo [ERROR] Hardware Virtualization (VT-x / AMD-V) is DISABLED in BIOS! echo [ERROR] Hardware Virtualization is DISABLED in BIOS!
echo Please reboot into BIOS, enable Virtualization, and run again. echo Please reboot into BIOS, enable Virtualization, and run again.
pause pause
exit /b 1 exit /b 1
@@ -96,7 +104,6 @@ if %errorLevel% neq 0 (
echo [PHASE 1] %WSL_DISTRO% is staged, but Windows has NOT rebooted yet! echo [PHASE 1] %WSL_DISTRO% is staged, but Windows has NOT rebooted yet!
) )
:: Register RunOnce so this exact script resumes automatically after reboot
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce" /v "DTS_Master_Setup" /t REG_SZ /d "\"%~f0\"" /f >nul reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce" /v "DTS_Master_Setup" /t REG_SZ /d "\"%~f0\"" /f >nul
echo. echo.
@@ -114,8 +121,8 @@ if %errorLevel% neq 0 (
:: PHASE 2: INITIALIZE UBUNTU USER & ENABLE SYSTEMD IN WSL2 :: PHASE 2: INITIALIZE UBUNTU USER & ENABLE SYSTEMD IN WSL2
:: ============================================================================ :: ============================================================================
echo [1/7] Initializing Ubuntu-22.04 and enabling systemd... echo [1/7] Initializing Ubuntu-22.04 and enabling systemd...
wsl -d %WSL_DISTRO% -u root bash -c "if ! id -u dtsadmin >/dev/null 2>&1; then useradd -m -s /bin/bash -G sudo dtsadmin && echo 'dtsadmin ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/dtsadmin; fi" wsl -d %WSL_DISTRO% -u root bash -c "id -u dtsadmin >/dev/null 2>&1 || (useradd -m -s /bin/bash -G sudo dtsadmin && echo 'dtsadmin ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/dtsadmin)"
wsl -d %WSL_DISTRO% -u root bash -c "printf '[user]\ndefault=dtsadmin\n[boot]\nsystemd=true\n' > /etc/wsl.conf" wsl -d %WSL_DISTRO% -u root bash -c "echo [user] > /etc/wsl.conf && echo default=dtsadmin >> /etc/wsl.conf && echo [boot] >> /etc/wsl.conf && echo systemd=true >> /etc/wsl.conf"
wsl --terminate %WSL_DISTRO% >nul 2>&1 wsl --terminate %WSL_DISTRO% >nul 2>&1
timeout /t 2 /nobreak >nul timeout /t 2 /nobreak >nul
@@ -124,38 +131,30 @@ timeout /t 2 /nobreak >nul
:: PHASE 3: INSTALL & PIN DOCKER ENGINE 28.3.2 + COMPOSE V2 (IDEMPOTENT) :: PHASE 3: INSTALL & PIN DOCKER ENGINE 28.3.2 + COMPOSE V2 (IDEMPOTENT)
:: ============================================================================ :: ============================================================================
echo [2/7] Installing Docker Engine 28.3.2 + Compose V2 (if not installed)... echo [2/7] Installing Docker Engine 28.3.2 + Compose V2 (if not installed)...
wsl -d %WSL_DISTRO% -u root bash -c "if ! command -v docker >/dev/null 2>&1; then \ wsl -d %WSL_DISTRO% -u root bash -c "echo c2V0IC1lCmlmICEgY29tbWFuZCAtdiBkb2NrZXIgPi9kZXYvbnVsbCAyPiYxOyB0aGVuCiAgYXB0LWdldCB1cGRhdGUKICBhcHQtZ2V0IGluc3RhbGwgLXkgY2EtY2VydGlmaWNhdGVzIGN1cmwgZ251cGcgbHNiLXJlbGVhc2UKICBpbnN0YWxsIC1tIDA3NTUgLWQgL2V0Yy9hcHQva2V5cmluZ3MKICBjdXJsIC1mc1NMIGh0dHBzOi8vZG93bmxvYWQuZG9ja2VyLmNvbS9saW51eC91YnVudHUvZ3BnIHwgZ3BnIC0tZGVhcm1vciAtLXllcyAtbyAvZXRjL2FwdC9rZXlyaW5ncy9kb2NrZXIuZ3BnCiAgZWNobyAiZGViIFthcmNoPSQoZHBrZyAtLXByaW50LWFyY2hpdGVjdHVyZSkgc2lnbmVkLWJ5PS9ldGMvYXB0L2tleXJpbmdzL2RvY2tlci5ncGddIGh0dHBzOi8vZG93bmxvYWQuZG9ja2VyLmNvbS9saW51eC91YnVudHUgJChsc2JfcmVsZWFzZSAtY3MpIHN0YWJsZSIgPiAvZXRjL2FwdC9zb3VyY2VzLmxpc3QuZC9kb2NrZXIubGlzdAogIGFwdC1nZXQgdXBkYXRlCiAgYXB0LWdldCBpbnN0YWxsIC15IGRvY2tlci1jZT01OjI4LjMuMi0xfnVidW50dS4yMi4wNH5qYW1teSBkb2NrZXItY2UtY2xpPTU6MjguMy4yLTF+dWJ1bnR1LjIyLjA0fmphbW15IGNvbnRhaW5lcmQuaW8gZG9ja2VyLWNvbXBvc2UtcGx1Z2luCiAgYXB0LW1hcmsgaG9sZCBkb2NrZXItY2UgZG9ja2VyLWNlLWNsaSBjb250YWluZXJkLmlvCmZpCnN5c3RlbWN0bCBlbmFibGUgZG9ja2VyCnN5c3RlbWN0bCBzdGFydCBkb2NrZXIKdXNlcm1vZCAtYUcgZG9ja2VyIGR0c2FkbWluCg== | base64 -d | bash"
apt-get update && apt-get install -y ca-certificates curl gnupg lsb-release && \
install -m 0755 -d /etc/apt/keyrings && \
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor --yes -o /etc/apt/keyrings/docker.gpg && \
echo \"deb [arch=\$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \$(lsb_release -cs) stable\" > /etc/apt/sources.list.d/docker.list && \
apt-get update && \
apt-get install -y docker-ce=5:28.3.2-1~ubuntu.22.04~jammy docker-ce-cli=5:28.3.2-1~ubuntu.22.04~jammy containerd.io docker-compose-plugin && \
apt-mark hold docker-ce docker-ce-cli containerd.io; \
fi && systemctl enable docker && systemctl start docker"
if %errorLevel% neq 0 ( if %errorLevel% neq 0 (
echo [ERROR] Docker installation or startup failed inside WSL. echo [ERROR] Docker installation or startup failed inside WSL.
pause pause
exit /b 1 exit /b 1
) )
wsl -d %WSL_DISTRO% -u root bash -c "usermod -aG docker dtsadmin"
:: ============================================================================ :: ============================================================================
:: PHASE 4: DEPLOY DOCKER CONTAINERS & REGISTER WSL BOOT TASK :: PHASE 4: DEPLOY DOCKER CONTAINERS & REGISTER WSL BOOT TASK
:: ============================================================================ :: ============================================================================
echo [3/7] Deploying Walmart containers to %PROJECT_DIR%... echo [3/7] Deploying Walmart containers to %PROJECT_DIR%...
echo Please log in to Docker registry (%REGISTRY_URL%) if prompted: echo Please log in to Docker registry (%REGISTRY_URL%) if prompted:
wsl -d %WSL_DISTRO% -u root bash -c "docker login %REGISTRY_URL%" wsl -d %WSL_DISTRO% -u root docker login %REGISTRY_URL%
if %errorLevel% neq 0 ( if %errorLevel% neq 0 (
echo [ERROR] Docker registry login failed. echo [ERROR] Docker registry login failed.
pause pause
exit /b 1 exit /b 1
) )
for /f "delims=" %%i in ('wsl -d %WSL_DISTRO% -u root wslpath -a "%ROOT_DIR%"') do set "WSL_ROOT_DIR=%%i" set "CLEAN_ROOT=%ROOT_DIR:~0,-1%"
for /f "delims=" %%i in ('wsl -d %WSL_DISTRO% -u root wslpath -a "%CLEAN_ROOT%"') do set "WSL_ROOT_DIR=%%i"
wsl -d %WSL_DISTRO% -u root bash -c "mkdir -p %PROJECT_DIR% && cp '%WSL_ROOT_DIR%/compose.yml' %PROJECT_DIR%/ && cp '%WSL_ROOT_DIR%/.env' %PROJECT_DIR%/ && cd %PROJECT_DIR% && docker compose pull && docker compose up -d" wsl -d %WSL_DISTRO% -u root bash -c "mkdir -p %PROJECT_DIR% && cp '%WSL_ROOT_DIR%/compose.yml' %PROJECT_DIR%/ && cp '%WSL_ROOT_DIR%/.env' %PROJECT_DIR%/ && sed -i 's/\r$//' %PROJECT_DIR%/.env && cd %PROJECT_DIR% && docker compose pull && docker compose up -d"
if %errorLevel% neq 0 ( if %errorLevel% neq 0 (
echo [ERROR] Failed to start Docker containers. echo [ERROR] Failed to start Docker containers.
pause pause
@@ -163,12 +162,7 @@ if %errorLevel% neq 0 (
) )
echo [4/7] Configuring WSL + Docker to auto-start on Windows Boot... echo [4/7] Configuring WSL + Docker to auto-start on Windows Boot...
powershell -NoProfile -ExecutionPolicy Bypass -Command ^ powershell -NoProfile -ExecutionPolicy Bypass -Command "$action = New-ScheduledTaskAction -Execute 'wsl.exe' -Argument '-d %WSL_DISTRO% -u root -- service docker start'; $trigger = New-ScheduledTaskTrigger -AtStartup; $principal = New-ScheduledTaskPrincipal -UserId 'SYSTEM' -LogonType ServiceAccount -RunLevel Highest; $settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit 0; Register-ScheduledTask -TaskName 'DTS_WSL_Docker_AutoStart' -Action $action -Trigger $trigger -Principal $principal -Settings $settings -Force | Out-Null"
"$action = New-ScheduledTaskAction -Execute 'wsl.exe' -Argument '-d %WSL_DISTRO% -u root -- service docker start';" ^
"$trigger = New-ScheduledTaskTrigger -AtStartup;" ^
"$principal = New-ScheduledTaskPrincipal -UserId 'SYSTEM' -LogonType ServiceAccount -RunLevel Highest;" ^
"$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit 0;" ^
"Register-ScheduledTask -TaskName 'DTS_WSL_Docker_AutoStart' -Action $action -Trigger $trigger -Principal $principal -Settings $settings -Force | Out-Null"
:: ============================================================================ :: ============================================================================
:: PHASE 5: INTERACTIVE KIOSK USER CREATION & AUTO-LOGON SETUP :: PHASE 5: INTERACTIVE KIOSK USER CREATION & AUTO-LOGON SETUP
@@ -195,52 +189,28 @@ if /i "%KIOSK_USER%"=="%USERNAME%" (
set "KIOSK_PASS=" set "KIOSK_PASS="
set /p KIOSK_PASS="Enter password for '%KIOSK_USER%' (leave blank for no password): " set /p KIOSK_PASS="Enter password for '%KIOSK_USER%' (leave blank for no password): "
if not "%PREV_KIOSK_USER%"=="" ( if "%PREV_KIOSK_USER%"=="" goto :SKIP_REMOVE_OLD
if /i not "%PREV_KIOSK_USER%"=="%KIOSK_USER%" ( if /i "%PREV_KIOSK_USER%"=="%KIOSK_USER%" goto :SKIP_REMOVE_OLD
if /i not "%PREV_KIOSK_USER%"=="%USERNAME%" ( if /i "%PREV_KIOSK_USER%"=="%USERNAME%" goto :SKIP_REMOVE_OLD
echo - Restoring normal Desktop shell for previous Kiosk user "%PREV_KIOSK_USER%"... if /i "%PREV_KIOSK_USER%"=="Administrator" goto :SKIP_REMOVE_OLD
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
"$oldUser = '%PREV_KIOSK_USER%';" ^ echo - Removing previous Kiosk user "%PREV_KIOSK_USER%" and its profile...
"$acc = Get-LocalUser -Name $oldUser -ErrorAction SilentlyContinue;" ^ for /f "tokens=3" %%S in ('query user "%PREV_KIOSK_USER%" 2^>nul ^| findstr /i "%PREV_KIOSK_USER%"') do logoff %%S >nul 2>&1
"if ($acc) {" ^ timeout /t 2 /nobreak >nul
" $sid = $acc.SID.Value;" ^ powershell -NoProfile -ExecutionPolicy Bypass -Command "$u='%PREV_KIOSK_USER%'; $acc=Get-LocalUser -Name $u -ErrorAction SilentlyContinue; if ($acc) { $sid=$acc.SID.Value; Get-CimInstance Win32_UserProfile -Filter \"SID='$sid'\" -ErrorAction SilentlyContinue | Remove-CimInstance -ErrorAction SilentlyContinue; Remove-LocalUser -Name $u -ErrorAction SilentlyContinue }"
" $profReg = \"HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\$sid\";" ^ :SKIP_REMOVE_OLD
" $profilePath = (Get-ItemProperty $profReg -ErrorAction SilentlyContinue).ProfileImagePath;" ^
" if ($profilePath -and (Test-Path (Join-Path $profilePath 'NTUSER.DAT'))) {" ^
" $hivePath = Join-Path $profilePath 'NTUSER.DAT';" ^
" $loaded = $false;" ^
" if (-not (Test-Path \"Registry::HKEY_USERS\$sid\")) { reg load \"HKU\$sid\" \"$hivePath\" >$null 2>&1; if ($LASTEXITCODE -eq 0) { $loaded = $true; } }" ^
" if (Test-Path \"Registry::HKEY_USERS\$sid\") {" ^
" Remove-ItemProperty -Path \"Registry::HKEY_USERS\$sid\Software\Microsoft\Windows\CurrentVersion\Policies\System\" -Name 'Shell' -ErrorAction SilentlyContinue;" ^
" }" ^
" if ($loaded) { [gc]::Collect(); Start-Sleep -Milliseconds 300; reg unload \"HKU\$sid\" >$null 2>&1; }" ^
" }" ^
"}"
)
)
)
net accounts /minpwlen:0 >nul 2>&1 net accounts /minpwlen:0 >nul 2>&1
powershell -NoProfile -ExecutionPolicy Bypass -Command ^ powershell -NoProfile -ExecutionPolicy Bypass -Command "$u = '%KIOSK_USER%'; $p = '%KIOSK_PASS%'; $existing = Get-LocalUser -Name $u -ErrorAction SilentlyContinue; if (-not $existing) { if ([string]::IsNullOrEmpty($p)) { New-LocalUser -Name $u -NoPassword | Out-Null } else { New-LocalUser -Name $u -Password (ConvertTo-SecureString $p -AsPlainText -Force) -PasswordNeverExpires | Out-Null } Add-LocalGroupMember -Group 'Users' -Member $u -ErrorAction SilentlyContinue } else { Enable-LocalUser -Name $u | Out-Null; if ([string]::IsNullOrEmpty($p)) { Set-LocalUser -Name $u -Password ([securestring]::new()) } else { Set-LocalUser -Name $u -Password (ConvertTo-SecureString $p -AsPlainText -Force) -PasswordNeverExpires $true } }"
"$u = '%KIOSK_USER%'; $p = '%KIOSK_PASS%';" ^ wmic useraccount where name="%KIOSK_USER%" set PasswordExpires=False >nul 2>&1
"$existing = Get-LocalUser -Name $u -ErrorAction SilentlyContinue;" ^ net user "%KIOSK_USER%" /logonpasswordchg:no >nul 2>&1
"if (-not $existing) {" ^
" if ([string]::IsNullOrEmpty($p)) { New-LocalUser -Name $u -NoPassword -PasswordNeverExpires | Out-Null }" ^
" else { New-LocalUser -Name $u -Password (ConvertTo-SecureString $p -AsPlainText -Force) -PasswordNeverExpires | Out-Null }" ^
" Add-LocalGroupMember -Group 'Users' -Member $u -ErrorAction SilentlyContinue;" ^
"} else {" ^
" Enable-LocalUser -Name $u | Out-Null;" ^
" if ([string]::IsNullOrEmpty($p)) { Set-LocalUser -Name $u -Password ([securestring]::new()) -PasswordNeverExpires $true }" ^
" else { Set-LocalUser -Name $u -Password (ConvertTo-SecureString $p -AsPlainText -Force) -PasswordNeverExpires $true }" ^
"}"
if %errorLevel% neq 0 ( if %errorLevel% neq 0 (
echo [ERROR] Failed to create or update user "%KIOSK_USER%". echo [ERROR] Failed to create or update user "%KIOSK_USER%".
pause pause
exit /b 1 exit /b 1
) )
echo [6/7] Applying Kiosk Shell, Auto-Logon & Persistent Browser Profile... echo [6/7] Applying Kiosk Shell, Auto-Logon and Persistent 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
@@ -261,32 +231,7 @@ reg add "%EDGE_POL%" /v "InPrivateModeAvailability" /t REG_DWORD /d 1 /f >nul
reg add "%EDGE_POL%" /v "ClearBrowsingDataOnExit" /t REG_DWORD /d 0 /f >nul reg add "%EDGE_POL%" /v "ClearBrowsingDataOnExit" /t REG_DWORD /d 0 /f >nul
reg add "%EDGE_POL%" /v "RestoreOnStartup" /t REG_DWORD /d 4 /f >nul reg add "%EDGE_POL%" /v "RestoreOnStartup" /t REG_DWORD /d 4 /f >nul
powershell -NoProfile -ExecutionPolicy Bypass -Command ^ powershell -NoProfile -ExecutionPolicy Bypass -Command "$user = '%KIOSK_USER%'; $edge = '%EDGE_EXE%'; $sid = (New-Object System.Security.Principal.NTAccount($user)).Translate([System.Security.Principal.SecurityIdentifier]).Value; $profReg = \"HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\$sid\"; if (-not (Test-Path $profReg)) { Add-Type -TypeDefinition 'using System; using System.Runtime.InteropServices; using System.Text; public class Prof { [DllImport(\"userenv.dll\", CharSet=CharSet.Unicode, SetLastError=true)] public static extern bool CreateProfile(string pszUserSid, string pszUserName, StringBuilder pszProfilePath, uint cchProfilePath); }'; $sb = New-Object System.Text.StringBuilder 260; [Prof]::CreateProfile($sid, $user, $sb, $sb.Capacity) | Out-Null } $profilePath = (Get-ItemProperty $profReg -ErrorAction SilentlyContinue).ProfileImagePath; if ($profilePath) { $hivePath = Join-Path $profilePath 'NTUSER.DAT'; $edgeCmd = '\"' + $edge + '\" --kiosk \"file:///C:/KioskApp/startup.html\" --edge-kiosk-type=fullscreen --user-data-dir=\"C:\KioskBrowserData\" --no-first-run --disable-features=TranslateUI --allow-file-access-from-files'; $loaded = $false; if (-not (Test-Path \"Registry::HKEY_USERS\$sid\")) { reg load \"HKU\$sid\" \"$hivePath\" >$null 2>&1; if ($LASTEXITCODE -eq 0) { $loaded = $true } } if (Test-Path \"Registry::HKEY_USERS\$sid\") { [Microsoft.Win32.Registry]::SetValue(\"HKEY_USERS\$sid\Software\Microsoft\Windows\CurrentVersion\Policies\System\", 'Shell', $edgeCmd, [Microsoft.Win32.RegistryValueKind]::String); $stuckPath = \"Registry::HKEY_USERS\$sid\Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects3\"; if (Test-Path $stuckPath) { $v = (Get-ItemProperty -Path $stuckPath -Name Settings).Settings; $v[8] = 3; Set-ItemProperty -Path $stuckPath -Name Settings -Value $v } } if ($loaded) { [gc]::Collect(); Start-Sleep -Milliseconds 300; reg unload \"HKU\$sid\" >$null 2>&1 } }"
"$user = '%KIOSK_USER%';$edge = '%EDGE_EXE%';" ^
"$sid = (New-Object System.Security.Principal.NTAccount($user)).Translate([System.Security.Principal.SecurityIdentifier]).Value;" ^
"$profReg = \"HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\$sid\";" ^
"if (-not (Test-Path $profReg)) {" ^
" Add-Type -TypeDefinition 'using System; using System.Runtime.InteropServices; using System.Text; public class Prof { [DllImport(\"userenv.dll\", CharSet=CharSet.Unicode, SetLastError=true)] public static extern bool CreateProfile(string pszUserSid, string pszUserName, StringBuilder pszProfilePath, uint cchProfilePath); }';" ^
" $sb = New-Object System.Text.StringBuilder 260;" ^
" [Prof]::CreateProfile($sid,$user, $sb,$sb.Capacity) | Out-Null;" ^
"}" ^
"$profilePath = (Get-ItemProperty$profReg -ErrorAction SilentlyContinue).ProfileImagePath;" ^
"if ($profilePath) {" ^
" $hivePath = Join-Path$profilePath 'NTUSER.DAT';" ^
" $edgeCmd = '\"' + $edge + '\" --kiosk \"file:///C:/KioskApp/startup.html\" --edge-kiosk-type=fullscreen --user-data-dir=\"C:\KioskBrowserData\" --no-first-run --disable-features=TranslateUI --allow-file-access-from-files';" ^
" $loaded =$false;" ^
" if (-not (Test-Path \"Registry::HKEY_USERS\$sid\")) { reg load \"HKU\$sid\" \"$hivePath\" >$null 2>&1; if ($LASTEXITCODE -eq 0) { $loaded =$true; } }" ^
" if (Test-Path \"Registry::HKEY_USERS\$sid\") {" ^
" [Microsoft.Win32.Registry]::SetValue(\"HKEY_USERS\$sid\Software\Microsoft\Windows\CurrentVersion\Policies\System\", 'Shell', $edgeCmd, [Microsoft.Win32.RegistryValueKind]::String);" ^
" $stuckPath = \"Registry::HKEY_USERS\$sid\Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects3\";" ^
" if (Test-Path $stuckPath) {" ^
" $v = (Get-ItemProperty -Path$stuckPath -Name Settings).Settings;" ^
" $v[8] = 3;" ^
" Set-ItemProperty -Path $stuckPath -Name Settings -Value$v;" ^
" }" ^
" }" ^
" if ($loaded) { [gc]::Collect(); Start-Sleep -Milliseconds 300; reg unload \"HKU\$sid\" >$null 2>&1; }" ^
"}"
schtasks /delete /tn "DTS_Torque_Vault_Kiosk" /f >nul 2>&1 schtasks /delete /tn "DTS_Torque_Vault_Kiosk" /f >nul 2>&1
@@ -316,10 +261,10 @@ 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 28.3.2 : Installed & Auto-Starting at Boot echo - WSL2 + Docker 28.3.2 : Installed and Auto-Starting at Boot
echo - Walmart Containers : Running in %PROJECT_DIR% echo - Walmart Containers : Running in %PROJECT_DIR%
echo - Kiosk User : %KIOSK_USER% (Auto-Logon + Persistent Data) echo - Kiosk User : %KIOSK_USER% (Auto-Logon + Persistent Data)
echo - Power & Updates : 24/7 Always-On (No Sleep / No Auto-Reboot) echo - Power and Updates : 24/7 Always-On (No Sleep / No Auto-Reboot)
echo ============================================================================ echo ============================================================================
echo. echo.
set /p REBOOT_FINAL="Reboot now to enter full Kiosk Production mode? (Y/N): " set /p REBOOT_FINAL="Reboot now to enter full Kiosk Production mode? (Y/N): "
+96 -77
View File
@@ -1,6 +1,14 @@
@echo off @echo off
setlocal EnableDelayedExpansion setlocal EnableDelayedExpansion
:: ============================================================================
:: CONFIGURATION
:: ============================================================================
set "WSL_DISTRO=Ubuntu-22.04"
set "PROJECT_DIR=/opt/walmart"
set "KIOSK_APP_DIR=C:\KioskApp"
set "KIOSK_DATA_DIR=C:\KioskBrowserData"
:: ============================================================================ :: ============================================================================
:: 0. AUTO-ELEVATE TO ADMINISTRATOR :: 0. AUTO-ELEVATE TO ADMINISTRATOR
:: ============================================================================ :: ============================================================================
@@ -12,116 +20,127 @@ if %errorLevel% neq 0 (
) )
echo ============================================================================ echo ============================================================================
echo DTS TORQUE VAULT - UNINSTALL KIOSK & RESTORE WINDOWS NORMAL MODE echo DTS TORQUE VAULT - KIOSK MODE UNINSTALLER AND SYSTEM RESTORE
echo ============================================================================ echo ============================================================================
echo. echo.
echo This tool will:
:: Detect current Auto-Logon user automatically echo 1. Disable Windows Auto-Logon and Kiosk Shell restrictions
set "DETECTED_USER=" echo 2. Remove or restore the dedicated Kiosk user account
for /f "tokens=2*" %%A in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v "DefaultUserName" 2^>nul') do set "DETECTED_USER=%%B" echo 3. Remove startup tasks and restore default Power / Update policies
echo 4. Optionally stop and remove Walmart Docker containers
if not "%DETECTED_USER%"=="" ( echo.
echo Detected configured Kiosk user: "%DETECTED_USER%" set /p CONFIRM="Are you sure you want to uninstall Kiosk Mode? (Y/N): "
set /p KIOSK_USER="Enter Kiosk username to restore/remove [Default: %DETECTED_USER%]: " if /i not "%CONFIRM%"=="Y" (
if "!KIOSK_USER!"=="" set "KIOSK_USER=%DETECTED_USER%" echo Uninstall cancelled.
) else ( pause
set /p KIOSK_USER="Enter Kiosk username to restore/remove (leave blank to skip user restore): " exit /b 0
) )
:: ============================================================================
:: 1. DETECT CURRENT KIOSK ACCOUNT & DISABLE AUTO-LOGON
:: ============================================================================
echo. echo.
set /p DEL_USER="Do you want to DELETE the local user account '%KIOSK_USER%' completely? (Y/N) [N = Keep user & restore normal Desktop]: " echo [1/5] Disabling Windows Auto-Logon and Edge Kiosk policies...
set /p DEL_DATA="Do you want to DELETE Kiosk app & browser data (C:\KioskApp, C:\KioskBrowserData)? (Y/N): "
set /p DEL_WSL="Do you want to REMOVE Docker containers and Ubuntu-22.04 WSL distro? (Y/N): " set "KIOSK_USER="
echo. for /f "tokens=2*" %%A in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v "DefaultUserName" 2^>nul') do set "KIOSK_USER=%%B"
:: ============================================================================
:: 1. DISABLE WINDOWS AUTO-LOGON & CLEAN RUNONCE
:: ============================================================================
echo [1/5] Disabling Windows Auto-Logon...
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 "0" /f >nul reg add "%WINLOGON_KEY%" /v "AutoAdminLogon" /t REG_SZ /d "0" /f >nul 2>&1
reg delete "%WINLOGON_KEY%" /v "DefaultUserName" /f >nul 2>&1
reg delete "%WINLOGON_KEY%" /v "DefaultPassword" /f >nul 2>&1 reg delete "%WINLOGON_KEY%" /v "DefaultPassword" /f >nul 2>&1
reg delete "%WINLOGON_KEY%" /v "DefaultDomainName" /f >nul 2>&1
reg delete "%WINLOGON_KEY%" /v "AutoLogonCount" /f >nul 2>&1 reg delete "%WINLOGON_KEY%" /v "AutoLogonCount" /f >nul 2>&1
reg delete "HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce" /v "DTS_Master_Setup" /f >nul 2>&1 reg add "%WINLOGON_KEY%" /v "Shell" /t REG_SZ /d "explorer.exe" /f >nul 2>&1
reg delete "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v "Shell" /f >nul 2>&1
reg delete "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System" /v "Shell" /f >nul 2>&1
:: ============================================================================
:: 2. REMOVE EDGE KIOSK POLICIES
:: ============================================================================
echo [2/5] Removing Microsoft Edge Kiosk policies...
set "EDGE_POL=HKLM\SOFTWARE\Policies\Microsoft\Edge" set "EDGE_POL=HKLM\SOFTWARE\Policies\Microsoft\Edge"
reg delete "%EDGE_POL%" /v "InPrivateModeAvailability" /f >nul 2>&1 reg delete "%EDGE_POL%" /v "InPrivateModeAvailability" /f >nul 2>&1
reg delete "%EDGE_POL%" /v "ClearBrowsingDataOnExit" /f >nul 2>&1 reg delete "%EDGE_POL%" /v "ClearBrowsingDataOnExit" /f >nul 2>&1
reg delete "%EDGE_POL%" /v "RestoreOnStartup" /f >nul 2>&1 reg delete "%EDGE_POL%" /v "RestoreOnStartup" /f >nul 2>&1
:: ============================================================================ :: ============================================================================
:: 3. REMOVE SCHEDULED TASKS :: 2. REMOVE OR RESTORE DEDICATED KIOSK USER ACCOUNT
:: ============================================================================ :: ============================================================================
echo [3/5] Removing Kiosk and WSL Auto-Start Scheduled Tasks... echo [2/5] Handling dedicated Kiosk user account...
schtasks /delete /tn "DTS_WSL_Docker_AutoStart" /f >nul 2>&1
schtasks /delete /tn "DTS_Torque_Vault_Kiosk" /f >nul 2>&1 if "%KIOSK_USER%"=="" goto :NO_KIOSK_USER
if /i "%KIOSK_USER%"=="%USERNAME%" goto :NO_KIOSK_USER
if /i "%KIOSK_USER%"=="Administrator" goto :NO_KIOSK_USER
echo Detected Kiosk account: "%KIOSK_USER%"
for /f "tokens=3" %%S in ('query user "%KIOSK_USER%" 2^>nul ^| findstr /i "%KIOSK_USER%"') do logoff %%S >nul 2>&1
timeout /t 2 /nobreak >nul
set /p DEL_USER="Delete Kiosk user account '%KIOSK_USER%' and its profile? (Y=Delete / N=Restore Desktop): "
if /i "%DEL_USER%"=="Y" (
powershell -NoProfile -ExecutionPolicy Bypass -Command "$u='%KIOSK_USER%'; $acc=Get-LocalUser -Name $u -ErrorAction SilentlyContinue; if ($acc) { $sid=$acc.SID.Value; Get-CimInstance Win32_UserProfile -Filter \"SID='$sid'\" -ErrorAction SilentlyContinue | Remove-CimInstance -ErrorAction SilentlyContinue; Remove-LocalUser -Name $u -ErrorAction SilentlyContinue }"
echo - Removed Kiosk user "%KIOSK_USER%" and its local profile.
) else (
powershell -NoProfile -ExecutionPolicy Bypass -Command "$u='%KIOSK_USER%'; $acc=Get-LocalUser -Name $u -ErrorAction SilentlyContinue; if ($acc) { $sid=$acc.SID.Value; $p=(Get-ItemProperty \"HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\$sid\" -ErrorAction SilentlyContinue).ProfileImagePath; if ($p -and (Test-Path \"$p\NTUSER.DAT\")) { $loaded=$false; if (-not (Test-Path \"Registry::HKEY_USERS\$sid\")) { reg.exe load \"HKU\$sid\" \"$p\NTUSER.DAT\" >$null 2>&1; if ($LASTEXITCODE -eq 0) { $loaded=$true } } if (Test-Path \"Registry::HKEY_USERS\$sid\") { reg.exe delete \"HKU\$sid\Software\Microsoft\Windows\CurrentVersion\Policies\System\" /v Shell /f >$null 2>&1; reg.exe delete \"HKU\$sid\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\" /v Shell /f >$null 2>&1 } if ($loaded) { [gc]::Collect(); Start-Sleep 1; reg.exe unload \"HKU\$sid\" >$null 2>&1 } } }"
echo - Restored normal Windows Desktop shell for "%KIOSK_USER%".
)
goto :AFTER_KIOSK_USER
:NO_KIOSK_USER
echo - No separate Kiosk user account needed removal.
:AFTER_KIOSK_USER
:: ============================================================================ :: ============================================================================
:: 4. RESTORE NORMAL DESKTOP SHELL OR DELETE KIOSK USER ACCOUNT :: 3. REMOVE SCHEDULED TASKS AND KIOSK LOCAL FILES
:: ============================================================================ :: ============================================================================
echo [4/5] Restoring or removing Kiosk user "%KIOSK_USER%"... echo [3/5] Removing scheduled tasks and local Kiosk app files...
if not "%KIOSK_USER%"=="" ( schtasks /delete /tn "DTS_WSL_Docker_AutoStart" /f >nul 2>&1
if /i not "%KIOSK_USER%"=="%USERNAME%" ( schtasks /delete /tn "DTS_Torque_Vault_Kiosk" /f >nul 2>&1
powershell -NoProfile -ExecutionPolicy Bypass -Command ^ reg delete "HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce" /v "DTS_Master_Setup" /f >nul 2>&1
"$user = '%KIOSK_USER%';" ^
"$delUser = '%DEL_USER%';" ^ if exist "%KIOSK_APP_DIR%" rmdir /s /q "%KIOSK_APP_DIR%" >nul 2>&1
"$acc = Get-LocalUser -Name $user -ErrorAction SilentlyContinue;" ^
"if ($acc) {" ^ if exist "%KIOSK_DATA_DIR%" (
" $sid = $acc.SID.Value;" ^ set /p DEL_BROWSER="Delete persistent Kiosk browser data at %KIOSK_DATA_DIR%? (Y/N): "
" $profReg = \"HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\$sid\";" ^ if /i "!DEL_BROWSER!"=="Y" (
" $profilePath = (Get-ItemProperty $profReg -ErrorAction SilentlyContinue).ProfileImagePath;" ^ rmdir /s /q "%KIOSK_DATA_DIR%" >nul 2>&1
" if ($profilePath -and (Test-Path (Join-Path $profilePath 'NTUSER.DAT'))) {" ^ echo - Removed %KIOSK_DATA_DIR%
" $hivePath = Join-Path $profilePath 'NTUSER.DAT';" ^
" $loaded = $false;" ^
" if (-not (Test-Path \"Registry::HKEY_USERS\$sid\")) { reg load \"HKU\$sid\" \"$hivePath\" >$null 2>&1; if ($LASTEXITCODE -eq 0) { $loaded = $true; } }" ^
" if (Test-Path \"Registry::HKEY_USERS\$sid\") {" ^
" Remove-ItemProperty -Path \"Registry::HKEY_USERS\$sid\Software\Microsoft\Windows\CurrentVersion\Policies\System\" -Name 'Shell' -ErrorAction SilentlyContinue;" ^
" }" ^
" if ($loaded) { [gc]::Collect(); Start-Sleep -Milliseconds 300; reg unload \"HKU\$sid\" >$null 2>&1; }" ^
" }" ^
" if ($delUser -ieq 'Y') {" ^
" Write-Host (' - Deleting user account and profile for ' + $user + '...');" ^
" Get-CimInstance -ClassName Win32_UserProfile | Where-Object { $_.SID -eq $sid } | Remove-CimInstance -ErrorAction SilentlyContinue;" ^
" Remove-LocalUser -Name $user -ErrorAction SilentlyContinue;" ^
" } else {" ^
" Write-Host (' - Normal Windows Desktop restored for ' + $user + '.');" ^
" }" ^
"}"
) else (
echo - Skipping current logged-in Administrator account for safety.
) )
) )
:: ============================================================================ :: ============================================================================
:: 5. CLEAN UP KIOSK FOLDERS, POWER PLAN & OPTIONAL WSL/DOCKER REMOVAL :: 4. RESTORE DEFAULT WINDOWS POWER PLAN AND UPDATE POLICIES
:: ============================================================================ :: ============================================================================
echo [5/5] Restoring Power Plan and cleaning up files... echo [4/5] Restoring default Balanced Power Plan and Windows Update settings...
:: Restore Balanced Power Plan
powercfg -setactive 381b4222-f694-41f0-9685-ff5bb260df2e >nul 2>&1 powercfg -setactive 381b4222-f694-41f0-9685-ff5bb260df2e >nul 2>&1
reg delete "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" /v "NoAutoRebootWithLoggedOnUsers" /f >nul 2>&1
reg delete "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" /v "AUOptions" /f >nul 2>&1
if /i "%DEL_DATA%"=="Y" ( :: ============================================================================
echo - Removing C:\KioskApp and C:\KioskBrowserData... :: 5. OPTIONAL: STOP AND REMOVE WALMART DOCKER CONTAINERS
rd /s /q "C:\KioskApp" >nul 2>&1 :: ============================================================================
rd /s /q "C:\KioskBrowserData" >nul 2>&1 echo [5/5] Checking WSL Docker containers...
) wsl -d %WSL_DISTRO% -u root true >nul 2>&1
if %errorLevel% neq 0 goto :UNINSTALL_DONE
if /i "%DEL_WSL%"=="Y" ( set "STOP_DOCKER="
echo - Stopping containers and unregistering Ubuntu-22.04 WSL... set /p STOP_DOCKER="Stop and remove Walmart Docker containers in %PROJECT_DIR%? (Y/N): "
wsl -d Ubuntu-22.04 -u root bash -c "cd /opt/walmart && docker compose down -v" >nul 2>&1 if /i not "%STOP_DOCKER%"=="Y" goto :UNINSTALL_DONE
wsl --unregister Ubuntu-22.04 >nul 2>&1
set "DEL_VOLUMES="
set /p DEL_VOLUMES="Also delete database volumes - WARNING deletes all local data? (Y/N): "
if /i "%DEL_VOLUMES%"=="Y" (
wsl -d %WSL_DISTRO% -u root bash -c "cd %PROJECT_DIR% 2>/dev/null && docker compose down -v && rm -rf %PROJECT_DIR%"
echo - Removed containers, volumes, and %PROJECT_DIR%.
) else (
wsl -d %WSL_DISTRO% -u root bash -c "cd %PROJECT_DIR% 2>/dev/null && docker compose down"
echo - Stopped and removed containers - database volumes preserved.
) )
:UNINSTALL_DONE
echo. echo.
echo ============================================================================ echo ============================================================================
echo UNINSTALL COMPLETED! MINI PC RESTORED TO NORMAL WINDOWS MODE. echo UNINSTALL COMPLETED!
echo - Windows Auto-Logon and Kiosk restrictions have been removed
echo - Normal Windows Desktop and Power/Update policies restored
echo ============================================================================ echo ============================================================================
echo. echo.
set /p REBOOT_NOW="Reboot now to apply changes? (Y/N): " set "REBOOT_NOW="
set /p REBOOT_NOW="Reboot now to apply all changes cleanly? (Y/N): "
if /i "%REBOOT_NOW%"=="Y" shutdown /r /t 3 if /i "%REBOOT_NOW%"=="Y" shutdown /r /t 3
pause pause
+85 -37
View File
@@ -1,7 +1,21 @@
@echo off @echo off
setlocal EnableDelayedExpansion setlocal EnableDelayedExpansion
:: ============================================================================
:: CONFIGURATION (RESOLVE PARENT ROOT DIRECTORY FROM /scripts)
:: ============================================================================
set "SCRIPT_DIR=%~dp0"
for %%I in ("%SCRIPT_DIR%..") do set "ROOT_DIR=%%~fI\"
set "CLEAN_ROOT=%ROOT_DIR:~0,-1%"
set "WSL_DISTRO=Ubuntu-22.04"
set "PROJECT_DIR=/opt/walmart"
set "REGISTRY_URL=gitea.digitoolsolutions.synology.me"
set "KIOSK_APP_DIR=C:\KioskApp"
:: ============================================================================
:: 0. AUTO-ELEVATE TO ADMINISTRATOR :: 0. AUTO-ELEVATE TO ADMINISTRATOR
:: ============================================================================
net session >nul 2>&1 net session >nul 2>&1
if %errorLevel% neq 0 ( if %errorLevel% neq 0 (
echo Requesting Administrator privileges... echo Requesting Administrator privileges...
@@ -9,55 +23,89 @@ if %errorLevel% neq 0 (
exit /b exit /b
) )
set "SCRIPT_DIR=%~dp0" echo ============================================================================
for %%I in ("%SCRIPT_DIR%..") do set "ROOT_DIR=%%~fI\" echo DTS TORQUE VAULT - SYSTEM UPDATE (CONTAINERS AND KIOSK SHELL)
echo ============================================================================
echo.
set "WSL_DISTRO=Ubuntu-22.04" :: ============================================================================
set "PROJECT_DIR=/opt/walmart" :: 1. PRE-FLIGHT CHECK
set "KIOSK_APP_DIR=C:\KioskApp" :: ============================================================================
ping -n 1 8.8.8.8 >nul 2>&1
echo ============================================
echo Updating Walmart containers & Kiosk splash...
echo ============================================
for %%F in ("compose.yml" ".env" "templates\startup.html") do (
if not exist "%ROOT_DIR%%%~F" (
echo [ERROR] Missing required file: "%ROOT_DIR%%%~F"
pause
exit /b 1
)
)
for /f "delims=" %%i in ('wsl -d %WSL_DISTRO% -u root wslpath -a "%ROOT_DIR%"') do set "WSL_ROOT_DIR=%%i"
echo [1/4] Updating config files and Kiosk startup template...
if not exist "%KIOSK_APP_DIR%" mkdir "%KIOSK_APP_DIR%"
copy /Y "%ROOT_DIR%templates\startup.html" "%KIOSK_APP_DIR%\startup.html" >nul
wsl -d %WSL_DISTRO% -u root bash -c "mkdir -p %PROJECT_DIR% && cp '%WSL_ROOT_DIR%/compose.yml' %PROJECT_DIR%/ && cp '%WSL_ROOT_DIR%/.env' %PROJECT_DIR%/"
if %errorLevel% neq 0 ( if %errorLevel% neq 0 (
echo [ERROR] Failed to copy config files into WSL. Is %WSL_DISTRO% installed? echo [ERROR] No Internet connection detected! Connect LAN/Wi-Fi and run again.
pause pause
exit /b 1 exit /b 1
) )
echo [2/4] Pulling latest images... wsl -d %WSL_DISTRO% -u root true >nul 2>&1
wsl -d %WSL_DISTRO% -u root bash -c "cd %PROJECT_DIR% && docker compose pull"
if %errorLevel% neq 0 ( if %errorLevel% neq 0 (
echo [ERROR] Failed to pull Docker images. Check Internet or Docker login session. echo [ERROR] WSL distribution "%WSL_DISTRO%" is not installed. Run install.bat first.
pause pause
exit /b 1 exit /b 1
) )
echo [3/4] Restarting containers... :: ============================================================================
wsl -d %WSL_DISTRO% -u root bash -c "cd %PROJECT_DIR% && docker compose up -d" :: 2. UPDATE KIOSK STARTUP PAGE (IF PRESENT)
:: ============================================================================
echo [1/4] Updating Kiosk startup template...
if exist "%ROOT_DIR%templates\startup.html" (
if not exist "%KIOSK_APP_DIR%" mkdir "%KIOSK_APP_DIR%"
copy /Y "%ROOT_DIR%templates\startup.html" "%KIOSK_APP_DIR%\startup.html" >nul
icacls "%KIOSK_APP_DIR%" /grant "Users:(OI)(CI)RX" /T >nul
echo - Updated %KIOSK_APP_DIR%\startup.html
) else (
echo - Skipped (templates\startup.html not found in package)
)
echo [4/4] Cleaning up unused images... :: ============================================================================
wsl -d %WSL_DISTRO% -u root bash -c "docker image prune -af" :: 3. SYNC COMPOSE.YML AND .ENV INTO WSL
:: ============================================================================
echo [2/4] Syncing compose.yml and .env to %PROJECT_DIR%...
for /f "delims=" %%i in ('wsl -d %WSL_DISTRO% -u root wslpath -a "%CLEAN_ROOT%"') do set "WSL_ROOT_DIR=%%i"
if exist "%ROOT_DIR%compose.yml" (
wsl -d %WSL_DISTRO% -u root bash -c "mkdir -p %PROJECT_DIR% && cp '%WSL_ROOT_DIR%/compose.yml' %PROJECT_DIR%/"
echo - Synced compose.yml
)
if exist "%ROOT_DIR%.env" (
wsl -d %WSL_DISTRO% -u root bash -c "cp '%WSL_ROOT_DIR%/.env' %PROJECT_DIR%/ && sed -i 's/\r$//' %PROJECT_DIR%/.env"
echo - Synced and normalized .env
) else (
echo - Kept existing %PROJECT_DIR%/.env on device
)
:: ============================================================================
:: 4. PULL LATEST DOCKER IMAGES AND RECREATE CONTAINERS
:: ============================================================================
echo [3/4] Pulling latest Docker images and recreating containers...
wsl -d %WSL_DISTRO% -u root service docker start >nul 2>&1
wsl -d %WSL_DISTRO% -u root docker login %REGISTRY_URL%
if %errorLevel% neq 0 (
echo [ERROR] Docker registry login failed.
pause
exit /b 1
)
wsl -d %WSL_DISTRO% -u root bash -c "cd %PROJECT_DIR% && docker compose pull && docker compose up -d --remove-orphans"
if %errorLevel% neq 0 (
echo [ERROR] Failed to update Docker containers.
pause
exit /b 1
)
:: ============================================================================
:: 5. CLEANUP UNUSED DOCKER IMAGES
:: ============================================================================
echo [4/4] Cleaning up dangling/unused Docker images...
wsl -d %WSL_DISTRO% -u root docker image prune -f >nul 2>&1
echo. echo.
echo ============================================ echo ============================================================================
echo Walmart update completed! echo UPDATE COMPLETED SUCCESSFULLY!
echo ============================================ echo - All containers are up to date and running in %PROJECT_DIR%
wsl -d %WSL_DISTRO% -u root bash -c "docker ps" echo - Database and Kiosk user configuration were preserved
echo ============================================================================
echo.
pause pause