From 63c8caaace5ac7a059c8ccd0e10ec4a4513a6083 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Tue, 24 Jun 2025 18:45:58 +0200 Subject: [PATCH] feat: add windows installer --- assets/install-nightly.ps1 | 63 ++++++++++++++++++++++++++++++++++++++ assets/install.ps1 | 63 ++++++++++++++++++++++++++++++++++++++ content/index.smd | 16 ++++++++-- zine.ziggy | 2 ++ 4 files changed, 142 insertions(+), 2 deletions(-) create mode 100644 assets/install-nightly.ps1 create mode 100644 assets/install.ps1 diff --git a/assets/install-nightly.ps1 b/assets/install-nightly.ps1 new file mode 100644 index 0000000..f2015fc --- /dev/null +++ b/assets/install-nightly.ps1 @@ -0,0 +1,63 @@ +$ErrorActionPreference = "Stop" + +$repo = "neurocyte/flow-nightly" +$title = "flow nightly build" +$updater = "install-nightly" + +$release = Invoke-RestMethod -Uri "https://api.github.com/repos/$repo/releases/latest" +$version = $release.tag_name +$title_updater = "$title updater" +$title = "$title $version" +$install_dir = "$env:APPDATA\flow\bin" + +$existing_flow = Join-Path -Path $install_dir -ChildPath "flow.exe" +if (Test-Path $existing_flow) { + $existing_version_output = & $existing_flow --version 2>&1 | Out-String + $existing_version_lines = $existing_version_output -split "[\r\n]+" | Where-Object { $_ -match '^\s*version:\s*(.+?)\s*$' } + if ($existing_version_lines -and $matches) { + $existing_version = $matches[1] + if ($version -eq $existing_version) { + Write-Host "flow is up-to-date (version $version @ $install_dir)" + exit 0 + } + } +} + +switch ($env:PROCESSOR_ARCHITECTURE) { + "AMD64" { $arch = "x86_64" } + "ARM64" { $arch = "aarch64" } + default { + Write-Host "unknown architecture: $($env:PROCESSOR_ARCHITECTURE)" + exit 1 + } +} + +$filename = "flow-$version-windows-$arch.zip" + +if (-not (Test-Path $install_dir)) { + Write-Host "creating installation directory: $install_dir" + New-Item -ItemType Directory -Path $install_dir | Out-Null +} + +Write-Host "downloading $title..." +Invoke-WebRequest -Uri "https://github.com/$repo/releases/download/$version/$filename" -OutFile "$install_dir\$filename" + +echo "installing $title to $install_dir ..." +Expand-Archive -Path "$install_dir\$filename" -DestinationPath $install_dir -Force +Remove-Item "$install_dir\$filename" + +echo "installing $title_updater to $install_dir\update-flow.ps1 ..." +Invoke-WebRequest -Uri "https://flow-control.dev/$updater.ps1" -OutFile "$install_dir\update-flow.ps1" + +echo "$title installed successfully to $install_dir" + +$current_path = [System.Environment]::GetEnvironmentVariable("Path", "User") +if ($current_path -notlike "*$install_dir*") { + $response = Read-Host "do you want to add $install_dir to your PATH? (y/n)" + if ($response -eq "y") { + $newPath = "$current_path;$install_dir" + [System.Environment]::SetEnvironmentVariable("Path", $newPath, "User") + Write-Host "added $install_dir to PATH" + Write-Host "close your terminal for changes to take effect" + } +} diff --git a/assets/install.ps1 b/assets/install.ps1 new file mode 100644 index 0000000..324c805 --- /dev/null +++ b/assets/install.ps1 @@ -0,0 +1,63 @@ +$ErrorActionPreference = "Stop" + +$repo = "neurocyte/flow" +$title = "flow" +$updater = "install" + +$release = Invoke-RestMethod -Uri "https://api.github.com/repos/$repo/releases/latest" +$version = $release.tag_name +$title_updater = "$title updater" +$title = "$title $version" +$install_dir = "$env:APPDATA\flow\bin" + +$existing_flow = Join-Path -Path $install_dir -ChildPath "flow.exe" +if (Test-Path $existing_flow) { + $existing_version_output = & $existing_flow --version 2>&1 | Out-String + $existing_version_lines = $existing_version_output -split "[\r\n]+" | Where-Object { $_ -match '^\s*version:\s*(.+?)\s*$' } + if ($existing_version_lines -and $matches) { + $existing_version = $matches[1] + if ($version -eq $existing_version) { + Write-Host "flow is up-to-date (version $version @ $install_dir)" + exit 0 + } + } +} + +switch ($env:PROCESSOR_ARCHITECTURE) { + "AMD64" { $arch = "x86_64" } + "ARM64" { $arch = "aarch64" } + default { + Write-Host "unknown architecture: $($env:PROCESSOR_ARCHITECTURE)" + exit 1 + } +} + +$filename = "flow-$version-windows-$arch.zip" + +if (-not (Test-Path $install_dir)) { + Write-Host "creating installation directory: $install_dir" + New-Item -ItemType Directory -Path $install_dir | Out-Null +} + +Write-Host "downloading $title..." +Invoke-WebRequest -Uri "https://github.com/$repo/releases/download/$version/$filename" -OutFile "$install_dir\$filename" + +echo "installing $title to $install_dir ..." +Expand-Archive -Path "$install_dir\$filename" -DestinationPath $install_dir -Force +Remove-Item "$install_dir\$filename" + +echo "installing $title_updater to $install_dir\update-flow.ps1 ..." +Invoke-WebRequest -Uri "https://flow-control.dev/$updater.ps1" -OutFile "$install_dir\update-flow.ps1" + +echo "$title installed successfully to $install_dir" + +$current_path = [System.Environment]::GetEnvironmentVariable("Path", "User") +if ($current_path -notlike "*$install_dir*") { + $response = Read-Host "do you want to add $install_dir to your PATH? (y/n)" + if ($response -eq "y") { + $newPath = "$current_path;$install_dir" + [System.Environment]::SetEnvironmentVariable("Path", $newPath, "User") + Write-Host "added $install_dir to PATH" + Write-Host "close your terminal for changes to take effect" + } +} diff --git a/content/index.smd b/content/index.smd index 5e95b1b..00b1721 100644 --- a/content/index.smd +++ b/content/index.smd @@ -42,10 +42,22 @@ Fetch and install the latest release to `/usr/local/bin` with the installation h curl -fsSL https://flow-control.dev/install | sh ``` -Install latest nightly build and (optionally) specify the installation destination: +or on Windows ``` -curl -fsSL https://flow-control.dev/install | sh -s -- --nightly --prefix ~/.local/bin +Invoke-RestMethod "https://flow-control.dev/install.ps1" | Invoke-Expression +``` + +Install the latest nightly build: + +``` +curl -fsSL https://flow-control.dev/install | sh -s -- --nightly +``` + +or on Windows + +``` +Invoke-RestMethod "https://flow-control.dev/install-nightly.ps1" | Invoke-Expression ``` See all avalable options for the installer script: diff --git a/zine.ziggy b/zine.ziggy index 5a9965a..566ea4e 100644 --- a/zine.ziggy +++ b/zine.ziggy @@ -6,6 +6,8 @@ Site { .assets_dir_path = "assets", .static_assets = [ "install", + "install.ps1", + "install-nightly.ps1", "public.gpg", "fonts/AcPlus_IBM_VGA_9x16.ttf", "fonts/Iosevka-Regular.woff2",