@remoteshell/device 0.1.0-beta.1 → 0.1.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +26 -0
- package/NOTICE +20 -0
- package/bin/dev-agent-client.mjs +228 -0
- package/bin/dev-agent-runner.mjs +60 -0
- package/bin/dev-api-client.mjs +31 -0
- package/bin/dev-auto-worker.mjs +25 -0
- package/bin/dev-browser-open.mjs +12 -0
- package/bin/dev-dogfood-read.mjs +3 -0
- package/bin/dev-heartbeat-service.mjs +77 -0
- package/bin/dev-pairing-client.mjs +63 -0
- package/bin/dev-secrets.mjs +33 -0
- package/bin/dev-setup-recovery.mjs +34 -0
- package/bin/dev-signer-pin.mjs +22 -0
- package/bin/device.mjs +254 -9
- package/bin/direct-npx-runtime.mjs +150 -0
- package/bin/install-acquire.mjs +89 -0
- package/bin/install-integrity.mjs +74 -0
- package/bin/install-plan.mjs +43 -0
- package/bin/native-path-contract.mjs +23 -0
- package/bin/remoteshell-device-install.cmd +17 -0
- package/bin/remoteshell-device-install.ps1 +17 -0
- package/bin/remoteshell-device-install.sh +15 -0
- package/bin/remoteshell-device-preflight.cmd +10 -0
- package/bin/remoteshell-device-preflight.ps1 +10 -0
- package/bin/remoteshell-easy-diagnose.ps1 +32 -0
- package/bin/remoteshell-easy-install.ps1 +292 -0
- package/bin/remoteshell-easy-install.sh +71 -0
- package/bin/remoteshell-easy-uninstall.ps1 +128 -0
- package/bin/windows-acl-wmi-client.mjs +50 -0
- package/bin/windows-acl-wmi.js +43 -0
- package/bin/windows-credential-boundary.mjs +113 -0
- package/bin/windows-direct-autostart-runner.mjs +50 -0
- package/bin/windows-direct-autostart.mjs +110 -0
- package/bin/windows-install-layout.mjs +28 -0
- package/bin/windows-native-installer.mjs +91 -0
- package/bin/windows-private-store.mjs +176 -0
- package/bin/windows-user-lifecycle.mjs +34 -0
- package/npm-shrinkwrap.json +8591 -0
- package/package.json +14 -5
- package/shared/lib/bounded-search-contract.mjs +5 -0
- package/shared/lib/dc-generic-policy.mjs +102 -0
- package/shared/lib/dc-relay-contract.mjs +42 -0
- package/shared/lib/dc-tool-catalog.mjs +67 -0
- package/shared/lib/dev-dc-relay-contract.mjs +20 -0
- package/shared/lib/dev-paged-output.mjs +32 -0
- package/shared/lib/dev-root-exclusions.mjs +56 -0
- package/{src/common → shared/lib}/synthetic-write-policy.mjs +0 -1
- package/src/config/l2-dev-oci-credential.mjs +39 -0
- package/src/config/p2-private-credential.mjs +15 -0
- package/src/connection/dev-dogfood-processes.mjs +25 -0
- package/src/connection/dev-dogfood-read.mjs +64 -0
- package/src/connection/dev-dogfood-task.mjs +113 -0
- package/src/connection/dev-dogfood-write.mjs +62 -0
- package/src/connection/dev-file-task.mjs +119 -0
- package/src/connection/dev-r4-file-task.mjs +56 -0
- package/src/connection/dev-read-tools.mjs +134 -0
- package/src/connection/dev-root-scopes.mjs +82 -0
- package/src/{device-agent → core}/c1-supervisor.mjs +9 -7
- package/src/{device-agent → core}/c1-worker.mjs +7 -7
- package/src/dc/dc-access-readiness.mjs +31 -0
- package/src/dc/dev-dc-relay.mjs +47 -0
- package/src/device-agent/main.mjs +1 -230
- package/src/gateway-keepalive.mjs +73 -0
- package/src/main.mjs +436 -0
- package/src/{common → policy}/bounded-search-adapter.mjs +2 -3
- package/src/{common → policy}/isolated-read-adapter.mjs +1 -1
- package/src/{common → policy}/isolated-read-mount.mjs +1 -1
- package/src/{common → policy}/synthetic-auxiliary-adapter.mjs +1 -1
- package/src/{common → policy}/synthetic-file-adapter.mjs +1 -1
- package/src/{common → policy}/synthetic-file-transaction.mjs +1 -1
- package/src/{common → policy}/synthetic-write-adapter.mjs +2 -3
- /package/{src/common → shared/lib}/bounded-search-policy.mjs +0 -0
- /package/{src/common → shared/lib}/config.mjs +0 -0
- /package/{src/common → shared/lib}/contracts.mjs +0 -0
- /package/{src/common → shared/lib}/errors.mjs +0 -0
- /package/{src/common → shared/lib}/events.mjs +0 -0
- /package/{src/common → shared/lib}/execution-policy.mjs +0 -0
- /package/{src/common → shared/lib}/isolated-read-boundary.mjs +0 -0
- /package/{src/common → shared/lib}/isolated-read-policy.mjs +0 -0
- /package/{src/common → shared/lib}/lifecycle-events.mjs +0 -0
- /package/{src/common → shared/lib}/runtime-timing.mjs +0 -0
- /package/{src/common → shared/lib}/synthetic-auxiliary-policy.mjs +0 -0
- /package/{src/common → shared/lib}/tool-registry.mjs +0 -0
- /package/src/{device-agent → core}/c1-dc-transport.mjs +0 -0
- /package/src/{device-agent → core}/c1-startup.mjs +0 -0
- /package/src/{device-agent → core}/fixture.txt +0 -0
- /package/src/{common → policy}/synthetic-write-mount.mjs +0 -0
- /package/src/{common → policy}/verified-bounded-search.mjs +0 -0
- /package/src/{common → policy}/verified-isolated-read.mjs +0 -0
- /package/src/{common → policy}/verified-synthetic-write.mjs +0 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// #310 Shared, non-executing installation decision. Both OS entrypoints must
|
|
2
|
+
// consume one verified artifact; this module never runs it or changes credentials.
|
|
3
|
+
import {verifySignedInstallArchive} from './install-integrity.mjs';
|
|
4
|
+
const fail=code=>{throw Error(code);};
|
|
5
|
+
function semver(value){
|
|
6
|
+
if(typeof value!=='string'||!/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(value))
|
|
7
|
+
fail('DEVICE_INSTALL_VERSION_DENIED');
|
|
8
|
+
return value.split('-')[0].split('.').map(Number);
|
|
9
|
+
}
|
|
10
|
+
function compare(a,b){
|
|
11
|
+
const av=semver(a),bv=semver(b);
|
|
12
|
+
for(let i=0;i<3;i++){if(av[i]>bv[i])return 1;if(av[i]<bv[i])return -1;}
|
|
13
|
+
// Never infer prerelease ordering or treat a prerelease as a final release.
|
|
14
|
+
if(a===b)return 0;
|
|
15
|
+
fail('DEVICE_INSTALL_VERSION_REVIEW_REQUIRED');
|
|
16
|
+
}
|
|
17
|
+
export function planVerifiedInstall({
|
|
18
|
+
artifactPath,manifest,trustedKeys,os,arch,nodeVersion,wsl=false,
|
|
19
|
+
installedVersion=null,existingCredentials=false,existingService=false,
|
|
20
|
+
consent=false
|
|
21
|
+
}={}){
|
|
22
|
+
// Validate before making a version or installation decision, even on no-op.
|
|
23
|
+
const verified=verifySignedInstallArchive({
|
|
24
|
+
artifactPath,manifest,trustedKeys,os,arch,nodeVersion,wsl
|
|
25
|
+
});
|
|
26
|
+
if(typeof existingCredentials!=='boolean'||typeof existingService!=='boolean'||
|
|
27
|
+
typeof consent!=='boolean')fail('DEVICE_INSTALL_STATE_DENIED');
|
|
28
|
+
const result=installedVersion===null?'fresh':
|
|
29
|
+
compare(verified.version,installedVersion)===0?'already-installed':
|
|
30
|
+
compare(verified.version,installedVersion)>0?'upgrade':'downgrade';
|
|
31
|
+
if(result==='downgrade')fail('DEVICE_INSTALL_DOWNGRADE_DENIED');
|
|
32
|
+
if(existingService&&installedVersion===null)fail('DEVICE_INSTALL_STATE_DENIED');
|
|
33
|
+
return Object.freeze({
|
|
34
|
+
verified:true,os,arch,version:verified.version,
|
|
35
|
+
signingKeyFingerprint:verified.signingKeyFingerprint,
|
|
36
|
+
artifactSha256:verified.sha256,action:result,
|
|
37
|
+
// Installing, replacing, service enabling and re-enrollment are separate
|
|
38
|
+
// later steps and require an explicit consent/restore plan.
|
|
39
|
+
next:consent?'OS_INSTALL_APPROVAL_REQUIRED':'USER_CONSENT_REQUIRED',
|
|
40
|
+
approvedToExecute:false,installed:false,deviceRegistered:false,
|
|
41
|
+
credentialsPreserved:true,existingCredentials,existingService
|
|
42
|
+
});
|
|
43
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// #310 Windows lexical path boundary for offline planning only. This is NOT
|
|
2
|
+
// proof of NTFS ownership/ACLs, reparse-point freedom, or an approved Root.
|
|
3
|
+
import {win32} from 'node:path';
|
|
4
|
+
const deny=()=>{throw Error('DEVICE_WINDOWS_PATH_DENIED');};
|
|
5
|
+
const reserved=/^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\..*)?$/i;
|
|
6
|
+
export function canonicalWindowsLocalFile(path){
|
|
7
|
+
if(typeof path!=='string'||path.length<4||path.length>1024||!(/^[A-Za-z]:\\/.test(path)))
|
|
8
|
+
deny();
|
|
9
|
+
// Reject UNC, device namespaces, forward slashes, ADS, env interpolation and
|
|
10
|
+
// shell metacharacters before a name can be used in a task argument.
|
|
11
|
+
if(/[\x00-\x1f\x7f"<>|?*\/&^%]/.test(path)||path.slice(2).includes(':'))deny();
|
|
12
|
+
const segments=path.slice(3).split('\\');
|
|
13
|
+
if(segments.length===0||segments.some(x=>!x||x==='.'||x==='..'||/[. ]$/.test(x)||reserved.test(x)))deny();
|
|
14
|
+
const normalized=win32.normalize(path);
|
|
15
|
+
if(normalized!==path)deny(); // no invisible normalization changes
|
|
16
|
+
return path;
|
|
17
|
+
}
|
|
18
|
+
export function isWindowsChildPath(path,root){
|
|
19
|
+
const child=canonicalWindowsLocalFile(path),parent=canonicalWindowsLocalFile(root);
|
|
20
|
+
const rel=win32.relative(parent,child);
|
|
21
|
+
if(!rel||rel==='..'||rel.startsWith('..\\')||win32.isAbsolute(rel))deny();
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
@echo off
|
|
2
|
+
setlocal DisableDelayedExpansion
|
|
3
|
+
rem #310: package-local Windows bootstrap; no network download or privileged task.
|
|
4
|
+
rem Only run from an independently verified private package within this user profile.
|
|
5
|
+
if not "%~1"=="" (
|
|
6
|
+
echo DEVICE_INSTALL_ARGS_DENIED 1>&2
|
|
7
|
+
exit /b 2
|
|
8
|
+
)
|
|
9
|
+
where node >nul 2>nul
|
|
10
|
+
if errorlevel 1 (
|
|
11
|
+
echo DEVICE_INSTALL_NODE_UNSUPPORTED 1>&2
|
|
12
|
+
exit /b 1
|
|
13
|
+
)
|
|
14
|
+
node "%~dp0device.mjs" install-preflight
|
|
15
|
+
if errorlevel 1 exit /b %errorlevel%
|
|
16
|
+
node "%~dp0device.mjs" install
|
|
17
|
+
exit /b %errorlevel%
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# #310: package-local Windows bootstrap. Does not download or elevate.
|
|
2
|
+
# Run only from the verified private package in the current user's profile.
|
|
3
|
+
$ErrorActionPreference = 'Stop'
|
|
4
|
+
if ($args.Count -ne 0) {
|
|
5
|
+
[Console]::Error.WriteLine('DEVICE_INSTALL_ARGS_DENIED')
|
|
6
|
+
exit 2
|
|
7
|
+
}
|
|
8
|
+
$node = Get-Command node -CommandType Application -ErrorAction SilentlyContinue
|
|
9
|
+
if ($null -eq $node) {
|
|
10
|
+
[Console]::Error.WriteLine('DEVICE_INSTALL_NODE_UNSUPPORTED')
|
|
11
|
+
exit 1
|
|
12
|
+
}
|
|
13
|
+
$entry = Join-Path $PSScriptRoot 'device.mjs'
|
|
14
|
+
& $node.Source $entry install-preflight
|
|
15
|
+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
|
16
|
+
& $node.Source $entry install
|
|
17
|
+
exit $LASTEXITCODE
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# #310: package-local Linux bootstrap; never executes downloaded shell text.
|
|
3
|
+
# Download/verify/signature trust must be handled before invoking this script.
|
|
4
|
+
set -eu
|
|
5
|
+
if [ "$#" -ne 0 ]; then
|
|
6
|
+
echo DEVICE_INSTALL_ARGS_DENIED >&2
|
|
7
|
+
exit 2
|
|
8
|
+
fi
|
|
9
|
+
if ! command -v node >/dev/null 2>&1; then
|
|
10
|
+
echo DEVICE_INSTALL_NODE_UNSUPPORTED >&2
|
|
11
|
+
exit 1
|
|
12
|
+
fi
|
|
13
|
+
entry_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P)
|
|
14
|
+
node "$entry_dir/device.mjs" install-preflight
|
|
15
|
+
node "$entry_dir/device.mjs" install
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
@echo off
|
|
2
|
+
setlocal DisableDelayedExpansion
|
|
3
|
+
rem Windows native preflight only. No download, enrollment or service mutation.
|
|
4
|
+
where node >nul 2>nul
|
|
5
|
+
if errorlevel 1 (
|
|
6
|
+
echo DEVICE_INSTALL_NODE_UNSUPPORTED 1>&2
|
|
7
|
+
exit /b 1
|
|
8
|
+
)
|
|
9
|
+
node "%~dp0device.mjs" install-preflight
|
|
10
|
+
exit /b %errorlevel%
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Windows native preflight only. No download, enrollment or service mutation.
|
|
2
|
+
$ErrorActionPreference = 'Stop'
|
|
3
|
+
$node = Get-Command node -CommandType Application -ErrorAction SilentlyContinue
|
|
4
|
+
if ($null -eq $node) {
|
|
5
|
+
[Console]::Error.WriteLine('DEVICE_INSTALL_NODE_UNSUPPORTED')
|
|
6
|
+
exit 1
|
|
7
|
+
}
|
|
8
|
+
$entry = Join-Path $PSScriptRoot 'device.mjs'
|
|
9
|
+
& $node.Source $entry install-preflight
|
|
10
|
+
exit $LASTEXITCODE
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Read-only DEV installer diagnostics. Never output device keys, poll tokens or raw pair.out.
|
|
2
|
+
$ErrorActionPreference='Stop'
|
|
3
|
+
$identity=[Security.Principal.WindowsIdentity]::GetCurrent().Name
|
|
4
|
+
$local=[Environment]::GetFolderPath('LocalApplicationData')
|
|
5
|
+
$root=Join-Path $local 'RemoteShell'
|
|
6
|
+
$logDir=Join-Path $root 'EasyInstall\logs'
|
|
7
|
+
$install=Join-Path $root 'DeviceAgent\install'
|
|
8
|
+
$credentials=Join-Path $root 'DeviceAgent\dev-credentials'
|
|
9
|
+
Write-Output ('DIAG_AT='+((Get-Date).ToString('o')))
|
|
10
|
+
Write-Output ('WINDOWS_USER='+$identity)
|
|
11
|
+
Write-Output ('AGENT_INSTALLED='+(Test-Path -LiteralPath $install))
|
|
12
|
+
Write-Output ('LOCAL_CREDENTIAL_FILE_PRESENT='+(Test-Path -LiteralPath (Join-Path $credentials 'device.json')))
|
|
13
|
+
foreach($n in @('result.txt','pair.err','install.err','stage-agent.err','status.err')) {
|
|
14
|
+
$p=Join-Path $logDir $n
|
|
15
|
+
if(Test-Path -LiteralPath $p -PathType Leaf) {
|
|
16
|
+
Write-Output ('LOG_FILE='+$n)
|
|
17
|
+
foreach($line in (Get-Content -LiteralPath $p -Tail 90)) {
|
|
18
|
+
if($line -match '^(\xFEFF)?(RemoteShell EasyInstall DEV|AGENT_INSTALLED=|PAIR_|RESULT=|USER_|NEXT=|DEVICE_[A-Z0-9_]+$)' -or ($n -ne 'result.txt' -and $line -match '^[A-Z][A-Z0-9_]{4,90}$')) {
|
|
19
|
+
# Only predefined status lines and status codes, never JSON response bodies or URLs.
|
|
20
|
+
$clean=$line -replace 'https?://\S+','[URL]' -replace '(?i)(poll_token|capability|nonce|private_key)=\S+','$1=[REDACTED]'
|
|
21
|
+
Write-Output $clean
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
} else { Write-Output ('LOG_MISSING='+$n) }
|
|
25
|
+
}
|
|
26
|
+
$uninstall=Join-Path $root 'UninstallLogs\easy-uninstall-result.txt'
|
|
27
|
+
if(Test-Path -LiteralPath $uninstall -PathType Leaf) {
|
|
28
|
+
Write-Output 'UNINSTALL_RESULT'
|
|
29
|
+
Get-Content -LiteralPath $uninstall -Tail 25 | Where-Object {$_ -match '^(RemoteShell easy uninstall |AGENT_|USER_|LOCAL_|PRIVATE_|RESULT=)'}
|
|
30
|
+
}
|
|
31
|
+
Write-Output 'NOTE: Browser HTTP status and Google identity are NOT available from Agent logs.'
|
|
32
|
+
Write-Output 'NOTE: Pairing IDs are non-secret request correlations; never share raw pair.out.'
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
# RemoteShell #310 Windows no-prerequisite DEV installer.
|
|
2
|
+
# Requires only built-in Windows PowerShell 5.1. Includes isolated Node runtime.
|
|
3
|
+
param([switch]$CheckOnly,[switch]$SkipPair,[switch]$Background)
|
|
4
|
+
$ErrorActionPreference='Stop'
|
|
5
|
+
$ProgressPreference='SilentlyContinue'
|
|
6
|
+
$source=Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
7
|
+
$manifestFile=Join-Path $source 'manifest.json'
|
|
8
|
+
$phase='VERIFY'
|
|
9
|
+
$reportDir=$null
|
|
10
|
+
function Demand($ok,[string]$reason){if(-not $ok){throw $reason}}
|
|
11
|
+
function Digest($file){return (Get-FileHash -LiteralPath $file -Algorithm SHA256).Hash.ToLowerInvariant()}
|
|
12
|
+
function Step($label,$exe,[string[]]$parameters,[int]$limit=240){
|
|
13
|
+
$out=Join-Path $reportDir ($label+'.out')
|
|
14
|
+
$err=Join-Path $reportDir ($label+'.err')
|
|
15
|
+
$argsText=($parameters | ForEach-Object {if($_ -match '\s') {'"'+($_ -replace '"','')+'"'} else {$_}}) -join ' '
|
|
16
|
+
# In Windows PowerShell 5.1 -PassThru without -Wait can yield null ExitCode.
|
|
17
|
+
$child=Start-Process -FilePath $exe -ArgumentList $argsText -Wait -PassThru -RedirectStandardOutput $out -RedirectStandardError $err
|
|
18
|
+
Demand ($null -ne $child.ExitCode -and $child.ExitCode -eq 0) ($label+'_FAILED_EXIT_'+$child.ExitCode)
|
|
19
|
+
Write-Host ('[PASS] '+$label)
|
|
20
|
+
}
|
|
21
|
+
function StageComplete([string]$root){
|
|
22
|
+
try {
|
|
23
|
+
$agentFile=Join-Path $root 'node_modules\@remoteshell\device\package.json'
|
|
24
|
+
$dcFile=Join-Path $root 'node_modules\@wonderwhy-er\desktop-commander\package.json'
|
|
25
|
+
$sdkFile=Join-Path $root 'node_modules\@modelcontextprotocol\sdk\package.json'
|
|
26
|
+
$cliFile=Join-Path $root 'node_modules\@remoteshell\device\bin\device.mjs'
|
|
27
|
+
foreach($file in @($agentFile,$dcFile,$sdkFile,$cliFile)){
|
|
28
|
+
if(-not (Test-Path -LiteralPath $file -PathType Leaf)){return $false}
|
|
29
|
+
}
|
|
30
|
+
$a=Get-Content -LiteralPath $agentFile -Raw | ConvertFrom-Json
|
|
31
|
+
$d=Get-Content -LiteralPath $dcFile -Raw | ConvertFrom-Json
|
|
32
|
+
$k=Get-Content -LiteralPath $sdkFile -Raw | ConvertFrom-Json
|
|
33
|
+
return ($a.name -eq '@remoteshell/device' -and $a.version -eq $script:agentVersion -and
|
|
34
|
+
$d.version -eq '0.3.1' -and $k.version -eq '1.32.1')
|
|
35
|
+
}catch{return $false}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
function StartRegisteredUserAgent([string]$node,[string]$cli,[string]$log){
|
|
40
|
+
# The login-started Node console must not appear to the Windows user.
|
|
41
|
+
# wscript.exe launches the private Agent with window style 0 (hidden).
|
|
42
|
+
# The stable installed CLI is used, never the temporary staging CLI.
|
|
43
|
+
$phase='USER_WORKER'
|
|
44
|
+
$localPath=[Environment]::GetFolderPath('LocalApplicationData')
|
|
45
|
+
$root=Join-Path $localPath 'RemoteShell'
|
|
46
|
+
$installedCli=Join-Path $root 'DeviceAgent\install\node_modules\@remoteshell\device\bin\device.mjs'
|
|
47
|
+
$launcher=Join-Path $root 'EasyInstall\agent-autostart.vbs'
|
|
48
|
+
$wscript=Join-Path $env:WINDIR 'System32\wscript.exe'
|
|
49
|
+
Demand (Test-Path -LiteralPath $node -PathType Leaf) 'PRIVATE_NODE_MISSING'
|
|
50
|
+
Demand (Test-Path -LiteralPath $installedCli -PathType Leaf) 'INSTALLED_AGENT_CLI_MISSING'
|
|
51
|
+
Demand (Test-Path -LiteralPath $wscript -PathType Leaf) 'WINDOWS_SCRIPT_HOST_MISSING'
|
|
52
|
+
$vb=@(
|
|
53
|
+
'Set fso = CreateObject("Scripting.FileSystemObject")',
|
|
54
|
+
'Set sh = CreateObject("WScript.Shell")',
|
|
55
|
+
'base = fso.GetParentFolderName(WScript.ScriptFullName)',
|
|
56
|
+
'root = fso.GetParentFolderName(base)',
|
|
57
|
+
'node = base & "\runtime-v22\node.exe"',
|
|
58
|
+
'cli = root & "\DeviceAgent\install\node_modules\@remoteshell\device\bin\device.mjs"',
|
|
59
|
+
'sh.Run Chr(34) & node & Chr(34) & " " & Chr(34) & cli & Chr(34) & " dev-heartbeat", 0, False'
|
|
60
|
+
)
|
|
61
|
+
Demand (-not (Test-Path -LiteralPath $launcher)) 'EXISTING_LAUNCHER_REVIEW_REQUIRED'
|
|
62
|
+
Set-Content -LiteralPath $launcher -Value $vb -Encoding Unicode -ErrorAction Stop
|
|
63
|
+
$runKey='HKCU:\Software\Microsoft\Windows\CurrentVersion\Run'
|
|
64
|
+
$runName='RemoteShell-DEV-User-Agent'
|
|
65
|
+
$runValue=('"'+$wscript+'" "'+$launcher+'"')
|
|
66
|
+
$prior=Get-ItemProperty -LiteralPath $runKey -Name $runName -ErrorAction SilentlyContinue
|
|
67
|
+
Demand (-not $prior) 'EXISTING_USER_AUTOSTART_REVIEW_REQUIRED'
|
|
68
|
+
New-ItemProperty -LiteralPath $runKey -Name $runName -Value $runValue -PropertyType String -ErrorAction Stop | Out-Null
|
|
69
|
+
Add-Content -LiteralPath $log -Value 'USER_AUTOSTART=HKCU_RUN_HIDDEN_WSCRIPT' -Encoding UTF8
|
|
70
|
+
$existing=@(Get-CimInstance Win32_Process -Filter "Name='node.exe'" | Where-Object {
|
|
71
|
+
$_.ExecutablePath -ieq $node -and $_.CommandLine -like ('*'+$installedCli+'*dev-heartbeat*')
|
|
72
|
+
})
|
|
73
|
+
Demand ($existing.Count -eq 0) 'DUPLICATE_USER_AGENT_DENIED'
|
|
74
|
+
$child=Start-Process -FilePath $wscript -ArgumentList ('"'+$launcher+'"') -PassThru -WindowStyle Hidden
|
|
75
|
+
Demand ($null -ne $child -and $child.Id -gt 0) 'USER_WORKER_START_FAILED'
|
|
76
|
+
Start-Sleep -Seconds 5
|
|
77
|
+
$live=@(Get-CimInstance Win32_Process -Filter "Name='node.exe'" | Where-Object {
|
|
78
|
+
$_.ExecutablePath -ieq $node -and $_.CommandLine -like ('*'+$installedCli+'*dev-heartbeat*')
|
|
79
|
+
})
|
|
80
|
+
Demand ($live.Count -eq 1) 'USER_WORKER_NOT_RUNNING'
|
|
81
|
+
Add-Content -LiteralPath $log -Value 'USER_WORKER_PROCESS=PASS; GATEWAY_ONLINE_NOT_YET_VERIFIED' -Encoding UTF8
|
|
82
|
+
}
|
|
83
|
+
function IsRegistered([string]$node,[string]$cli){
|
|
84
|
+
$state=& $node $cli status 2>$null
|
|
85
|
+
Demand ($LASTEXITCODE -eq 0) 'REGISTERED_STATUS_FAILED'
|
|
86
|
+
$parsed=($state -join '') | ConvertFrom-Json
|
|
87
|
+
return ($parsed.installed -eq $true -and $parsed.registered -eq $true)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
try{
|
|
91
|
+
Demand (Test-Path -LiteralPath $manifestFile -PathType Leaf) 'MANIFEST_MISSING'
|
|
92
|
+
$manifest=Get-Content -LiteralPath $manifestFile -Raw | ConvertFrom-Json
|
|
93
|
+
Demand ($manifest.schema -eq 1 -and $manifest.platform -eq 'win32' -and $manifest.arch -eq 'x64' -and $manifest.devOnly -eq $true) 'MANIFEST_INVALID'
|
|
94
|
+
# Backward-compatible with older DEV-only Windows bundles; each new bundle pins its public beta explicitly.
|
|
95
|
+
$script:agentVersion=if($manifest.agentVersion){[string]$manifest.agentVersion}else{'0.1.0'}
|
|
96
|
+
Demand ($script:agentVersion -match '^0\.1\.0(-beta\.[1-9][0-9]*)?$') 'AGENT_VERSION_DENIED'
|
|
97
|
+
$paths=@{
|
|
98
|
+
node=(Join-Path $source 'runtime\node.exe');
|
|
99
|
+
npm=(Join-Path $source 'runtime\node_modules\npm\bin\npm-cli.js');
|
|
100
|
+
archive=(Join-Path $source 'agent.tgz')
|
|
101
|
+
}
|
|
102
|
+
foreach($key in @('node','npm','archive')){
|
|
103
|
+
Demand (Test-Path -LiteralPath $paths[$key] -PathType Leaf) ('MISSING_'+$key)
|
|
104
|
+
Demand ((Digest $paths[$key]) -eq $manifest.sha256.$key) ('HASH_MISMATCH_'+$key)
|
|
105
|
+
}
|
|
106
|
+
$who=[Security.Principal.WindowsIdentity]::GetCurrent().Name
|
|
107
|
+
$principal=New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
|
|
108
|
+
Demand (-not $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) 'DO_NOT_RUN_AS_ADMIN'
|
|
109
|
+
Demand ([Environment]::Is64BitOperatingSystem) 'WINDOWS_X64_REQUIRED'
|
|
110
|
+
$homePath=[Environment]::GetFolderPath('UserProfile')
|
|
111
|
+
$localPath=[Environment]::GetFolderPath('LocalApplicationData')
|
|
112
|
+
Demand ($homePath -and $localPath -and (Test-Path -LiteralPath $localPath)) 'WINDOWS_PROFILE_MISSING'
|
|
113
|
+
Demand ($localPath -ieq (Join-Path $homePath 'AppData\Local')) 'FOREIGN_PROFILE_DENIED'
|
|
114
|
+
$agentInstall=Join-Path $localPath 'RemoteShell\DeviceAgent\install'
|
|
115
|
+
$oldCredentials=Join-Path $localPath 'RemoteShell\DeviceAgent\dev-credentials'
|
|
116
|
+
$resume=(Test-Path -LiteralPath $agentInstall -PathType Container)
|
|
117
|
+
if($resume){
|
|
118
|
+
Demand (-not $SkipPair) 'EXISTING_AGENT_PRESERVED'
|
|
119
|
+
# A failed/expired pairing is not a reason to reinstall or overwrite keys.
|
|
120
|
+
# Resume only a fully staged, currently unregistered installation.
|
|
121
|
+
$privateRuntime=Join-Path $localPath 'RemoteShell\EasyInstall\runtime-v22'
|
|
122
|
+
$node=Join-Path $privateRuntime 'node.exe'
|
|
123
|
+
$cli=Join-Path $agentInstall 'node_modules\@remoteshell\device\bin\device.mjs'
|
|
124
|
+
Demand (StageComplete $agentInstall) 'EXISTING_AGENT_INCOMPLETE_REVIEW_REQUIRED'
|
|
125
|
+
Demand (Test-Path -LiteralPath $node -PathType Leaf) 'EXISTING_PRIVATE_RUNTIME_MISSING'
|
|
126
|
+
Demand ((Digest $node) -eq $manifest.sha256.node) 'EXISTING_PRIVATE_RUNTIME_HASH_DENIED'
|
|
127
|
+
Demand (-not (IsRegistered $node $cli)) 'EXISTING_AGENT_ALREADY_REGISTERED'
|
|
128
|
+
$live=@(Get-CimInstance Win32_Process -Filter "Name='node.exe'" | Where-Object {
|
|
129
|
+
$_.ExecutablePath -ieq $node -and $_.CommandLine -like ('*'+$cli+'*')
|
|
130
|
+
})
|
|
131
|
+
Demand ($live.Count -eq 0) 'EXISTING_AGENT_PROCESS_REVIEW_REQUIRED'
|
|
132
|
+
}else{
|
|
133
|
+
# A new install must not consume leftovers from a prior registration.
|
|
134
|
+
Demand (-not (Test-Path -LiteralPath $oldCredentials)) 'PREVIOUS_DEVICE_REGISTRATION_MUST_BE_REMOVED'
|
|
135
|
+
}
|
|
136
|
+
$version=& $paths.node '--version'
|
|
137
|
+
Demand ($LASTEXITCODE -eq 0 -and $version -match '^v22\.') 'BUNDLED_NODE_VERSION_DENIED'
|
|
138
|
+
if($CheckOnly){
|
|
139
|
+
Write-Host ('EASY_INSTALL_CHECK_PASS '+$version+' '+$who)
|
|
140
|
+
exit 0
|
|
141
|
+
}
|
|
142
|
+
$reportDir=Join-Path $localPath 'RemoteShell\EasyInstall\logs'
|
|
143
|
+
if(-not(Test-Path -LiteralPath $reportDir)){New-Item -ItemType Directory -Path $reportDir -Force|Out-Null}
|
|
144
|
+
$log=Join-Path $reportDir 'result.txt'
|
|
145
|
+
# Preserve prior status/error codes only; pair.out can carry private enrollment
|
|
146
|
+
# material and must never be backed up into a new distributable or shared path.
|
|
147
|
+
$priorLog=Join-Path $reportDir 'result.txt'
|
|
148
|
+
if(Test-Path -LiteralPath $priorLog -PathType Leaf){
|
|
149
|
+
$history=Join-Path $reportDir 'history'
|
|
150
|
+
if(-not(Test-Path -LiteralPath $history)){New-Item -ItemType Directory -Path $history -Force|Out-Null}
|
|
151
|
+
$stamp=Get-Date -Format 'yyyyMMdd-HHmmss-fff'
|
|
152
|
+
Copy-Item -LiteralPath $priorLog -Destination (Join-Path $history ('result-'+$stamp+'.txt')) -ErrorAction Stop
|
|
153
|
+
$priorError=Join-Path $reportDir 'pair.err'
|
|
154
|
+
if(Test-Path -LiteralPath $priorError -PathType Leaf){
|
|
155
|
+
# Raw stderr may be untrusted; preserve only known uppercase error codes.
|
|
156
|
+
Get-Content -LiteralPath $priorError | Where-Object {$_ -match '^DEVICE_[A-Z0-9_]+$'} |
|
|
157
|
+
Set-Content -LiteralPath (Join-Path $history ('pair-error-'+$stamp+'.txt')) -Encoding UTF8
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
Set-Content -LiteralPath $log -Value ('RemoteShell EasyInstall DEV '+(Get-Date -Format o)+' user='+$who) -Encoding UTF8
|
|
161
|
+
if($resume){
|
|
162
|
+
$phase='RESUME_PAIR'
|
|
163
|
+
Add-Content -LiteralPath $log -Value 'INSTALL_RESUME=PAIR_ONLY; PACKAGE_PRESERVED=true' -Encoding UTF8
|
|
164
|
+
Write-Host '[PASS] previously installed Agent verified; resuming Google approval only'
|
|
165
|
+
}else{
|
|
166
|
+
$phase='COPY_RUNTIME'
|
|
167
|
+
$privateRuntime=Join-Path $localPath 'RemoteShell\EasyInstall\runtime-v22'
|
|
168
|
+
if(-not(Test-Path -LiteralPath $privateRuntime)){
|
|
169
|
+
New-Item -ItemType Directory -Path $privateRuntime -Force|Out-Null
|
|
170
|
+
Copy-Item -LiteralPath (Join-Path $source 'runtime\node.exe') -Destination (Join-Path $privateRuntime 'node.exe')
|
|
171
|
+
New-Item -ItemType Directory -Path (Join-Path $privateRuntime 'node_modules') -Force|Out-Null
|
|
172
|
+
Copy-Item -LiteralPath (Join-Path $source 'runtime\node_modules\npm') -Destination (Join-Path $privateRuntime 'node_modules\npm') -Recurse
|
|
173
|
+
}
|
|
174
|
+
$node=Join-Path $privateRuntime 'node.exe'
|
|
175
|
+
$npm=Join-Path $privateRuntime 'node_modules\npm\bin\npm-cli.js'
|
|
176
|
+
Demand ((Digest $node) -eq $manifest.sha256.node -and (Digest $npm) -eq $manifest.sha256.npm) 'PRIVATE_RUNTIME_HASH_DENIED'
|
|
177
|
+
$env:PATH=$privateRuntime+';'+$env:PATH
|
|
178
|
+
$phase='STAGE'
|
|
179
|
+
$stage=Join-Path $localPath 'RemoteShell\EasyInstall\stage'
|
|
180
|
+
if(Test-Path -LiteralPath $stage){
|
|
181
|
+
Demand (StageComplete $stage) 'PREVIOUS_STAGE_INCOMPLETE_REVIEW_FIRST'
|
|
182
|
+
Write-Host '[PASS] stage-agent (verified existing dependencies)'
|
|
183
|
+
}else{
|
|
184
|
+
New-Item -ItemType Directory -Path $stage -Force|Out-Null
|
|
185
|
+
Step 'stage-agent' $node @($npm,'install','--prefix',$stage,'--ignore-scripts','--no-audit','--no-fund','--no-package-lock','--no-save',$paths.archive,'--fetch-retries=1','--fetch-timeout=90000')
|
|
186
|
+
Demand (StageComplete $stage) 'DEVICE_DEPENDENCY_VALIDATION_FAILED'
|
|
187
|
+
}
|
|
188
|
+
$cli=Join-Path $stage 'node_modules\@remoteshell\device\bin\device.mjs'
|
|
189
|
+
Demand (Test-Path -LiteralPath $cli -PathType Leaf) 'DEVICE_CLI_MISSING'
|
|
190
|
+
$phase='PREFLIGHT'
|
|
191
|
+
Step 'preflight' $node @($cli,'install-preflight') 20
|
|
192
|
+
$phase='INSTALL'
|
|
193
|
+
Step 'install' $node @($cli,'install') 240
|
|
194
|
+
Step 'status' $node @($cli,'status') 20
|
|
195
|
+
Add-Content -LiteralPath $log -Value 'AGENT_INSTALLED=true; REGISTERED=false; CONNECTED=false' -Encoding UTF8
|
|
196
|
+
Write-Host 'RemoteShell Agent package installed; Google owner approval is separate.'
|
|
197
|
+
Demand (-not (IsRegistered $node $cli)) 'UNEXPECTED_OLD_DEVICE_REGISTRATION_DENIED'
|
|
198
|
+
if($SkipPair){
|
|
199
|
+
Add-Content -LiteralPath $log -Value 'PAIR=SKIPPED_UNREGISTERED; USER_WORKER=NOT_STARTED' -Encoding UTF8
|
|
200
|
+
exit 0
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
$phase='PAIR'
|
|
204
|
+
$url='https://ailab-remoteshell.duckdns.org/dev/'
|
|
205
|
+
$out=Join-Path $reportDir 'pair.out';$err=Join-Path $reportDir 'pair.err'
|
|
206
|
+
$pair=Start-Process -FilePath $node -ArgumentList ('"'+$cli+'" windows-pair '+$url) -PassThru -RedirectStandardOutput $out -RedirectStandardError $err
|
|
207
|
+
$opened=$false;$approved=$false;$pairId='none';$pairStart=Get-Date;$pairDeadline=$pairStart.AddMinutes(5)
|
|
208
|
+
Add-Content -LiteralPath $log -Value ('PAIR_REQUEST_STARTED='+$pairStart.ToString('o')+'; PHASE=WAIT_OWNER_BROWSER') -Encoding UTF8
|
|
209
|
+
try{
|
|
210
|
+
$deadline=(Get-Date).AddMinutes(6)
|
|
211
|
+
while((Get-Date) -lt $deadline){
|
|
212
|
+
if(Test-Path -LiteralPath $out){
|
|
213
|
+
foreach($line in @(Get-Content -LiteralPath $out -ErrorAction SilentlyContinue)){
|
|
214
|
+
try{$obj=$line | ConvertFrom-Json}catch{continue}
|
|
215
|
+
if(-not $opened -and $obj.next -eq 'approve-device-in-browser' -and $obj.ownerApprovalRequired -and $obj.approval_url){
|
|
216
|
+
$link=[uri]$obj.approval_url
|
|
217
|
+
Demand ($link.Scheme -eq 'https' -and $link.Host -eq 'ailab-remoteshell.duckdns.org' -and $link.AbsolutePath.StartsWith('/dev/')) 'PAIR_APPROVAL_URL_DENIED'
|
|
218
|
+
$pairId=($link.AbsolutePath -split '/')[-1]
|
|
219
|
+
Demand ($pairId -match '^[0-9a-fA-F-]{36}$') 'PAIR_REQUEST_ID_INVALID'
|
|
220
|
+
Add-Content -LiteralPath $log -Value ('PAIR_BROWSER_URL_CREATED='+$pairStart.ToString('o')+'; PAIR_ID='+$pairId+'; APPROVAL_DEADLINE='+$pairDeadline.ToString('o')) -Encoding UTF8
|
|
221
|
+
Write-Host 'Google approval: check account and approve the device in the browser.'
|
|
222
|
+
Start-Process $link.AbsoluteUri
|
|
223
|
+
Add-Content -LiteralPath $log -Value ('PAIR_BROWSER_OPEN_ATTEMPT='+((Get-Date).ToString('o'))+'; PAIR_ID='+$pairId) -Encoding UTF8
|
|
224
|
+
$opened=$true
|
|
225
|
+
}
|
|
226
|
+
if($obj.registered -eq $true -and $obj.connected -eq $true){
|
|
227
|
+
$approved=$true
|
|
228
|
+
Add-Content -LiteralPath $log -Value ('PAIR_AGENT_CONNECTED='+((Get-Date).ToString('o'))+'; PAIR_ID='+$pairId) -Encoding UTF8
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
$pair.Refresh()
|
|
233
|
+
if($pair.HasExited){break}
|
|
234
|
+
Start-Sleep -Milliseconds 700
|
|
235
|
+
}
|
|
236
|
+
$pair.Refresh()
|
|
237
|
+
if(-not $approved){
|
|
238
|
+
$reason=if(-not $opened){'PAIR_BROWSER_NOT_OPENED'}elseif((Get-Date) -ge $pairDeadline){'PAIR_APPROVAL_WINDOW_EXPIRED_OR_NO_SERVER_CONFIRMATION'}else{'PAIR_AGENT_TERMINATED_OR_SERVER_REJECTED'}
|
|
239
|
+
$exitStatus=if($pair.HasExited){[string]$pair.ExitCode}else{'RUNNING'}
|
|
240
|
+
Add-Content -LiteralPath $log -Value ('PAIR_DIAGNOSTIC='+$reason+'; PAIR_ID='+$pairId+'; PROCESS_EXIT='+$exitStatus+'; AT='+((Get-Date).ToString('o'))) -Encoding UTF8
|
|
241
|
+
throw $reason
|
|
242
|
+
}
|
|
243
|
+
Demand ($pair.HasExited -and ($null -eq $pair.ExitCode -or $pair.ExitCode -eq 0)) 'PAIR_PROCESS_EXIT_NONZERO'
|
|
244
|
+
Add-Content -LiteralPath $log -Value 'PAIR=PASS; GOOGLE_OWNER_APPROVAL=true' -Encoding UTF8
|
|
245
|
+
Write-Host '[PASS] Google owner approval and first heartbeat'
|
|
246
|
+
}finally{if(-not $pair.HasExited){try{$pair.Kill()}catch{}}}
|
|
247
|
+
$phase='START_AGENT'
|
|
248
|
+
Demand (IsRegistered $node $cli) 'OWNER_PAIRING_REGISTRATION_NOT_PERSISTED'
|
|
249
|
+
if($Background){
|
|
250
|
+
# Opt-in only: current user HKCU Run/VBS, no admin/system service.
|
|
251
|
+
StartRegisteredUserAgent $node $cli $log
|
|
252
|
+
Add-Content -LiteralPath $log -Value 'RUN_MODE=BACKGROUND; USER_AUTOSTART=ENABLED' -Encoding UTF8
|
|
253
|
+
}else{
|
|
254
|
+
# Default foreground: no autostart entry, no hidden launcher.
|
|
255
|
+
$runKey='HKCU:\Software\Microsoft\Windows\CurrentVersion\Run'
|
|
256
|
+
Demand (-not (Get-ItemProperty -LiteralPath $runKey -Name 'RemoteShell-DEV-User-Agent' -ErrorAction SilentlyContinue)) 'EXISTING_USER_AUTOSTART_REVIEW_REQUIRED'
|
|
257
|
+
Demand (-not (Test-Path -LiteralPath (Join-Path $localPath 'RemoteShell\EasyInstall\agent-autostart.vbs'))) 'EXISTING_LAUNCHER_REVIEW_REQUIRED'
|
|
258
|
+
Add-Content -LiteralPath $log -Value 'RUN_MODE=FOREGROUND; USER_AUTOSTART=DISABLED' -Encoding UTF8
|
|
259
|
+
}
|
|
260
|
+
$phase='COMPLETE'
|
|
261
|
+
# Device enrollment is NOT AI connection authorization. An authenticated owner
|
|
262
|
+
# must create and approve a connection covering this exact new device before
|
|
263
|
+
# ChatGPT can obtain the live DC catalog. No automatic connection grant.
|
|
264
|
+
$connectionsUrl='https://ailab-remoteshell.duckdns.org/dev/connections'
|
|
265
|
+
Write-Host ('NEXT: Sign in with the same Google RS identity at '+$connectionsUrl)
|
|
266
|
+
Write-Host 'NEXT: Select this newly registered device, create and approve an AI connection; then refresh ChatGPT tools.'
|
|
267
|
+
Add-Content -LiteralPath $log -Value ('NEXT=VERIFY_OWNER_AI_CONNECTION; URL='+$connectionsUrl) -Encoding UTF8
|
|
268
|
+
Add-Content -LiteralPath $log -Value 'RESULT=INSTALL_AND_PAIR_PASS; AI_CONNECTION_AND_DC_READ_AND_USAGE_NOT_TESTED' -Encoding UTF8
|
|
269
|
+
if(-not $Background){
|
|
270
|
+
$phase='FOREGROUND'
|
|
271
|
+
Write-Host 'Foreground Agent started. Keep this window open; Ctrl+C stops the session.'
|
|
272
|
+
& $node $cli dev-heartbeat
|
|
273
|
+
Demand ($LASTEXITCODE -eq 0) 'FOREGROUND_AGENT_EXIT_NONZERO'
|
|
274
|
+
}
|
|
275
|
+
}catch{
|
|
276
|
+
Write-Host ('[STOP] '+$phase+': '+$_.Exception.Message)
|
|
277
|
+
if($reportDir -and (Test-Path -LiteralPath $reportDir)){
|
|
278
|
+
Add-Content -LiteralPath (Join-Path $reportDir 'result.txt') -Value ('RESULT=FAIL; PHASE='+$phase+'; ERROR='+$_.Exception.Message+'; AT='+((Get-Date).ToString('o'))) -Encoding UTF8
|
|
279
|
+
if($phase -eq 'PAIR'){
|
|
280
|
+
$stderrFile=Join-Path $reportDir 'pair.err'
|
|
281
|
+
if(Test-Path -LiteralPath $stderrFile){
|
|
282
|
+
$known=@(Get-Content -LiteralPath $stderrFile | Where-Object {$_ -match '^DEVICE_[A-Z0-9_]+$'} | Select-Object -First 3)
|
|
283
|
+
foreach($errorCode in $known){Add-Content -LiteralPath (Join-Path $reportDir 'result.txt') -Value ('PAIR_AGENT_ERROR_CODE='+$errorCode) -Encoding UTF8}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
exit 1
|
|
288
|
+
}finally{
|
|
289
|
+
if(-not $CheckOnly -and $reportDir -and (Test-Path -LiteralPath $reportDir -PathType Container)){
|
|
290
|
+
Write-Host ('Result: '+(Join-Path $reportDir 'result.txt'))
|
|
291
|
+
}
|
|
292
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# RS #310 private Ubuntu easy installer; Node not required before execution.
|
|
3
|
+
set -eu
|
|
4
|
+
umask 077
|
|
5
|
+
mode=install
|
|
6
|
+
run_mode=manual
|
|
7
|
+
confirm_linger=no
|
|
8
|
+
# Default stays manual; login/boot autostart are explicit user decisions.
|
|
9
|
+
case "$*" in
|
|
10
|
+
"") ;;
|
|
11
|
+
"--check-only") mode=check ;;
|
|
12
|
+
"--install-only") mode=install-only ;;
|
|
13
|
+
"--pair") mode=pair ;;
|
|
14
|
+
"--login") run_mode=login ;;
|
|
15
|
+
"--pair --login") mode=pair;run_mode=login ;;
|
|
16
|
+
"--boot --confirm-linger") run_mode=boot;confirm_linger=yes ;;
|
|
17
|
+
"--pair --boot --confirm-linger") mode=pair;run_mode=boot;confirm_linger=yes ;;
|
|
18
|
+
*) echo ARGS_DENIED >&2;exit 2 ;;
|
|
19
|
+
esac
|
|
20
|
+
base=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P)
|
|
21
|
+
[ "$(id -u)" -ne 0 ] || { echo DO_NOT_RUN_AS_ROOT >&2;exit 1;}
|
|
22
|
+
[ "$(uname -s)" = Linux ] && [ "$(uname -m)" = x86_64 ] || { echo LINUX_X64_REQUIRED >&2;exit 1;}
|
|
23
|
+
case "$(cat /proc/version 2>/dev/null || true)" in *icrosoft*|*WSL*)echo WSL_BETA_EXCLUDED >&2;exit 1;;esac
|
|
24
|
+
[ -f "$base/manifest.sha256" ] && [ -f "$base/runtime/node" ] && [ -f "$base/agent.tgz" ] || { echo KIT_FILES_MISSING >&2;exit 1;}
|
|
25
|
+
(cd "$base" && sha256sum -c manifest.sha256 >/dev/null) || { echo KIT_HASH_DENIED >&2;exit 1;}
|
|
26
|
+
case "$("$base/runtime/node" --version)" in v22.*):;;*)echo NODE22_REQUIRED >&2;exit 1;;esac
|
|
27
|
+
"$base/runtime/node" "$base/runtime/node_modules/npm/bin/npm-cli.js" --version >/dev/null 2>&1 || { echo NPM_BUNDLE_INVALID >&2;exit 1;}
|
|
28
|
+
[ -n "$HOME" ] && [ -d "$HOME" ] && [ "$HOME" != "/" ] || { echo HOME_DENIED >&2;exit 1;}
|
|
29
|
+
if [ "$mode" = check ];then echo EASY_INSTALL_LINUX_CHECK_PASS;exit 0;fi
|
|
30
|
+
private="$HOME/.local/share/remoteshell-easy"
|
|
31
|
+
runtime="$private/runtime-v22"
|
|
32
|
+
stage="$private/stage"
|
|
33
|
+
mkdir -p "$private"
|
|
34
|
+
if [ ! -d "$runtime" ];then cp -R "$base/runtime" "$runtime";fi
|
|
35
|
+
[ -x "$runtime/node" ] && [ -f "$runtime/node_modules/npm/bin/npm-cli.js" ] || { echo RUNTIME_INVALID >&2;exit 1;}
|
|
36
|
+
export PATH="$runtime:$PATH"
|
|
37
|
+
if [ "$mode" = pair ];then
|
|
38
|
+
cli="$HOME/.local/share/remoteshell-device/install/node_modules/@remoteshell/device/bin/device.mjs"
|
|
39
|
+
[ -f "$cli" ] || { echo AGENT_NOT_INSTALLED >&2;exit 1;}
|
|
40
|
+
if [ "$confirm_linger" = yes ];then
|
|
41
|
+
"$runtime/node" "$cli" setup https://ailab-remoteshell.duckdns.org/dev/ "$run_mode" --confirm-linger
|
|
42
|
+
else
|
|
43
|
+
"$runtime/node" "$cli" setup https://ailab-remoteshell.duckdns.org/dev/ "$run_mode"
|
|
44
|
+
fi
|
|
45
|
+
exit $?
|
|
46
|
+
fi
|
|
47
|
+
[ ! -e "$HOME/.local/share/remoteshell-device/install" ] || { echo EXISTING_AGENT_PRESERVED >&2;exit 1;}
|
|
48
|
+
[ ! -e "$stage" ] || { echo PREVIOUS_STAGE_EXISTS >&2;exit 1;}
|
|
49
|
+
mkdir -m 700 "$stage"
|
|
50
|
+
"$runtime/node" "$runtime/node_modules/npm/bin/npm-cli.js" install --prefix "$stage" --ignore-scripts --no-audit --no-fund --no-package-lock --no-save "$base/agent.tgz" || { echo STAGE_DEPENDENCY_FAILED >&2;exit 1;}
|
|
51
|
+
cli="$stage/node_modules/@remoteshell/device/bin/device.mjs"
|
|
52
|
+
[ -f "$cli" ] || { echo STAGE_AGENT_MISSING >&2;exit 1;}
|
|
53
|
+
"$runtime/node" "$cli" install-preflight
|
|
54
|
+
"$runtime/node" "$cli" install || { echo AGENT_INSTALL_FAILED >&2;exit 1;}
|
|
55
|
+
# The install receipt is in the user's permanent layout; the npm staging
|
|
56
|
+
# tree is disposable. Otherwise uninstall -> reinstall is blocked by stage.
|
|
57
|
+
installed_cli="$HOME/.local/share/remoteshell-device/install/node_modules/@remoteshell/device/bin/device.mjs"
|
|
58
|
+
[ -f "$installed_cli" ] || { echo INSTALLED_AGENT_MISSING >&2;exit 1;}
|
|
59
|
+
[ -d "$stage" ] && [ ! -L "$stage" ] || { echo STAGE_INVALID >&2;exit 1;}
|
|
60
|
+
rm -rf -- "$stage"
|
|
61
|
+
cli="$installed_cli"
|
|
62
|
+
echo EASY_INSTALL_LINUX_PASS_NOT_YET_PAIRED
|
|
63
|
+
if [ "$mode" = install ];then
|
|
64
|
+
if [ "$confirm_linger" = yes ];then
|
|
65
|
+
"$runtime/node" "$cli" setup https://ailab-remoteshell.duckdns.org/dev/ "$run_mode" --confirm-linger
|
|
66
|
+
else
|
|
67
|
+
"$runtime/node" "$cli" setup https://ailab-remoteshell.duckdns.org/dev/ "$run_mode"
|
|
68
|
+
fi
|
|
69
|
+
else
|
|
70
|
+
echo 'Pair later: sh install.sh --pair'
|
|
71
|
+
fi
|