10 Commits
13 changed files with 1270 additions and 139 deletions
+23 -23
View File
@@ -1,34 +1,34 @@
# Frontend environments # Frontend environments
VITE_PORT = VITE_PORT = 3000
VITE_API_BASE_URL = VITE_API_BASE_URL = /api/v1/
VITE_API_WS_URL = VITE_API_WS_URL = /ws/
VITE_SECURITY_CODE = VITE_SECURITY_CODE = "00"
# Backend environments # Backend environments
DEBUG = DEBUG = False
SECRET_KEY = SECRET_KEY = <ENTER SECRET KEY HERE>
ALLOWED_HOSTS = ALLOWED_HOSTS = localhost,proxy
PER_PAGE_SIZE = PER_PAGE_SIZE = 10
# Database # Database
MYSQL_PORT= MYSQL_PORT=3306
DATABASE_NAME = DATABASE_NAME = walmart_db
DATABASE_USER = DATABASE_USER = root
DATABASE_PASSWORD = DATABASE_PASSWORD = digitoolsolutions
DATABASE_HOST = DATABASE_HOST = mysql
DJANGO_SUPERUSER_USERNAME = DJANGO_SUPERUSER_USERNAME = superadmin
DJANGO_SUPERUSER_EMAIL = DJANGO_SUPERUSER_EMAIL = admin@gmail.com
DJANGO_SUPERUSER_PASSWORD = DJANGO_SUPERUSER_PASSWORD = admin
# Redis # Redis
REDIS_PORT = REDIS_PORT=6379
# Watchtower # Watchtower
WATCHTOWER_HTTP_API_TOKEN = WATCHTOWER_HTTP_API_TOKEN = <ENTER TOKEN HERE>
UPDATE_HOOK_TOKEN = UPDATE_HOOK_TOKEN = <ENTER TOKEN HERE>
WATCHTOWER_URL = WATCHTOWER_URL = http://watchtower:8080/v1/update
# Registry Images # Registry Images
FRONTEND_IMAGE = FRONTEND_IMAGE = gitea.digitoolsolutions.synology.me/dts/tv-walmart-fe:latest
BACKEND_IMAGE = BACKEND_IMAGE = gitea.digitoolsolutions.synology.me/dts/tv-walmart-be:latest
RELEASE_API_URL = RELEASE_API_URL = https://server.digitoolsolutions.synology.me/api/v1/system/release/latest/
+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
+99
View File
@@ -0,0 +1,99 @@
# DTS Torque Vault - Mini PC Kiosk Commissioning & QA Checklist
Use this checklist after a fresh deployment with `setup.bat` or `scripts\install.bat`.
For maintenance, also complete the Update Verification section after `scripts\update.bat`.
---
## Unit Information
| Field | Details |
| :----------------------------- | :-------------------------------------------- |
| **Device Hostname / Serial #** | `________________________________________` |
| **Site / Location** | `________________________________________` |
| **Configured Kiosk Username** | `Torque Vault` _(or: `____________________`)_ |
| **Technician Name** | `________________________________________` |
| **Deployment Date** | `____ / ____ / ____` |
---
## 1. Pre-Deployment & Package Verification
- [ ] Deployment package is available locally at `C:\Apps\mini-pc-setup\` (via `setup.bat`) or from the approved extracted release.
- [ ] All required files are present: `setup.bat`, `scripts\install.bat`, `scripts\update.bat`, `scripts\uninstall.bat`, `templates\startup.html`, `compose.yml`, `.env.template`, `.env`, `Readme.md`, and `CheckList.md`.
- [ ] `.env` has been reviewed and contains the intended `FRONTEND_IMAGE`, `BACKEND_IMAGE`, database, Redis, application, and Watchtower values. Production secrets have not been copied into the shared release.
- [ ] `setup.bat` or `scripts\install.bat` was run as Administrator.
- [ ] BIOS Hardware Virtualization (`Intel VT-x` / `AMD-V`) verified as **Enabled**.
- [ ] Active LAN / Wi-Fi connection confirmed.
- [ ] Microsoft Edge is installed in one of the standard 32-bit or 64-bit Program Files locations.
---
## 2. WSL2 & Docker Backend Verification
_(Sign in as **Administrator** to run these checks if needed)_
- [ ] `Ubuntu-22.04` WSL2 distribution is installed with `systemd=true` in `/etc/wsl.conf` and `vmIdleTimeout=-1` in the installing Administrator's `%USERPROFILE%\.wslconfig`.
- [ ] Docker Engine package `5:28.3.2-1~ubuntu.22.04~jammy` and Docker Compose V2 are installed; Docker Engine packages are pinned with `apt-mark hold`.
- [ ] The `walmart` project runs from `/opt/walmart` and all services show an expected status:
`wsl -d Ubuntu-22.04 -u root docker ps`
- [ ] Container names are expected: `tv-proxy-prod`, `tv-redis-prod`, `tv-db-prod`, `tv-backend-prod`, `tv-frontend-prod`, and `tv-watchtower-prod`.
- [ ] Backend health endpoint `http://localhost:3000/api/v1/system/health-check/` returns **`Online`**.
- [ ] Scheduled Task **`WSL Docker Startup`** exists, triggers **At startup**, and runs under the installing Administrator account (not `SYSTEM`).
- [ ] The startup task has no execution-time limit and is allowed to restart if it fails.
---
## 3. Kiosk Mode, Auto-Logon & Session Persistence
- [ ] **Cold Boot / Reboot Test:** Restart the Mini PC and verify it bypasses the Windows login screen and automatically signs into the Kiosk account (`Torque Vault`).
- [ ] **UI Lockdown:** The Start Menu and Taskbar are hidden in the kiosk session; Microsoft Edge launches fullscreen from `C:\KioskApp\startup.html` and transitions to `http://localhost:3000`.
- [ ] Edge is launched with a persistent profile under `C:\KioskBrowserData` and InPrivate browsing, browsing-data clearing, and first-run prompts are disabled.
- [ ] **Session Persistence Test:** Log into the web application inside Kiosk mode, reboot the Mini PC, and confirm the browser session/cookies in `C:\KioskBrowserData` remain intact (no forced re-login).
- [ ] **Admin Escape Hatch:** Pressing `Ctrl + Alt + Del` and switching/signing out allows access to the Administrator account with a normal Windows Desktop.
---
## 4. 24/7 Power, Peripherals & Update Hardening
- [ ] Active Windows Power Plan is set to **High Performance**.
- [ ] Sleep and hibernation are disabled. The selected display-off timeout is applied (`0` means the display stays on).
- [ ] **USB Selective Suspend** is **Disabled** (`0`).
- [ ] Disk timeouts are set to **Never** (`0`).
- [ ] Windows is configured not to automatically reboot with the logged-on user for scheduled updates.
- [ ] Connected peripherals (USB dongle, barcode scanner, touchscreen) respond immediately after sitting idle for 15+ minutes.
- [ ] **Power Loss Recovery Test:** Disconnect AC power (or perform a hard power cycle), reconnect power, and confirm the Mini PC boots directly back into the active Kiosk application without manual intervention.
---
## 5. Update Verification
Complete this section after running `scripts\update.bat` as Administrator.
- [ ] The current `.env` and `compose.yml` were reviewed and copied/synchronized by the updater.
- [ ] Docker registry login succeeds and the updater completes the image pull.
- [ ] `docker compose -p walmart up -d --remove-orphans` completes successfully.
- [ ] Backend health endpoint returns **`Online`** after the update.
- [ ] `C:\KioskApp\startup.html` is updated when `templates\startup.html` is present.
- [ ] Existing named volumes `tv-data-prod`, `tv-redis-prod`, and `tv-state-prod` are preserved.
- [ ] The application remains usable and required kiosk data/logon are unchanged.
- [ ] Dangling Docker images are pruned and `docker compose -p walmart ps` shows the expected service state.
---
## 6. Troubleshooting Evidence
- [ ] Container status checked:
`wsl -d Ubuntu-22.04 -u root docker ps`
- [ ] Backend logs checked if needed:
`wsl -d Ubuntu-22.04 -u root docker logs tv-backend-prod`
- [ ] Registry login and `FRONTEND_IMAGE` / `BACKEND_IMAGE` values verified if image pull fails.
- [ ] `WSL Docker Startup` Task Scheduler entry verified if the application is unavailable after reboot.
---
## Final Sign-Off
- [ ] **PASS — Unit approved for production deployment.**
**Technician Signature:** `___________________________` &nbsp;&nbsp;&nbsp; **Date:** `____ / ____ / ____`
+84 -28
View File
@@ -1,41 +1,97 @@
# Setup Project on Mini PC (Windows) # DTS Torque Vault — Mini PC Kiosk Deployment
In the `scripts` folder there are several `.bat` files used to set up the environment on the mini PC. Deployment and maintenance guide for Windows Mini PCs running DTS Torque Vault in Edge kiosk mode, with the application stack hosted by Docker Engine inside WSL2.
## Repository contents
```text
mini-pc-setup/
├── setup.bat # Downloads and extracts the latest Gitea release
├── compose.yml # Docker Compose stack (project name: walmart)
├── .env.template # Sample configuration used to create .env
├── CheckList.md # Commissioning and QA checklist
├── scripts/
│ ├── install.bat # Installs and configures WSL2, Docker, and kiosk mode
│ ├── update.bat # Pulls images and updates the Compose stack
│ └── uninstall.bat # Removes kiosk configuration and/or application data
└── templates/
└── startup.html # Local startup screen that waits for the web app
```
The installer creates a hidden `.env` file from `.env.template` if `.env` is missing. The sample file is then removed from the deployment directory. Keep `.env` private: it contains application and database settings, including secrets. Docker registry credentials are entered separately at the login prompt.
## Requirements ## Requirements
- Create an `Apps` folder on the `C` drive. - 64-bit Windows 10 or Windows 11, with Microsoft Edge installed.
- Clone this repository into the `Apps` directory. Note that should not rename the directory you have just cloned. - A local Windows Administrator account. Run deployment while signed in to the administrator account that should own the WSL startup task.
- CPU virtualization enabled in BIOS/UEFI.
- Internet access for Gitea, Ubuntu/WSL, Docker packages, and container images.
## Steps ## Fresh deployment
1. **Update and rename `.env.template` file to `.env`** 1. Run `setup.bat` as Administrator, or extract a release and run `scripts\install.bat` as Administrator.
- `setup.bat` downloads the latest release of `lamtruong28/mini-pc-setup` from `https://gitea.digitoolsolutions.synology.me` and extracts it to `C:\Apps\mini-pc-setup`.
- If the release requires authentication, the bootstrapper prompts for Gitea credentials.
- **Warning:** `setup.bat` deletes the existing `C:\Apps\mini-pc-setup` directory before extracting. Back up any local configuration or files there first.
2. On the first install, review and complete `.env` in Notepad when prompted. Configure the image names and all application, database, Redis, and Watchtower values required by your deployment. Do not put production credentials in a shared release.
3. If WSL2 or `Ubuntu-22.04` is not ready, the installer installs it, creates a logon-triggered resume task, and reboots Windows. Sign back in to the same Administrator account; the installer resumes automatically.
4. Follow the prompts:
- Enter a non-root Linux username and a sudo password for WSL (the suggested username is `gateway`).
- Sign in to the Docker registry when prompted.
- Select a separate Windows kiosk account (default name: `Torque Vault`) and optionally set its password.
- Choose the display-off timeout in minutes (default: 15; enter `0` to keep the display on).
5. At completion, enter `Y` to reboot into kiosk mode.
2. **Run `setup-wsl.bat`** ## What the installer configures
- This will install WSL with Ubuntu‑22.04.
- Follow the prompts to create a default UNIX user account inside WSL.
3. **Run `setup-docker.bat`** | Stage | Configuration |
- This will install Docker Engine (v2) and Docker Compose V2 inside the Ubuntu WSL you just created. | ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
- It also enables the Docker daemon to start automatically. | Pre-check | Verifies Edge, required configuration files, Internet connectivity, and virtualization; restricts the deployment folder ACLs to Administrators and SYSTEM. |
| WSL2 | Installs/starts `Ubuntu-22.04`, configures the selected Linux user, enables systemd, and sets `vmIdleTimeout=-1` in the administrator's `.wslconfig`. |
| Docker | Installs Docker Engine `5:28.3.2-1~ubuntu.22.04~jammy` and Compose V2; holds Docker Engine packages at the installed version. |
| Application | Copies `compose.yml` and `.env` to `/opt/walmart`, pulls images, starts the `walmart` Compose project, and polls the health endpoint for `Online` (up to 10 attempts, 30 seconds apart). |
| Kiosk account and startup | Configures Windows Auto-Logon and the kiosk user's shell to launch fullscreen Edge using `C:\KioskApp\startup.html`; stores Edge profile data in `C:\KioskBrowserData`. Registers the `WSL Docker Startup` task to start the stack at Windows startup under the installing Administrator account. |
| 24/7 settings | Selects High Performance, disables sleep and hibernation, leaves disk timeouts off, disables USB selective suspend, applies the selected display timeout, and configures Windows Update not to auto-reboot while a user is logged on. |
4. **Run `setup-prj.bat`** The startup page checks `http://localhost:3000/api/v1/system/health-check/` and redirects to the application when the endpoint responds successfully.
- Login docker to Gitea.
- Create `walmart` folder in WSL.
- Copy `.env` and `compose` files to `walmart` folder.
- Run docker compose file `docker compose up -d`.
5. **Run `update-prj.bat`** ## Maintenance
- This will pull latest image from container registry.
- Restart all containers in compose file
- Remove unused images (old images)
## Notes ### Update the application
- During these steps, you may be asked to enter your UNIX user password (for `sudo` commands). Run `C:\Apps\mini-pc-setup\scripts\update.bat` as Administrator, preferably after signing out of the kiosk account and into the Administrator account.
- Make sure you reboot your PC after running `setup-wsl.bat` before continuing with the next scripts.
- Verify installation by running: The updater checks WSL and required files, syncs `compose.yml` and `.env` to `/opt/walmart`, prompts for Docker registry login, pulls images, and runs `docker compose -p walmart up -d --remove-orphans`. It then checks the health endpoint and prunes dangling images. The named Docker volumes are preserved, but containers may restart and the application may be temporarily unavailable during an update.
```bash
docker --version To change settings, edit `.env` or `compose.yml` in `C:\Apps\mini-pc-setup` before running the updater. The startup page is also copied to `C:\KioskApp` when present.
docker compose version
### Commission the device
Use [CheckList.md](./CheckList.md) to verify WSL/Docker, application health, kiosk startup, persistent browser data, peripherals, and power recovery.
### Uninstall or restore the desktop
Run `C:\Apps\mini-pc-setup\scripts\uninstall.bat` as Administrator and choose a mode:
- **`1` Auto Wipe All:** Requires typing `YES`. Removes kiosk settings and user/profile, browser data, kiosk files/tasks, and the Walmart Compose project and volumes; restores the Balanced power plan and removes selected policies. If run from `C:\Apps\mini-pc-setup`, it also schedules that setup folder for deletion.
- **`2` Manual / Custom:** Prompts whether to delete or restore the kiosk user's desktop, keep browser data, remove the Compose project, delete its volumes, and remove the setup folder.
Deleting Compose volumes permanently deletes local application/database data. The uninstaller removes the application stack and its project files; it does **not** uninstall the WSL distribution or Docker packages.
## Troubleshooting
- **The application is unavailable after reboot:** In Task Scheduler, inspect **WSL Docker Startup**. It should run at startup under the Administrator account used for installation (not `SYSTEM`). Check container status with:
```bat
wsl -d Ubuntu-22.04 -u root docker ps
``` ```
- **Inspect backend logs:**
```bat
wsl -d Ubuntu-22.04 -u root docker logs tv-backend-prod
```
- **Registry login or image pull fails:** Confirm Internet access, registry credentials, and the `FRONTEND_IMAGE` and `BACKEND_IMAGE` values in `.env`.
- **Leave kiosk mode for maintenance:** Press `Ctrl + Alt + Del` and switch/sign out to the Administrator account. The Administrator account retains the normal Windows desktop.
+557
View File
@@ -0,0 +1,557 @@
@echo off
setlocal EnableDelayedExpansion
:: ============================================================================
:: CONFIGURATION (EDIT THESE VARIABLES DIRECTLY)
:: ============================================================================
set "SCRIPT_DIR=%~dp0"
for %%I in ("%SCRIPT_DIR%..") do set "ROOT_DIR=%%~fI\"
set "CLEAN_ROOT=%ROOT_DIR:~0,-1%"
:: WSL2 & Docker Engine Settings
set "WSL_DISTRO=Ubuntu-22.04"
set "DEFAULT_WSL_USER=gateway"
set "DOCKER_VERSION=5:28.3.2-1~ubuntu.22.04~jammy"
:: Project & Health-Check Polling Settings
set "PROJECT_NAME=walmart"
set "PROJECT_DIR=/opt/walmart"
set "REGISTRY_URL=gitea.digitoolsolutions.synology.me"
set "HEALTH_PORT=3000"
set "HEALTH_PATH=/api/v1/system/health-check/"
set "HEALTH_INTERVAL=30"
set "HEALTH_MAX_RETRIES=10"
:: 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"
:: ============================================================================
:: 0. AUTO-ELEVATE TO ADMINISTRATOR
:: ============================================================================
net session >nul 2>&1
if %errorLevel% neq 0 (
echo Requesting Administrator privileges...
powershell -NoProfile -Command "Start-Process -FilePath '%~f0' -Verb RunAs"
exit /b
)
echo ============================================================================
echo DTS TORQUE VAULT - MASTER MINI-PC DEPLOYMENT (24/7 PRODUCTION EDITION)
echo ============================================================================
echo.
:: ============================================================================
:: PRE-FLIGHT CHECK: REQUIRED FILES, EDGE, INTERNET & BIOS VIRTUALIZATION
:: ============================================================================
echo [PRE-CHECK] Verifying required files, Edge, Internet and CPU Virtualization...
if exist "%EDGE_EXE%" goto :EDGE_OK
echo [ERROR] Microsoft Edge not found at "%EDGE_EXE%".
pause
exit /b 1
:EDGE_OK
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
echo - Generating .env with secure random SECRET_KEY and Watchtower tokens...
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
"$tpl = Get-Content -Raw -Path '%ENV_SAMPLE%';" ^
"$rng = [System.Security.Cryptography.RandomNumberGenerator]::Create();" ^
"$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'.ToCharArray();" ^
"$b1 = New-Object byte[] 50; $rng.GetBytes($b1);" ^
"$secret = -join ($b1 | ForEach-Object { $chars[$_ %% $chars.Length] });" ^
"$b2 = New-Object byte[] 32; $rng.GetBytes($b2); $wtToken = ([BitConverter]::ToString($b2) -replace '-','').ToLower();" ^
"$b3 = New-Object byte[] 32; $rng.GetBytes($b3); $hookToken = ([BitConverter]::ToString($b3) -replace '-','').ToLower();" ^
"$tpl = $tpl -replace '<ENTER SECRET KEY HERE>', $secret;" ^
"$tpl = [regex]::Replace($tpl, '<ENTER TOKEN HERE>', $wtToken, 1);" ^
"$tpl = [regex]::Replace($tpl, '<ENTER TOKEN HERE>', $hookToken, 1);" ^
"$utf8NoBom = New-Object System.Text.UTF8Encoding $false;" ^
"[System.IO.File]::WriteAllText('%ROOT_DIR%.env', $tpl, $utf8NoBom);" ^
"if ($tpl -match '<ENTER ') { exit 2 } else { exit 0 }"
if %errorLevel% equ 2 (
echo [ACTION REQUIRED] Some placeholders remain in .env. Configure 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
)
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"
pause
exit /b 1
)
if not exist "%ROOT_DIR%compose.yml" (
echo [ERROR] Missing required file: "%ROOT_DIR%compose.yml"
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
ping -n 1 8.8.8.8 >nul 2>&1
if %errorLevel% neq 0 (
echo [ERROR] No Internet connection detected! Connect LAN/Wi-Fi and run again.
pause
exit /b 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 (
echo [ERROR] Hardware Virtualization is DISABLED in BIOS!
echo Please reboot into BIOS, enable Virtualization, and run again.
pause
exit /b 1
)
echo - Pre-flight checks passed!
echo.
:: ============================================================================
:: 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 (
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
)
goto :PHASE1_NEED_REBOOT
)
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 ============================================================================
echo [REBOOT REQUIRED] Windows must restart to activate WSL2 kernel.
echo This installer will resume automatically after you log back in as Admin.
echo ============================================================================
echo.
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
:: ============================================================================
echo [1/7] Initializing %WSL_DISTRO%, configuring Linux user, systemd and VM idle timeout...
set "WSL_USER="
set /p WSL_USER="Enter Linux username for WSL [Default: %DEFAULT_WSL_USER%]: "
if "%WSL_USER%"=="" set "WSL_USER=%DEFAULT_WSL_USER%"
if /i "%WSL_USER%"=="root" goto :ERR_WSL_ROOT
set "WSL_PASS="
set /p WSL_PASS="Enter Linux sudo password for '%WSL_USER%' [Default: Dts@2026]: "
if "%WSL_PASS%"=="" set "WSL_PASS=Dts@2026"
powershell -NoProfile -ExecutionPolicy Bypass -Command "$wslCfg = Join-Path $env:USERPROFILE '.wslconfig'; Set-Content -Path $wslCfg -Value \"[wsl2]`r`nvmIdleTimeout=-1\" -Encoding Ascii"
set "STEP1_SH=%TEMP%\dts_step1.sh"
> "%STEP1_SH%" echo set -e
>> "%STEP1_SH%" echo WSL_USR="$1"
>> "%STEP1_SH%" echo WSL_PWD="$2"
>> "%STEP1_SH%" echo id -u "$WSL_USR" ^>/dev/null 2^>^&1 ^|^| useradd -m -s /bin/bash -G sudo "$WSL_USR"
>> "%STEP1_SH%" echo echo "${WSL_USR}:${WSL_PWD}" ^| chpasswd
>> "%STEP1_SH%" echo rm -f "/etc/sudoers.d/${WSL_USR}"
>> "%STEP1_SH%" echo printf '[user]\ndefault=%%s\n[boot]\nsystemd=true\n' "$WSL_USR" ^> /etc/wsl.conf
for /f "delims=" %%i in ('wsl -d %WSL_DISTRO% -u root wslpath -a "%STEP1_SH%"') do set "WSL_STEP1_SH=%%i"
wsl -d %WSL_DISTRO% -u root bash -c "tr -d '\r' < '%WSL_STEP1_SH%' > /tmp/dts_step1.sh && bash /tmp/dts_step1.sh '%WSL_USER%' '%WSL_PASS%'; RC=$?; rm -f /tmp/dts_step1.sh; exit $RC"
set "STEP1_ERR=%errorLevel%"
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 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
echo [ERROR] Cannot use root as the standard WSL user!
pause
exit /b 1
:ERR_WSL_USER
echo [ERROR] Failed to create or configure Linux user "%WSL_USER%".
pause
exit /b 1
:PHASE2_DONE
:: ============================================================================
:: PHASE 3: INSTALL & PIN DOCKER ENGINE + COMPOSE V2 (DIRECT .SH + DYNAMIC PARAMS)
:: ============================================================================
echo [2/7] Installing Docker Engine (%DOCKER_VERSION%) + Compose V2...
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 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
>> "%STEP2_SH%" echo curl -fsSL https://download.docker.com/linux/ubuntu/gpg ^| gpg --dearmor --yes -o /etc/apt/keyrings/docker.gpg
>> "%STEP2_SH%" echo 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
>> "%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 }
>> "%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"
wsl -d %WSL_DISTRO% -u root bash -c "tr -d '\r' < '%WSL_STEP2_SH%' > /tmp/dts_step2.sh && bash /tmp/dts_step2.sh '%DOCKER_VERSION%' '%WSL_USER%'; RC=$?; rm -f /tmp/dts_step2.sh; exit $RC"
set "STEP2_ERR=%errorLevel%"
del /f /q "%STEP2_SH%" >nul 2>&1
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%...
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% 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"
set "STEP3_SH=%TEMP%\dts_step3.sh"
> "%STEP3_SH%" echo set -e
>> "%STEP3_SH%" echo SRC_DIR="$1"
>> "%STEP3_SH%" echo PROJ_DIR="$2"
>> "%STEP3_SH%" echo PROJ_NAME="$3"
>> "%STEP3_SH%" echo PORT="$4"
>> "%STEP3_SH%" echo ENDPOINT="$5"
>> "%STEP3_SH%" echo INTERVAL="$6"
>> "%STEP3_SH%" echo MAX_RETRIES="$7"
>> "%STEP3_SH%" echo mkdir -p "$PROJ_DIR"
>> "%STEP3_SH%" echo cp "$SRC_DIR/compose.yml" "$PROJ_DIR/compose.yml"
>> "%STEP3_SH%" echo tr -d '\r' ^< "$SRC_DIR/.env" ^> "$PROJ_DIR/.env"
>> "%STEP3_SH%" echo cd "$PROJ_DIR"
>> "%STEP3_SH%" echo docker compose -p "$PROJ_NAME" pull
>> "%STEP3_SH%" echo docker compose -p "$PROJ_NAME" up -d
>> "%STEP3_SH%" echo echo " - Up complete. Polling http://localhost:${PORT}${ENDPOINT} every ${INTERVAL}s (max ${MAX_RETRIES} attempts)..."
>> "%STEP3_SH%" echo for i in $(seq 1 "$MAX_RETRIES"); do
>> "%STEP3_SH%" echo RES=$(curl -kfsS --max-time 3 "http://localhost:${PORT}${ENDPOINT}" 2^>/dev/null ^|^| true)
>> "%STEP3_SH%" echo if echo "$RES" ^| grep -qi "Online"; then
>> "%STEP3_SH%" echo echo " - Server is Online and migrations are complete!"
>> "%STEP3_SH%" echo exit 0
>> "%STEP3_SH%" echo fi
>> "%STEP3_SH%" echo echo " - Attempt $i/$MAX_RETRIES: Server is still initializing/migrating, retrying in ${INTERVAL}s..."
>> "%STEP3_SH%" echo sleep "$INTERVAL"
>> "%STEP3_SH%" echo done
>> "%STEP3_SH%" echo echo " - [ERROR] Timed out waiting for Server on port $PORT to become Online!"
>> "%STEP3_SH%" echo exit 1
for /f "delims=" %%i in ('wsl -d %WSL_DISTRO% -u root wslpath -a "%STEP3_SH%"') do set "WSL_STEP3_SH=%%i"
wsl -d %WSL_DISTRO% -u root bash -c "tr -d '\r' < '%WSL_STEP3_SH%' > /tmp/dts_step3.sh && bash /tmp/dts_step3.sh '%WSL_ROOT_DIR%' '%PROJECT_DIR%' '%PROJECT_NAME%' '%HEALTH_PORT%' '%HEALTH_PATH%' '%HEALTH_INTERVAL%' '%HEALTH_MAX_RETRIES%'; RC=$?; rm -f /tmp/dts_step3.sh; exit $RC"
set "STEP3_ERR=%errorLevel%"
del /f /q "%STEP3_SH%" >nul 2>&1
if %STEP3_ERR% neq 0 (
echo [ERROR] Deployment or server health-check failed. Check logs with: wsl -d %WSL_DISTRO% -u root docker logs tv-backend-prod
pause
exit /b 1
)
:: ============================================================================
:: PHASE 5: INTERACTIVE KIOSK USER CREATION & AUTO-LOGON SETUP
:: ============================================================================
echo.
echo [5/7] Configuring Kiosk Mode Account...
echo Existing local user accounts:
powershell -NoProfile -Command "Get-LocalUser | Where-Object { $_.Enabled -eq $true } | Select-Object -ExpandProperty Name"
echo.
set "PREV_KIOSK_USER="
for /f "tokens=2*" %%A in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v "DefaultUserName" 2^>nul') do set "PREV_KIOSK_USER=%%B"
set "KIOSK_USER="
set /p KIOSK_USER="Enter Kiosk username to create/configure [Default: %DEFAULT_KIOSK_USER%]: "
if "%KIOSK_USER%"=="" set "KIOSK_USER=%DEFAULT_KIOSK_USER%"
if /i "%KIOSK_USER%"=="%USERNAME%" (
echo [ERROR] Cannot use current Administrator account "%KIOSK_USER%" for Kiosk!
pause
exit /b 1
)
set "KIOSK_PASS="
set /p KIOSK_PASS="Enter password for '%KIOSK_USER%' (leave blank for no password): "
if "%PREV_KIOSK_USER%"=="" goto :SKIP_REMOVE_OLD
if /i "%PREV_KIOSK_USER%"=="%KIOSK_USER%" goto :SKIP_REMOVE_OLD
if /i "%PREV_KIOSK_USER%"=="%USERNAME%" goto :SKIP_REMOVE_OLD
if /i "%PREV_KIOSK_USER%"=="Administrator" goto :SKIP_REMOVE_OLD
echo - Removing previous Kiosk user "%PREV_KIOSK_USER%" and its profile...
for /f "tokens=3" %%S in ('query user "%PREV_KIOSK_USER%" 2^>nul ^| findstr /i "%PREV_KIOSK_USER%"') do logoff %%S >nul 2>&1
timeout /t 2 /nobreak >nul
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" ^
"}"
:SKIP_REMOVE_OLD
net accounts /minpwlen:0 >nul 2>&1
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 }" ^
"}"
if %errorLevel% neq 0 (
echo [ERROR] Failed to create or update user "%KIOSK_USER%".
pause
exit /b 1
)
wmic useraccount where name="%KIOSK_USER%" set PasswordExpires=False >nul 2>&1
net user "%KIOSK_USER%" /logonpasswordchg:no >nul 2>&1
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_APP_DIR%" mkdir "%KIOSK_APP_DIR%"
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_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 WSL Docker Startup.
) else (
echo - Registered 24/7 startup task: WSL Docker Startup (User: %USERDOMAIN%\%USERNAME%^)
)
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 "DefaultDomainName" /t REG_SZ /d "%COMPUTERNAME%" /f >nul
reg add "%WINLOGON_KEY%" /v "DefaultUserName" /t REG_SZ /d "%KIOSK_USER%" /f >nul
reg add "%WINLOGON_KEY%" /v "DefaultPassword" /t REG_SZ /d "%KIOSK_PASS%" /f >nul
reg delete "%WINLOGON_KEY%" /v "AutoLogonCount" /f >nul 2>&1
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" /v "HideFastUserSwitching" /t REG_DWORD /d 0 /f >nul
reg delete "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v "Shell" /f >nul 2>&1
set "EDGE_POL=HKLM\SOFTWARE\Policies\Microsoft\Edge"
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 "RestoreOnStartup" /t REG_DWORD /d 4 /f >nul
reg add "%EDGE_POL%" /v "ShowHomeButton" /t REG_DWORD /d 0 /f >nul
reg add "%EDGE_POL%" /v "HomepageLocation" /t REG_SZ /d "file:///C:/KioskApp/startup.html" /f >nul
reg add "%EDGE_POL%" /v "NewTabPageLocation" /t REG_SZ /d "file:///C:/KioskApp/startup.html" /f >nul
reg add "%EDGE_POL%" /v "DeveloperToolsAvailability" /t REG_DWORD /d 2 /f >nul
reg add "%EDGE_POL%" /v "AllowDeletingBrowserHistory" /t REG_DWORD /d 0 /f >nul
reg add "%EDGE_POL%" /v "PrintingEnabled" /t REG_DWORD /d 0 /f >nul
reg add "%EDGE_POL%" /v "DownloadRestrictions" /t REG_DWORD /d 3 /f >nul
reg add "%EDGE_POL%" /v "BookmarkBarEnabled" /t REG_DWORD /d 0 /f >nul
reg add "%EDGE_POL%" /v "AutofillAddressEnabled" /t REG_DWORD /d 0 /f >nul
reg add "%EDGE_POL%" /v "AutofillCreditCardEnabled" /t REG_DWORD /d 0 /f >nul
reg add "%EDGE_POL%" /v "PasswordManagerEnabled" /t REG_DWORD /d 0 /f >nul
reg add "%EDGE_POL%" /v "HideFirstRunExperience" /t REG_DWORD /d 1 /f >nul
reg add "%EDGE_POL%" /v "TranslateEnabled" /t REG_DWORD /d 0 /f >nul
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 --allow-file-access-from-files --disable-pinch';" ^
" $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
:: ============================================================================
:: PHASE 6: CONFIGURE 24/7 ALWAYS-ON POWER PLAN & BLOCK AUTO-REBOOT UPDATES
:: ============================================================================
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
:: 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
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
reg add "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" /v "AUOptions" /t REG_DWORD /d 3 /f >nul
echo.
echo ============================================================================
echo ALL-IN-ONE 24/7 KIOSK DEPLOYMENT COMPLETED!
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 (%DISPLAY_STATUS_MSG%, No Lock/Sleep)
echo ============================================================================
echo.
set "REBOOT_FINAL="
set /p REBOOT_FINAL="Reboot now to enter full Kiosk Production mode? (Y/N): "
if /i "%REBOOT_FINAL%"=="Y" shutdown /r /t 3
pause
-22
View File
@@ -1,22 +0,0 @@
@echo off
echo Adding official Docker repository...
wsl -d Ubuntu-22.04 bash -c "sudo apt-get update && sudo apt-get install -y ca-certificates curl gnupg lsb-release"
wsl -d Ubuntu-22.04 bash -c "sudo install -m 0755 -d /etc/apt/keyrings"
wsl -d Ubuntu-22.04 bash -c "curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg"
wsl -d Ubuntu-22.04 bash -c "echo 'deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable' | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null"
echo Installing Docker Engine 28.3.2 + Docker Compose V2...
wsl -d Ubuntu-22.04 bash -c "sudo apt-get update && sudo 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"
echo Holding Docker packages to prevent auto-upgrade...
wsl -d Ubuntu-22.04 bash -c "sudo apt-mark hold docker-ce docker-ce-cli containerd.io"
echo Enabling Docker daemon...
wsl -d Ubuntu-22.04 bash -c "sudo systemctl enable docker && sudo systemctl start docker"
echo ============================================
echo Setup complete! Checking versions...
wsl -d Ubuntu-22.04 bash -c "docker --version"
wsl -d Ubuntu-22.04 bash -c "docker compose version"
echo ============================================
pause
-27
View File
@@ -1,27 +0,0 @@
@echo off
REM ============================================
REM Clone source code and start Docker Compose
REM ============================================
echo Login docker
wsl -d Ubuntu-22.04 bash -c "sudo docker login gitea.digitoolsolutions.synology.me"
echo [1/3] Copying files into WSL...
REM Create ~/walmart folder in WSL
wsl -d Ubuntu-22.04 bash -c "mkdir -p ~/walmart"
REM Copy docker-compose.yml and .env from Windows to WSL
wsl -d Ubuntu-22.04 bash -c "cp /mnt/c/Apps/mini-pc-setup/compose.yml ~/walmart/"
wsl -d Ubuntu-22.04 bash -c "cp /mnt/c/Apps/mini-pc-setup/.env ~/walmart/"
echo [2/3] Starting containers...
wsl -d Ubuntu-22.04 bash -c "cd ~/walmart && sudo docker compose up -d"
echo [3/3] Showing running containers...
wsl -d Ubuntu-22.04 bash -c "sudo docker ps"
echo ============================================
echo Project 'walmart' is up and running!
echo ============================================
pause
-5
View File
@@ -1,5 +0,0 @@
@echo off
echo Installing WSL with Ubuntu-22.04...
wsl --install -d Ubuntu-22.04
echo Please reboot your computer and create your Ubuntu user before continuing.
pause
+243
View File
@@ -0,0 +1,243 @@
@echo off
setlocal EnableDelayedExpansion
:: ============================================================================
:: CONFIGURATION (SYNCED WITH INSTALL.BAT)
:: ============================================================================
set "SCRIPT_DIR=%~dp0"
for %%I in ("%SCRIPT_DIR%..") do (
set "ROOT_DIR=%%~fI\"
set "ROOT_FOLDER_NAME=%%~nxI"
)
set "CLEAN_ROOT=%ROOT_DIR:~0,-1%"
set "WSL_DISTRO=Ubuntu-22.04"
set "PROJECT_NAME=walmart"
set "PROJECT_DIR=/opt/walmart"
set "KIOSK_APP_DIR=C:\KioskApp"
set "KIOSK_DATA_DIR=C:\KioskBrowserData"
:: ============================================================================
:: 0. AUTO-ELEVATE TO ADMINISTRATOR
:: ============================================================================
net session >nul 2>&1
if %errorLevel% neq 0 (
echo Requesting Administrator privileges...
powershell -NoProfile -Command "Start-Process -FilePath '%~f0' -Verb RunAs"
exit /b
)
echo ============================================================================
echo DTS TORQUE VAULT - KIOSK MODE UNINSTALLER AND SYSTEM RESTORE
echo ============================================================================
echo.
echo Select uninstall mode:
echo [1] Auto Wipe All - Automatically remove Kiosk user, browser data,
echo scheduled tasks, Docker containers, database volumes
echo and the '%ROOT_FOLDER_NAME%' setup folder
echo [2] Manual / Custom - Choose step-by-step what to keep or delete
echo [0] Cancel
echo.
set "UNINSTALL_MODE="
set /p UNINSTALL_MODE="Enter your choice [1 / 2 / 0]: "
if "%UNINSTALL_MODE%"=="0" (
echo Uninstall cancelled.
pause
exit /b 0
)
set "AUTO_WIPE=0"
if "%UNINSTALL_MODE%"=="1" (
set "AUTO_WIPE=1"
echo.
echo [WARNING] Option 1 selected: ALL Kiosk settings, user profiles, browser data,
echo and local database volumes will be permanently wiped!
set "CONFIRM_WIPE="
set /p CONFIRM_WIPE="Type YES to confirm full automatic wipe: "
if /i not "!CONFIRM_WIPE!"=="YES" (
echo Uninstall cancelled.
pause
exit /b 0
)
) else if not "%UNINSTALL_MODE%"=="2" (
echo [ERROR] Invalid selection. Exiting.
pause
exit /b 1
)
:: ============================================================================
:: 1. DETECT CURRENT KIOSK ACCOUNT & DISABLE AUTO-LOGON
:: ============================================================================
echo.
echo [1/5] Disabling Windows Auto-Logon and Edge Kiosk policies...
set "KIOSK_USER="
for /f "tokens=2*" %%A in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v "DefaultUserName" 2^>nul') do set "KIOSK_USER=%%B"
set "WINLOGON_KEY=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
reg add "%WINLOGON_KEY%" /v "AutoAdminLogon" /t REG_SZ /d "0" /f >nul 2>&1
reg delete "%WINLOGON_KEY%" /v "DefaultPassword" /f >nul 2>&1
reg delete "%WINLOGON_KEY%" /v "AutoLogonCount" /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
set "EDGE_POL=HKLM\SOFTWARE\Policies\Microsoft\Edge"
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 "RestoreOnStartup" /f >nul 2>&1
:: ============================================================================
:: 2. REMOVE OR RESTORE DEDICATED KIOSK USER ACCOUNT
:: ============================================================================
echo [2/5] Handling dedicated Kiosk user account...
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 "DEL_USER=Y"
if "%AUTO_WIPE%"=="0" (
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;" ^
" $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]=2; Set-ItemProperty -Path $stuckPath -Name Settings -Value $v }" ^
" }" ^
" if ($loaded) { [gc]::Collect(); Start-Sleep 1; reg.exe unload \"HKU\$sid\" >$null 2>&1 }" ^
" }" ^
"}"
echo - Restored normal Windows Desktop shell and taskbar for "%KIOSK_USER%".
)
goto :AFTER_KIOSK_USER
:NO_KIOSK_USER
echo - No separate Kiosk user account needed removal.
:AFTER_KIOSK_USER
:: ============================================================================
:: 3. REMOVE SCHEDULED TASKS AND KIOSK LOCAL FILES
:: ============================================================================
echo [3/5] Removing scheduled tasks and local Kiosk app files...
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
if exist "%KIOSK_APP_DIR%" rmdir /s /q "%KIOSK_APP_DIR%" >nul 2>&1
if exist "%KIOSK_DATA_DIR%" (
set "DEL_BROWSER=Y"
if "%AUTO_WIPE%"=="0" (
set /p DEL_BROWSER="Delete persistent Kiosk browser data at %KIOSK_DATA_DIR%? (Y/N): "
)
if /i "!DEL_BROWSER!"=="Y" (
rmdir /s /q "%KIOSK_DATA_DIR%" >nul 2>&1
echo - Removed %KIOSK_DATA_DIR%
) else (
echo - Preserved %KIOSK_DATA_DIR%
)
)
:: ============================================================================
:: 4. RESTORE DEFAULT WINDOWS POWER PLAN AND UPDATE POLICIES
:: ============================================================================
echo [4/5] Restoring default Balanced Power Plan and Windows Update settings...
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 "%AUTO_WIPE%"=="1" if exist "%USERPROFILE%\.wslconfig" del /f /q "%USERPROFILE%\.wslconfig" >nul 2>&1 & echo - Removed custom .wslconfig.
:: ============================================================================
:: 5. STOP AND REMOVE WALMART DOCKER CONTAINERS
:: ============================================================================
echo [5/5] Checking WSL Docker containers...
wsl -d %WSL_DISTRO% -u root true >nul 2>&1
if %errorLevel% neq 0 goto :UNINSTALL_DONE
set "STOP_DOCKER=Y"
if "%AUTO_WIPE%"=="0" (
set /p STOP_DOCKER="Stop and remove Walmart Docker containers in %PROJECT_DIR%? (Y/N): "
)
if /i not "%STOP_DOCKER%"=="Y" goto :UNINSTALL_DONE
set "DEL_VOLUMES=Y"
if "%AUTO_WIPE%"=="0" (
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 -p '%PROJECT_NAME%' down -v --remove-orphans; rm -rf '%PROJECT_DIR%'"
echo - Removed containers, database volumes, and %PROJECT_DIR%.
) else (
wsl -d %WSL_DISTRO% -u root bash -c "cd '%PROJECT_DIR%' 2>/dev/null && docker compose -p '%PROJECT_NAME%' down --remove-orphans"
echo - Stopped and removed containers - database volumes preserved.
)
:UNINSTALL_DONE
set "DEL_SETUP_DIR=N"
if /i "%ROOT_FOLDER_NAME%"=="mini-pc-setup" (
if "%AUTO_WIPE%"=="1" (
set "DEL_SETUP_DIR=Y"
) else (
set /p DEL_SETUP_DIR="Delete setup folder '%CLEAN_ROOT%' only? (Y/N): "
)
) else (
echo [INFO] Skipping setup folder deletion because parent folder is '%ROOT_FOLDER_NAME%' - not 'mini-pc-setup'.
)
echo.
echo ============================================================================
echo UNINSTALL COMPLETED!
echo - Windows Auto-Logon and Kiosk restrictions have been removed
echo - Normal Windows Desktop and Power/Update policies restored
echo ============================================================================
echo.
set "REBOOT_NOW="
set /p REBOOT_NOW="Reboot now to apply all changes cleanly? (Y/N): "
if /i "%DEL_SETUP_DIR%"=="Y" (
echo Cleaning up '%CLEAN_ROOT%' in 2 seconds - other folders in parent directory remain untouched...
cd /d "%TEMP%"
if /i "%REBOOT_NOW%"=="Y" (
start "" /b cmd /c "timeout /t 2 /nobreak >nul & rmdir /s /q "%CLEAN_ROOT%" & shutdown /r /t 2"
) else (
start "" /b cmd /c "timeout /t 2 /nobreak >nul & rmdir /s /q "%CLEAN_ROOT%""
)
exit /b 0
)
if /i "%REBOOT_NOW%"=="Y" shutdown /r /t 3
pause
-26
View File
@@ -1,26 +0,0 @@
@echo off
echo ============================================
echo Updating Walmart containers...
echo ============================================
echo [1/4] Update config...
wsl -d Ubuntu-22.04 bash -c "cp /mnt/c/Apps/mini-pc-setup/compose.yml ~/walmart/"
wsl -d Ubuntu-22.04 bash -c "cp /mnt/c/Apps/mini-pc-setup/.env ~/walmart/"
echo [2/4] Pull latest images...
wsl -d Ubuntu-22.04 bash -c "cd ~/walmart && sudo docker compose pull"
echo [3/4] Restart containers...
wsl -d Ubuntu-22.04 bash -c "cd ~/walmart && sudo docker compose up -d"
echo [4/4] Remove unused images...
wsl -d Ubuntu-22.04 bash -c "sudo docker image prune -af"
pause
echo.
echo ============================================
echo Walmart update completed!
echo ============================================
pause
+158
View File
@@ -0,0 +1,158 @@
@echo off
setlocal EnableDelayedExpansion
:: ============================================================================
:: CONFIGURATION (SYNCED WITH INSTALL.BAT & UNINSTALL.BAT)
:: ============================================================================
set "SCRIPT_DIR=%~dp0"
for %%I in ("%SCRIPT_DIR%..") do set "ROOT_DIR=%%~fI\"
set "CLEAN_ROOT=%ROOT_DIR:~0,-1%"
:: WSL2 & Project Settings
set "WSL_DISTRO=Ubuntu-22.04"
set "PROJECT_NAME=walmart"
set "PROJECT_DIR=/opt/walmart"
set "REGISTRY_URL=gitea.digitoolsolutions.synology.me"
:: Health-Check Polling Settings
set "HEALTH_PORT=3000"
set "HEALTH_PATH=/api/v1/system/health-check/"
set "HEALTH_INTERVAL=30"
set "HEALTH_MAX_RETRIES=10"
:: Kiosk Local Assets
set "KIOSK_APP_DIR=C:\KioskApp"
:: ============================================================================
:: 0. AUTO-ELEVATE TO ADMINISTRATOR
:: ============================================================================
net session >nul 2>&1
if %errorLevel% neq 0 (
echo Requesting Administrator privileges...
powershell -NoProfile -Command "Start-Process -FilePath '%~f0' -Verb RunAs"
exit /b
)
echo ============================================================================
echo DTS TORQUE VAULT - PRODUCTION UPDATE MANAGER (ZERO-BASE64 EDITION)
echo ============================================================================
echo.
:: ============================================================================
:: 1. PRE-FLIGHT CHECK: WSL, NETWORK & SOURCE FILES
:: ============================================================================
echo [1/4] Verifying WSL2 environment, Internet connection, and config files...
wsl -d %WSL_DISTRO% -u root true >nul 2>&1
if %errorLevel% neq 0 (
echo [ERROR] %WSL_DISTRO% is not installed or not running. Run install.bat first!
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
exit /b 1
)
ping -n 1 8.8.8.8 >nul 2>&1
if %errorLevel% neq 0 (
echo [ERROR] No Internet connection detected! Connect LAN/Wi-Fi and run again.
pause
exit /b 1
)
:: ============================================================================
:: 2. SYNC KIOSK STARTUP TEMPLATE & AUTHENTICATE REGISTRY
:: ============================================================================
echo [2/4] Updating Kiosk startup screen and checking Docker registry login...
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 2>&1
echo - Updated %KIOSK_APP_DIR%\startup.html
)
wsl -d %WSL_DISTRO% -u root docker login %REGISTRY_URL%
if %errorLevel% neq 0 (
echo [ERROR] Docker registry login failed for %REGISTRY_URL%.
pause
exit /b 1
)
:: ============================================================================
:: 3. PULL LATEST IMAGES, RECREATE CONTAINERS & VERIFY HEALTH-CHECK (PORT 3000)
:: ============================================================================
echo [3/4] Pulling latest images, updating containers, and verifying Online status...
for /f "delims=" %%i in ('wsl -d %WSL_DISTRO% -u root wslpath -a "%CLEAN_ROOT%"') do set "WSL_ROOT_DIR=%%i"
set "UPDATE_SH=%TEMP%\dts_update.sh"
> "%UPDATE_SH%" echo set -e
>> "%UPDATE_SH%" echo SRC_DIR="$1"
>> "%UPDATE_SH%" echo PROJ_DIR="$2"
>> "%UPDATE_SH%" echo PROJ_NAME="$3"
>> "%UPDATE_SH%" echo PORT="$4"
>> "%UPDATE_SH%" echo ENDPOINT="$5"
>> "%UPDATE_SH%" echo INTERVAL="$6"
>> "%UPDATE_SH%" echo MAX_RETRIES="$7"
>> "%UPDATE_SH%" echo.
>> "%UPDATE_SH%" echo systemctl is-active --quiet docker ^|^| service docker start
>> "%UPDATE_SH%" echo mkdir -p "$PROJ_DIR"
>> "%UPDATE_SH%" echo cp "$SRC_DIR/compose.yml" "$PROJ_DIR/compose.yml"
>> "%UPDATE_SH%" echo tr -d '\r' ^< "$SRC_DIR/.env" ^> "$PROJ_DIR/.env"
>> "%UPDATE_SH%" echo.
>> "%UPDATE_SH%" echo cd "$PROJ_DIR"
>> "%UPDATE_SH%" echo echo " - Pulling latest container images from registry..."
>> "%UPDATE_SH%" echo docker compose -p "$PROJ_NAME" pull
>> "%UPDATE_SH%" echo echo " - Recreating updated containers (preserving database volumes)..."
>> "%UPDATE_SH%" echo docker compose -p "$PROJ_NAME" up -d --remove-orphans
>> "%UPDATE_SH%" echo.
>> "%UPDATE_SH%" echo echo " - Polling http://localhost:${PORT}${ENDPOINT} every ${INTERVAL}s (max ${MAX_RETRIES} attempts)..."
>> "%UPDATE_SH%" echo for i in $(seq 1 "$MAX_RETRIES"); do
>> "%UPDATE_SH%" echo RES=$(curl -kfsS --max-time 3 "http://localhost:${PORT}${ENDPOINT}" 2^>/dev/null ^|^| true)
>> "%UPDATE_SH%" echo if echo "$RES" ^| grep -qi "Online"; then
>> "%UPDATE_SH%" echo echo " - Update verified: Server is Online and database migrations are complete!"
>> "%UPDATE_SH%" echo exit 0
>> "%UPDATE_SH%" echo fi
>> "%UPDATE_SH%" echo echo " - Attempt $i/$MAX_RETRIES: Server is still restarting/migrating, retrying in ${INTERVAL}s..."
>> "%UPDATE_SH%" echo sleep "$INTERVAL"
>> "%UPDATE_SH%" echo done
>> "%UPDATE_SH%" echo echo " - [ERROR] Timed out waiting for Server on port $PORT to become Online!"
>> "%UPDATE_SH%" echo exit 1
for /f "delims=" %%i in ('wsl -d %WSL_DISTRO% -u root wslpath -a "%UPDATE_SH%"') do set "WSL_UPDATE_SH=%%i"
wsl -d %WSL_DISTRO% -u root bash -c "tr -d '\r' < '%WSL_UPDATE_SH%' > /tmp/dts_update.sh && bash /tmp/dts_update.sh '%WSL_ROOT_DIR%' '%PROJECT_DIR%' '%PROJECT_NAME%' '%HEALTH_PORT%' '%HEALTH_PATH%' '%HEALTH_INTERVAL%' '%HEALTH_MAX_RETRIES%'; RC=$?; rm -f /tmp/dts_update.sh; exit $RC"
set "UPDATE_ERR=%errorLevel%"
del /f /q "%UPDATE_SH%" >nul 2>&1
if %UPDATE_ERR% neq 0 (
echo [ERROR] Update or server health-check failed!
echo Inspect backend logs with: wsl -d %WSL_DISTRO% -u root docker logs tv-backend-prod
pause
exit /b 1
)
:: ============================================================================
:: 4. CLEAN UP DANGLING DOCKER IMAGES & SHOW CONTAINER STATUS
:: ============================================================================
echo [4/4] Cleaning up unused old Docker images and checking container status...
wsl -d %WSL_DISTRO% -u root bash -c "docker image prune -f >/dev/null 2>&1 && cd '%PROJECT_DIR%' && docker compose -p '%PROJECT_NAME%' ps"
echo.
echo ============================================================================
echo UPDATE COMPLETED SUCCESSFULLY!
echo - Project / Directory : %PROJECT_NAME% (%PROJECT_DIR%)
echo - Backend Health : Verified Online on Port %HEALTH_PORT%
echo - Database Volumes : Preserved safely
echo ============================================================================
echo.
pause
+69
View File
@@ -0,0 +1,69 @@
@echo off
setlocal EnableDelayedExpansion
:: ============================================================================
:: CONFIGURATION
:: ============================================================================
set "GITEA_URL=https://gitea.digitoolsolutions.synology.me"
set "REPO_OWNER=lamtruong28"
set "REPO_NAME=mini-pc-setup"
set "EXTRACT_DIR=C:\Apps\%REPO_NAME%"
:: ============================================================================
:: 0. AUTO-ELEVATE TO ADMINISTRATOR
:: ============================================================================
net session >nul 2>&1
if %errorLevel% neq 0 (
echo Requesting Administrator privileges...
powershell -NoProfile -Command "Start-Process -FilePath '%~f0' -Verb RunAs"
exit /b
)
echo ============================================================================
echo DTS TORQUE VAULT - ONE-CLICK LATEST RELEASE BOOTSTRAPPER
echo ============================================================================
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 "$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
)
:: ============================================================================
:: 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 "$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 %EXTRACT_DIR%!
pause
exit /b 1
)
call "%EXTRACT_DIR%\scripts\install.bat"
@@ -10,6 +10,15 @@
box-sizing: border-box; box-sizing: border-box;
} }
html,
body {
overscroll-behavior-x: none;
touch-action: pan-y;
-ms-content-zooming: none;
user-select: none;
-webkit-user-select: none;
}
body { body {
display: flex; display: flex;
justify-content: center; justify-content: center;
@@ -45,7 +54,7 @@
#000 calc(100% - 12px) #000 calc(100% - 12px)
); );
border-radius: 50%; border-radius: 50%;
animation: spin 3s infinite ease-in-out; animation: spin 5s infinite ease-in-out;
} }
.loader::before, .loader::before,
.loader::after { .loader::after {
@@ -79,7 +88,7 @@
right/calc(200% + 1ch) 100%; right/calc(200% + 1ch) 100%;
-webkit-background-clip: text; -webkit-background-clip: text;
background-clip: text; background-clip: text;
animation: l7 3s infinite steps(100); animation: l7 5s infinite steps(100);
} }
.loader-text:before { .loader-text:before {
content: "Loading..."; content: "Loading...";
@@ -102,17 +111,29 @@
</main> </main>
<script> <script>
const HEALTH_URL = "http://localhost:3000/api/v1/system/health-check/";
const FE_URL = "http://localhost:3000/";
async function checkBackend() { async function checkBackend() {
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 2500);
try { try {
const res = await fetch( const res = await fetch(`${HEALTH_URL}?t=${Date.now()}`, {
"http://localhost:3000/api/v1/health-check/", signal: controller.signal,
{ mode: "no-cors" }, });
); clearTimeout(timeoutId);
window.location.href = "http://localhost:3000/"; if (res.ok) {
window.location.replace(FE_URL);
return;
}
} catch (e) { } catch (e) {
setTimeout(checkBackend, 3000); clearTimeout(timeoutId);
} }
setTimeout(checkBackend, 2000);
} }
setTimeout(checkBackend, 1000); setTimeout(checkBackend, 1000);
</script> </script>
</body> </body>