Skip to content

Commit

Permalink
Update Windows install script workaround npm issue (#1654)
Browse files Browse the repository at this point in the history
* Update Windows install script workaround npm issue

* Test removing RunAsAdministrator

* Revert "Test removing RunAsAdministrator"

This reverts commit 46c8096.

* Test removing npm fix

* Revert "Test removing npm fix"

This reverts commit 0f9adbe.

* Test dump daemon logs

* More test

* More tests

* More tests

* Test

* Test

* Test

* Test

* Cleanup

* Add spawn error handler

* Fix event handler

* Remove node version debug
  • Loading branch information
longzheng authored Dec 6, 2024
1 parent 3162d2b commit a7424b3
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions install/local/install-scrypted-dependencies-win.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#Requires -RunAsAdministrator

# Set-PSDebug -Trace 1

# stop existing service if any
Expand All @@ -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 {
Expand All @@ -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');
Expand All @@ -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);
});
"@

Expand Down Expand Up @@ -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();
"@

Expand Down

0 comments on commit a7424b3

Please sign in to comment.