<# .SYNOPSIS MODULYX setup for Windows: installs the MODULYX agent for the current user. No administrator rights needed. .DESCRIPTION Run it from a normal PowerShell window (not "Run as administrator"): irm https://modulyx.reycarbone.it/setup.ps1 | iex With options: & ([scriptblock]::Create((irm https://modulyx.reycarbone.it/setup.ps1))) -Autostart What it does: 1. Reads the latest release from https://modulyx.reycarbone.it/releases/latest.json. 2. Downloads the agent zip and checks its SHA-256 against the release's SHA256SUMS file. A mismatch stops the setup. 3. Installs it to %LOCALAPPDATA%\MODULYX\app and adds a "MODULYX" shortcut to the Start menu. Your settings in %APPDATA%\MODULYX are kept; if you used PhoneBox before, its settings are copied there once. No other program is touched. 4. Optionally starts it with Windows (-Autostart), then starts it and opens its settings page. The agent downloads Google's Android platform-tools (adb) by itself the first time it needs them, so nothing else has to be installed to connect a phone over USB. Run the setup again to update or repair the installation. .PARAMETER Autostart Start MODULYX when you sign in to Windows. .PARAMETER NoStart Install only; do not start the agent. .PARAMETER DryRun Download and check everything, show what would happen and change nothing. #> param([switch]$Autostart, [switch]$NoStart, [switch]$DryRun) $ErrorActionPreference = 'Stop' $ProgressPreference = 'SilentlyContinue' $Site = 'https://modulyx.reycarbone.it' $App = Join-Path $env:LOCALAPPDATA 'MODULYX\app' try { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 } catch { } function Step([string]$Text) { Write-Host ''; Write-Host "==> $Text" -ForegroundColor Cyan } function Ok([string]$Text) { Write-Host " OK $Text" -ForegroundColor Green } function Note([string]$Text) { Write-Host " $Text" } Write-Host 'MODULYX setup' Step 'Checking this PC' $identity = [Security.Principal.WindowsIdentity]::GetCurrent() if ((New-Object Security.Principal.WindowsPrincipal $identity).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { throw 'Run this from a normal PowerShell window, not as administrator: MODULYX installs for your own user.' } if (-not [Environment]::Is64BitOperatingSystem) { throw 'MODULYX needs 64-bit Windows 10 or 11.' } Ok "Windows $([Environment]::OSVersion.Version.Build), 64-bit" Step 'Finding the latest release' $feed = Invoke-RestMethod -Uri "$Site/releases/latest.json" -UseBasicParsing $zipAsset = $feed.assets | Where-Object { $_.name -like 'MODULYX-Agent-*-win-x64.zip' } | Select-Object -First 1 $sumsAsset = $feed.assets | Where-Object { $_.name -like 'SHA256SUMS-*.txt' } | Select-Object -First 1 if (-not $zipAsset -or -not $sumsAsset) { throw 'The release has no Windows agent or no checksum file. Nothing was installed.' } $version = $feed.tag_name.TrimStart('v') Ok "MODULYX $version" Step 'Downloading and checking the agent' $temp = Join-Path ([IO.Path]::GetTempPath()) ('modulyx-setup-' + [Guid]::NewGuid().ToString('N')) New-Item -ItemType Directory -Path $temp | Out-Null try { $zipName = [IO.Path]::GetFileName(([Uri]$zipAsset.browser_download_url).LocalPath) $zip = Join-Path $temp $zipName $sums = Join-Path $temp 'SHA256SUMS.txt' Invoke-WebRequest -Uri $sumsAsset.browser_download_url -OutFile $sums -UseBasicParsing Note "$zipName (about 65 MB) ..." Invoke-WebRequest -Uri $zipAsset.browser_download_url -OutFile $zip -UseBasicParsing $line = Get-Content $sums | Where-Object { $_ -match ('^[0-9a-fA-F]{64}\s+\*?' + [regex]::Escape($zipName) + '\s*$') } | Select-Object -First 1 if (-not $line) { throw "$zipName is not listed in the release checksums; the download was not used." } $expected = ([regex]::Match($line, '^[0-9a-fA-F]{64}')).Value $actual = (Get-FileHash -LiteralPath $zip -Algorithm SHA256).Hash if ($actual -ne $expected) { throw "The download does not match its checksum (expected $expected, got $actual). Nothing was installed; run the setup again." } Ok 'The download matches the release checksum' Note 'The agent is not code-signed: Windows SmartScreen or an antivirus may warn about it. The checksum above shows it is the published file.' if ($DryRun) { Step 'Dry run: nothing was changed'; return } Step "Installing to $App" Get-Process MODULYX, PhoneBoxAgent -ErrorAction SilentlyContinue | Where-Object { $_.Path -like "$App\*" } | ForEach-Object { $_.Kill(); [void]$_.WaitForExit(10000) } Get-ChildItem -LiteralPath $App -File -ErrorAction SilentlyContinue | Remove-Item -Force -ErrorAction SilentlyContinue # a clean replace: no file of an older version is left behind New-Item -ItemType Directory -Force -Path $App | Out-Null Expand-Archive -LiteralPath $zip -DestinationPath $App -Force $exe = Join-Path $App 'MODULYX.exe' if (-not (Test-Path $exe)) { throw 'The agent was not found after unpacking.' } Ok "MODULYX $version installed; your settings are kept" $shell = New-Object -ComObject WScript.Shell function Shortcut([string]$Path) { $l = $shell.CreateShortcut($Path); $l.TargetPath = $exe; $l.WorkingDirectory = $App; $l.IconLocation = "$exe,0"; $l.Description = 'MODULYX'; $l.Save() } Shortcut (Join-Path ([Environment]::GetFolderPath('Programs')) 'MODULYX.lnk') Ok 'Added a "MODULYX" shortcut to the Start menu' $startup = Join-Path ([Environment]::GetFolderPath('Startup')) 'MODULYX.lnk' if ($Autostart) { Shortcut $startup; Ok 'MODULYX starts when you sign in' } elseif (Test-Path $startup) { Note 'MODULYX already starts with Windows (kept)' } if (-not $NoStart) { Step 'Starting MODULYX' Start-Process -FilePath $exe -WorkingDirectory $App $up = $false foreach ($i in 1..20) { Start-Sleep -Milliseconds 700; try { Invoke-WebRequest 'http://127.0.0.1:8765/' -UseBasicParsing -TimeoutSec 2 | Out-Null; $up = $true; break } catch { } } if ($up) { Ok 'MODULYX is running: settings at http://127.0.0.1:8765'; Start-Process 'http://127.0.0.1:8765' } else { Note 'MODULYX is starting; open it from the Start menu if the settings page does not open.' } } Step 'Connect your phone' Note "1. Install the MODULYX app on the Android phone: $Site/#download" Note '2. Turn on USB debugging and plug it in with a data cable. MODULYX downloads adb by itself. Step-by-step guide:' Note " $Site/usb/" Note '3. Or pair over Wi-Fi: Settings > General > Wi-Fi & Tailscale > Pair a phone over Wi-Fi.' Note 'Uninstall: close MODULYX, then delete %LOCALAPPDATA%\MODULYX and the Start menu shortcut. Settings stay in %APPDATA%\MODULYX.' } finally { Remove-Item -LiteralPath $temp -Recurse -Force -ErrorAction SilentlyContinue }