Repository navigation
feat(install): add a MeshLLM Start menu entry on Windows #3045
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9f726ac
f0269b0
d6098b4
29982b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ param( | |
| [string]$Flavor, | ||
| [switch]$NoPathUpdate, | ||
| [switch]$NoSetup, | ||
| [switch]$NoShortcut, | ||
| [switch]$Help | ||
| ) | ||
|
|
||
|
|
@@ -29,6 +30,10 @@ if (Test-Truthy $env:MESH_LLM_INSTALL_PRERELEASE) { | |
| $PreRelease = $true | ||
| } | ||
|
|
||
| if (Test-Truthy $env:MESH_LLM_INSTALL_NO_SHORTCUT) { | ||
| $NoShortcut = $true | ||
| } | ||
|
|
||
| $RequireChecksum = Test-Truthy $env:MESH_LLM_REQUIRE_CHECKSUM | ||
|
|
||
| if (-not $Flavor -and $env:MESH_LLM_INSTALL_FLAVOR) { | ||
|
|
@@ -42,14 +47,15 @@ if (-not $InstallDir) { | |
|
|
||
| function Show-Usage { | ||
| @" | ||
| Usage: install.ps1 [-PreRelease] [-InstallDir <DIR>] [-Flavor <FLAVOR>] [-NoPathUpdate] [-NoSetup] | ||
| Usage: install.ps1 [-PreRelease] [-InstallDir <DIR>] [-Flavor <FLAVOR>] [-NoPathUpdate] [-NoSetup] [-NoShortcut] | ||
|
|
||
| Options: | ||
| -PreRelease Install the latest published GitHub prerelease instead of the latest stable release. | ||
| -InstallDir <DIR> Install directory. Defaults to %LOCALAPPDATA%\mesh-llm\bin. | ||
| -Flavor <FLAVOR> Legacy compatibility flag. The installer installs the Windows x64 product bundle, including its packaged runtime; ``mesh-llm.exe setup`` may select another compatible runtime. | ||
| -NoPathUpdate Do not add the install directory to the user Path. | ||
| -NoSetup Do not run ``mesh-llm.exe setup``; print the exact command instead. | ||
| -NoShortcut Do not add the MeshLLM Start menu shortcut, which opens the console and starts the node when it is not running. | ||
| -Help Show this help text. | ||
|
|
||
| Environment overrides: | ||
|
|
@@ -58,6 +64,8 @@ Environment overrides: | |
| MESH_LLM_INSTALL_PRERELEASE=1 | ||
| MESH_LLM_INSTALL_REPO=Mesh-LLM/mesh-llm | ||
| MESH_LLM_REQUIRE_CHECKSUM=1 | ||
| MESH_LLM_INSTALL_NO_SHORTCUT=1 | ||
| MESH_LLM_INSTALL_START_MENU_DIR (folder for the shortcut; defaults to the user's Start menu Programs folder) | ||
| "@ | ||
| } | ||
|
|
||
|
|
@@ -647,6 +655,143 @@ function Add-InstallDirToPath { | |
| return $true | ||
| } | ||
|
|
||
| $ConsoleLauncherName = "mesh-llm-console.ps1" | ||
| # The first release whose `mesh-llm uninstall` removes the shortcut and its | ||
| # launcher. An older bundle would leave a shortcut to a deleted launcher behind. | ||
| $StartMenuMinimumVersion = [version]"0.81.0" | ||
|
|
||
| # Run by the Start menu shortcut: open the console, starting the node first when | ||
| # it is not answering. The node starts through the `mesh-llm` scheduled task when | ||
| # `setup` installed it for this copy, else with the command that task runs. The | ||
| # second line records the shortcut, so `mesh-llm uninstall` removes the one this | ||
| # copy created and no other. | ||
| $ConsoleLauncherScript = @' | ||
| # Opens the MeshLLM console for the mesh-llm.exe beside this script. | ||
| # Start menu shortcut: __MESH_LLM_START_MENU_SHORTCUT__ | ||
| $ErrorActionPreference = 'Stop' | ||
| $mesh = Join-Path $PSScriptRoot 'mesh-llm.exe' | ||
| $console = 'http://127.0.0.1:3131/' | ||
|
|
||
| function Test-Console { | ||
| try { | ||
| Invoke-WebRequest -Uri ($console + 'api/status') -UseBasicParsing -TimeoutSec 2 | Out-Null | ||
| return $true | ||
| } catch { | ||
| return $false | ||
| } | ||
| } | ||
|
|
||
| # The `mesh-llm` task starts this copy only when setup registered it from this | ||
| # directory: setup runs the task in the binary's own directory. | ||
| function Test-TaskRunsThisCopy { | ||
| $xml = $null | ||
| try { | ||
| $ErrorActionPreference = 'SilentlyContinue' | ||
| $xml = (& schtasks.exe /Query /TN mesh-llm /XML 2>$null) -join "`n" | ||
| if ($LASTEXITCODE -ne 0) { return $false } | ||
| } catch { | ||
| return $false | ||
| } | ||
| try { | ||
| $directory = ([xml]$xml).Task.Actions.Exec.WorkingDirectory | ||
| } catch { | ||
| return $false | ||
| } | ||
| if (-not $directory) { return $false } | ||
| $directory = [Environment]::ExpandEnvironmentVariables($directory).TrimEnd('\') | ||
| return [string]::Equals($directory, $PSScriptRoot.TrimEnd('\'), [StringComparison]::OrdinalIgnoreCase) | ||
| } | ||
|
|
||
| function Show-Failure([string]$Message) { | ||
| Add-Type -AssemblyName PresentationFramework | ||
| [System.Windows.MessageBox]::Show($Message, 'MeshLLM') | Out-Null | ||
| } | ||
|
|
||
| if (-not (Test-Console)) { | ||
| if (Test-TaskRunsThisCopy) { | ||
| # Start-Process, not &: with 'Stop', Windows PowerShell turns the stderr | ||
| # of a failed run into a terminating error. | ||
| $run = Start-Process -FilePath schtasks.exe -ArgumentList '/Run', '/TN', 'mesh-llm' -WindowStyle Hidden -Wait -PassThru | ||
| if ($run.ExitCode -ne 0) { | ||
| Show-Failure "MeshLLM's background task did not start (schtasks exit code $($run.ExitCode)). Run 'mesh-llm status' in PowerShell to see why." | ||
| exit 1 | ||
| } | ||
| } else { | ||
| Start-Process -FilePath $mesh -ArgumentList 'serve' -WindowStyle Hidden | ||
| } | ||
| $deadline = (Get-Date).AddSeconds(90) | ||
| while ((Get-Date) -lt $deadline -and -not (Test-Console)) { | ||
| Start-Sleep -Seconds 1 | ||
| } | ||
| } | ||
|
|
||
| if (Test-Console) { | ||
| Start-Process $console | ||
| } else { | ||
| Show-Failure "MeshLLM did not start within 90 seconds. Run 'mesh-llm status' in PowerShell to see why." | ||
| } | ||
| '@ | ||
|
|
||
| function Get-StartMenuDir { | ||
| if ($env:MESH_LLM_INSTALL_START_MENU_DIR) { | ||
| return $env:MESH_LLM_INSTALL_START_MENU_DIR | ||
| } | ||
| return [Environment]::GetFolderPath("Programs") | ||
| } | ||
|
|
||
| # The version in what `mesh-llm --version` printed, without any prerelease | ||
| # suffix, or $null when there is none. | ||
| function Get-MeshVersion { | ||
| param([string]$VersionText) | ||
|
|
||
| if ($VersionText -match '(\d+)\.(\d+)\.(\d+)') { | ||
| return [version]"$($Matches[1]).$($Matches[2]).$($Matches[3])" | ||
| } | ||
| return $null | ||
| } | ||
|
|
||
| # A MeshLLM entry in the Start menu, so the console is one click away without | ||
| # opening a terminal. Returns the shortcut path, or $null when there is none. | ||
| function Install-StartMenuShortcut { | ||
| param([string]$MeshBinary, [string]$VersionText) | ||
|
|
||
| if ($NoShortcut) { | ||
| return $null | ||
| } | ||
| $version = Get-MeshVersion -VersionText $VersionText | ||
| if (-not $version -or $version -lt $StartMenuMinimumVersion) { | ||
| Write-Host "Skipping the Start menu shortcut: this mesh-llm cannot remove it on uninstall (it can from $StartMenuMinimumVersion)." | ||
| return $null | ||
| } | ||
|
|
||
| # The shortcut keeps these paths for Explorer, which does not know the | ||
| # directory this installer ran from. | ||
| $installDirFull = (Resolve-Path -LiteralPath $InstallDir).ProviderPath | ||
| $meshBinaryFull = (Resolve-Path -LiteralPath $MeshBinary).ProviderPath | ||
| $launcher = Join-Path $installDirFull $ConsoleLauncherName | ||
| $startMenu = Get-StartMenuDir | ||
| New-Item -ItemType Directory -Path $startMenu -Force | Out-Null | ||
| $shortcutPath = Join-Path (Resolve-Path -LiteralPath $startMenu).ProviderPath "MeshLLM.lnk" | ||
|
|
||
| $script = $ConsoleLauncherScript.Replace("__MESH_LLM_START_MENU_SHORTCUT__", $shortcutPath) | ||
| # Written beside it, then moved over it, so a failed write leaves an | ||
| # earlier launcher whole. | ||
| $pending = "$launcher.tmp" | ||
| Set-Content -LiteralPath $pending -Value $script -Encoding UTF8 | ||
| Move-Item -LiteralPath $pending -Destination $launcher -Force | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reject a directory at the launcher path. If
|
||
| $shell = New-Object -ComObject WScript.Shell | ||
| $shortcut = $shell.CreateShortcut($shortcutPath) | ||
| $shortcut.TargetPath = Join-Path $env:SystemRoot "System32\WindowsPowerShell\v1.0\powershell.exe" | ||
| $shortcut.Arguments = "-NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden -File `"$launcher`"" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in f0269b0: the launcher, working directory, icon and recorded shortcut path are resolved to absolute paths before they are saved. The harness checks the recorded path is absolute. |
||
| $shortcut.WorkingDirectory = $installDirFull | ||
| $shortcut.IconLocation = "$meshBinaryFull,0" | ||
| $shortcut.Description = "Open the MeshLLM console" | ||
| # 7: start minimized, so no console window shows while the node starts. | ||
| $shortcut.WindowStyle = 7 | ||
| $shortcut.Save() | ||
| return $shortcutPath | ||
| } | ||
|
|
||
| function Test-InteractiveSession { | ||
| if ($env:MESH_LLM_INSTALL_INTERACTIVE) { | ||
| return Test-Truthy $env:MESH_LLM_INSTALL_INTERACTIVE | ||
|
|
@@ -714,12 +859,30 @@ try { | |
|
|
||
| $meshBinary = Join-Path $InstallDir "mesh-llm.exe" | ||
| Write-Host "Installed $asset to $InstallDir" | ||
| & $meshBinary --version | ||
| $versionText = (& $meshBinary --version) -join " " | ||
| Write-Host $versionText | ||
|
|
||
| if ($NoPathUpdate -and -not $pathUpdated) { | ||
| Write-Host "Install directory was not added to PATH. Use the full command below until you add $InstallDir to PATH." | ||
| } | ||
|
|
||
| # The shortcut is a convenience: a failure to add it must not stop setup. | ||
| # A launcher an earlier install left may still back a working shortcut, | ||
| # so only one this attempt created is removed. | ||
| $launcherExisted = Test-Path -LiteralPath (Join-Path $InstallDir $ConsoleLauncherName) | ||
| try { | ||
| $shortcutPath = Install-StartMenuShortcut -MeshBinary $meshBinary -VersionText $versionText | ||
| if ($shortcutPath) { | ||
| Write-Host "Added MeshLLM to the Start menu: it opens the console and starts the node when it is not running." | ||
| } | ||
| } catch { | ||
| Write-Warning "Could not add MeshLLM to the Start menu: $($_.Exception.Message)" | ||
| Remove-Item -LiteralPath (Join-Path $InstallDir "$ConsoleLauncherName.tmp") -Force -ErrorAction SilentlyContinue | ||
| if (-not $launcherExisted) { | ||
| Remove-Item -LiteralPath (Join-Path $InstallDir $ConsoleLauncherName) -Force -ErrorAction SilentlyContinue | ||
| } | ||
| } | ||
|
|
||
| Invoke-SetupOrPrint -MeshBinary $meshBinary | ||
| } finally { | ||
| if (Test-Path $tmpRoot) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The website publishes this script on a push to
main, while the default download currently installs v0.80.0. That binary's uninstaller leaves both of these new files behind. Gate shortcut creation on cleanup support in the downloaded bundle, or coordinate the website rollout with a release that can remove it.Website deploy trigger · Current stable release
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in f0269b0: the entry is only added when the installed
mesh-llm --versionis 0.81.0 or later, the first release whose uninstall removes it. With the current 0.80.0 bundle the installer says it is skipping the shortcut and goes on. The harness covers both (native_windows_consumer_skips_the_shortcut_for_a_bundle_that_cannot_remove_it).