diff --git a/install/local/install-scrypted-dependencies-win.ps1 b/install/local/install-scrypted-dependencies-win.ps1 index cc31b86b53..4ab0234b15 100644 --- a/install/local/install-scrypted-dependencies-win.ps1 +++ b/install/local/install-scrypted-dependencies-win.ps1 @@ -1,3 +1,5 @@ +#Requires -RunAsAdministrator + # Set-PSDebug -Trace 1 # stop existing service if any @@ -22,11 +24,16 @@ $SCRYPTED_WINDOWS_PYTHON_VERSION="-3.9" # Refresh environment variables for py and npx to work $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") +# Workaround Windows Node no longer creating %APPDATA%\npm which causes npx to fail +# Fixed in newer versions of NPM but not the one bundled with 20.11.1 +# https://github.com/nodejs/node/issues/53538 +npm i -g npm py $SCRYPTED_WINDOWS_PYTHON_VERSION -m pip install --upgrade pip py $SCRYPTED_WINDOWS_PYTHON_VERSION -m pip install debugpy typing_extensions typing opencv-python $SCRYPTED_INSTALL_VERSION=[System.Environment]::GetEnvironmentVariable("SCRYPTED_INSTALL_VERSION","User") + if ($SCRYPTED_INSTALL_VERSION -eq $null) { npx -y scrypted@latest install-server } else { @@ -41,6 +48,8 @@ npm install --prefix $SCRYPTED_HOME @koush/node-windows --save $NPX_PATH = (Get-Command npx).Path # The path needs double quotes to handle spaces in the directory path $NPX_PATH_ESCAPED = '"' + $NPX_PATH.replace('\', '\\') + '"' +# On newer versions of NPM, the NPX might be a .ps1 file which doesn't work with child_process.spawn, change to .cmd +$NPX_PATH_ESCAPED = $NPX_PATH_ESCAPED.replace('.ps1', '.cmd') $SERVICE_JS = @" const fs = require('fs'); @@ -54,6 +63,8 @@ child_process.spawn('$NPX_PATH_ESCAPED', ['-y', 'scrypted', 'serve'], { stdio: 'inherit', // allow spawning .cmd https://nodejs.org/en/blog/vulnerability/april-2024-security-releases-2 shell: true, +}).on('error', (err) => { + console.error('Error spawning child process', err); }); "@ @@ -99,6 +110,9 @@ svc.on("install", () => { svc.on("start", () => { console.log("Service started"); }); +svc.on("error", (err) => { + console.log("Service error", err); +}); svc.install(); "@