Files
Campus-25/server/UploadWebsite.bat
2026-10-14 06:59:51 +02:00

75 lines
2.9 KiB
Batchfile

@echo off
setlocal EnableDelayedExpansion
title Campus - upload website only
REM ============================================================================
REM Ships ONLY the public website (Server\...\Website\) to the VPS. No build, no
REM restart: Kestrel serves these files straight off disk, so the new pages are
REM live on the next page load.
REM
REM What it does:
REM 1. copies Website\ to a temp folder
REM 2. cache-busts app.js / data.js / style.css ?v= tags in every .html with a
REM fresh stamp (same trick PackageServer.ps1 uses, so browsers don't keep
REM the old app.js for an hour)
REM 3. pscp -r's it into /opt/campus/Website
REM
REM Use UploadUpdate.bat for C# changes, PackageServer.ps1 when Data\ changes.
REM ============================================================================
set "ROOT=%~dp0"
set "SITE=%ROOT%Server\2025-RecRoom-Server-E12354-main\Website"
set "OUT=%TEMP%\campus-siteupload"
set "VPS=root@50.114.179.17"
set "REMOTE=/opt/campus"
echo.
echo === Campus website deploy (no restart) ====================================
echo.
for %%T in (pscp.exe plink.exe powershell.exe) do (
where %%T >nul 2>&1 || (echo [x] %%T is not on PATH. & goto :fail)
)
if not exist "%SITE%\index.html" (echo [x] Cannot find %SITE% & goto :fail)
if not exist "%ROOT%Password.txt" (echo [x] Cannot find %ROOT%Password.txt & goto :fail)
set "PW="
for /f "usebackq delims=" %%p in ("%ROOT%Password.txt") do if not defined PW set "PW=%%p"
if not defined PW (echo [x] Password.txt is empty. & goto :fail)
REM ---- 1/3 stage -------------------------------------------------------------
echo [1/3] Staging Website\ ...
if exist "%OUT%" rmdir /s /q "%OUT%"
mkdir "%OUT%" >nul 2>&1
xcopy "%SITE%" "%OUT%\" /e /i /q /y >nul
if errorlevel 1 (echo [x] Copy failed. & goto :fail)
REM ---- 2/3 cache-bust --------------------------------------------------------
echo [2/3] Cache-busting script/style tags ...
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
"$tag = Get-Date -Format 'yyyyMMdd-HHmmss'; $n = 0;" ^
"Get-ChildItem '%OUT%' -Filter *.html -Recurse | ForEach-Object {" ^
" $h = [IO.File]::ReadAllText($_.FullName);" ^
" $new = [regex]::Replace($h, '((?:app|data)\.js|style\.css)\?v=[A-Za-z0-9._-]+', ('$1?v=' + $tag));" ^
" if ($new -ne $h) { [IO.File]::WriteAllText($_.FullName, $new, [Text.UTF8Encoding]::new($false)); $n++ } };" ^
"Write-Host (' bumped ' + $n + ' page(s) to v=' + $tag)"
REM ---- 3/3 upload ------------------------------------------------------------
echo [3/3] Uploading to %VPS%:%REMOTE%/Website ...
plink -batch -pw %PW% %VPS% "mkdir -p %REMOTE%/Website"
pscp -batch -r -pw %PW% "%OUT%\*" "%VPS%:%REMOTE%/Website/"
if errorlevel 1 (echo. & echo [x] Upload FAILED. & goto :fail)
echo.
echo === DONE - the site is live, no restart needed. Hard-refresh if a page looks stale.
echo.
pause
exit /b 0
:fail
echo.
echo === FAILED.
echo.
pause
exit /b 1