diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 066be0f..05ef281 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,8 +2,14 @@ name: CI on: push: + branches: [master] pull_request: +# A newer push to the same branch or PR supersedes the running check. +concurrency: + group: ci-${{ github.ref }} + cancel-in-progress: true + env: CARGO_TERM_COLOR: always @@ -16,7 +22,7 @@ jobs: os: [ubuntu-latest, windows-latest, macos-latest] runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v7 - uses: dtolnay/rust-toolchain@stable with: components: clippy @@ -26,6 +32,21 @@ jobs: sudo apt-get update sudo apt-get install -y libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev libxkbcommon-dev libssl-dev - uses: Swatinem/rust-cache@v2 - - run: cargo build --workspace --release - - run: cargo test --workspace - - run: cargo clippy --workspace --all-targets -- -D warnings + - run: cargo build --workspace --release --locked + - run: cargo test --workspace --locked + - run: cargo clippy --workspace --all-targets --locked -- -D warnings + + scripts: + name: install scripts + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + - name: shellcheck install.sh + run: shellcheck install.sh + - name: PSScriptAnalyzer install.ps1 + shell: pwsh + run: | + # Write-Host is the right tool for an installer piped into iex. + $issues = Invoke-ScriptAnalyzer -Path install.ps1 -Severity Warning,Error -ExcludeRule PSAvoidUsingWriteHost + $issues | Format-Table -AutoSize + if ($issues) { exit 1 } diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..87e9e1b --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,178 @@ +name: Release + +# Pushing a tag vX.Y.Z (matching the version in Cargo.toml) builds bench51 +# for every target, publishes a GitHub release with the archives, checksums +# and the CHANGELOG.md section as notes, then installs it with the one-line +# installers on each OS. Pull requests that touch the release machinery get +# a dry run: everything except publishing. + +on: + push: + tags: ['v*'] + pull_request: + paths: + - .github/workflows/release.yml + - install.sh + - install.ps1 + workflow_dispatch: + +permissions: + contents: read + +env: + CARGO_TERM_COLOR: always + +jobs: + build: + name: ${{ matrix.target }} + strategy: + fail-fast: false + matrix: + include: + # 22.04 keeps the glibc requirement low for older distributions. + - { target: x86_64-unknown-linux-gnu, os: ubuntu-22.04 } + - { target: aarch64-unknown-linux-gnu, os: ubuntu-22.04-arm } + - { target: x86_64-pc-windows-msvc, os: windows-latest } + - { target: aarch64-apple-darwin, os: macos-latest } + # Cross-compiled on Apple silicon, so it can't be run here. + - { target: x86_64-apple-darwin, os: macos-latest, cross: true } + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v7 + + - name: Check the tag matches Cargo.toml + if: startsWith(github.ref, 'refs/tags/v') + shell: bash + run: | + version=$(sed -n 's/^version = "\(.*\)"$/\1/p' Cargo.toml | head -n 1) + if [ "$GITHUB_REF_NAME" != "v$version" ]; then + echo "::error::tag $GITHUB_REF_NAME does not match version $version in Cargo.toml" + exit 1 + fi + + - uses: dtolnay/rust-toolchain@stable + with: + targets: ${{ matrix.target }} + + - name: Install Linux GUI dependencies + if: runner.os == 'Linux' + run: | + sudo apt-get update + sudo apt-get install -y libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev libxkbcommon-dev libssl-dev + + - uses: Swatinem/rust-cache@v2 + with: + key: ${{ matrix.target }} + + - name: Build + run: cargo build --release --locked --target ${{ matrix.target }} -p bench51 -p bench51-gui + + - name: Package + shell: bash + run: | + name=bench51-${{ matrix.target }} + ext= + if [ "$RUNNER_OS" = Windows ]; then ext=.exe; fi + mkdir -p "dist/$name" + cp "target/${{ matrix.target }}/release/bench51$ext" "target/${{ matrix.target }}/release/bench51-gui$ext" "dist/$name/" + cp README.md LICENSE CHANGELOG.md "dist/$name/" + if [ "$RUNNER_OS" = Linux ]; then + mkdir -p "dist/$name/share/applications" "dist/$name/share/icons/hicolor/scalable/apps" + cp crates/bench51-gui/assets/bench51-gui.desktop "dist/$name/share/applications/" + cp crates/bench51-gui/assets/bench51-gui.svg "dist/$name/share/icons/hicolor/scalable/apps/" + fi + cd dist + if [ "$RUNNER_OS" = Windows ]; then + 7z a -tzip "$name.zip" "$name" > /dev/null + else + tar -czf "$name.tar.gz" "$name" + fi + rm -rf "$name" + ls -l + + - name: Install the archive and run it + if: runner.os != 'Windows' && !matrix.cross + shell: bash + run: | + sh install.sh --archive "dist/bench51-${{ matrix.target }}.tar.gz" --dir "$RUNNER_TEMP/bin" --no-desktop + "$RUNNER_TEMP/bin/bench51-gui" --version + printf 'ORG 0\nloop: MOV A,#1\n SJMP loop\n END\n' > "$RUNNER_TEMP/t.asm" + "$RUNNER_TEMP/bin/bench51" --assemble "$RUNNER_TEMP/t.asm" + test -s "$RUNNER_TEMP/t.hex" + + - name: Install the archive and run it + if: runner.os == 'Windows' + shell: pwsh + run: | + ./install.ps1 -Archive "dist/bench51-${{ matrix.target }}.zip" -InstallDir "$env:RUNNER_TEMP\bench51" -NoShortcut + if ($LASTEXITCODE) { exit $LASTEXITCODE } + # The GUI has no console; check its exit code instead of its output. + $gui = Start-Process -FilePath "$env:RUNNER_TEMP\bench51\bench51-gui.exe" -ArgumentList '--version' -Wait -PassThru + if ($gui.ExitCode -ne 0) { exit 1 } + + - uses: actions/upload-artifact@v7 + with: + name: bench51-${{ matrix.target }} + path: dist/* + if-no-files-found: error + + publish: + needs: build + if: startsWith(github.ref, 'refs/tags/v') + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v7 + + - uses: actions/download-artifact@v8 + with: + path: dist + merge-multiple: true + + - name: Checksums + run: | + cd dist + sha256sum -- * > SHA256SUMS + cat SHA256SUMS + + - name: Release notes from CHANGELOG.md + run: | + version=${GITHUB_REF_NAME#v} + awk -v v="$version" '/^## \[/ { if (on) exit; on = index($0, "[" v "]") } on' CHANGELOG.md | tail -n +2 > notes.md + if [ ! -s notes.md ]; then + echo "::error::CHANGELOG.md has no section for $version" + exit 1 + fi + cat notes.md + + - name: Publish + env: + GH_TOKEN: ${{ github.token }} + run: gh release create "$GITHUB_REF_NAME" dist/* --verify-tag --title "bench51 $GITHUB_REF_NAME" --notes-file notes.md + + # Installs the published release exactly as the README tells people to. + verify: + name: install on ${{ matrix.os }} + needs: publish + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + runs-on: ${{ matrix.os }} + steps: + - name: One-line install + if: runner.os != 'Windows' + run: | + curl -fsSL "https://raw.githubusercontent.com/$GITHUB_REPOSITORY/$GITHUB_REF_NAME/install.sh" | sh + "$HOME/.local/bin/bench51" --version | grep -F "${GITHUB_REF_NAME#v}" + "$HOME/.local/bin/bench51-gui" --version | grep -F "${GITHUB_REF_NAME#v}" + + - name: One-line install + if: runner.os == 'Windows' + shell: pwsh + run: | + irm "https://raw.githubusercontent.com/$env:GITHUB_REPOSITORY/$env:GITHUB_REF_NAME/install.ps1" | iex + $version = & "$env:LOCALAPPDATA\Programs\bench51\bench51.exe" --version + if ($version -notmatch [regex]::Escape($env:GITHUB_REF_NAME.TrimStart('v'))) { exit 1 } + if (-not (Test-Path "$([Environment]::GetFolderPath('Programs'))\bench51.lnk")) { exit 1 } diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..7748b03 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,44 @@ +# Changelog + +All notable changes to bench51. The format follows +[Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and versions follow +[Semantic Versioning](https://semver.org/). + +## [0.2.0] - 2026-11-01 + +### Added + +- **bench51-gui**, a desktop IDE laid out like Keil µVision: menus, toolbar, + Project window, editor with breakpoint and error gutter, Build Output, and + in a debug session the Registers, Disassembly, Memory, Symbols, UART #1, + Ports, Timers and Interrupts windows. Windows dock and tab anywhere; the + edit and debug layouts are remembered separately. +- Monochrome, dot-matrix design in dark and light themes (follows the + system by default), with Space Grotesk, Space Mono and Doto bundled. +- µVision's keys (F7, Ctrl-F5, F5, F10/F11, Ctrl-F10/F11, F9) with the + TUI's as aliases; find (Ctrl-F); inline memory editing; clickable SFR + bits and port pins; drag-and-drop to open files. +- Prebuilt releases for Linux (x86_64, aarch64), Windows (x86_64) and macOS + (Apple silicon, Intel), with one-line installers: `install.sh` for Linux + and macOS, `install.ps1` for Windows. +- CI on Linux, Windows and macOS. + +### Changed + +- The assembler, simulator and debugger session moved into a shared + `bench51-core` crate used by both front ends. The terminal app behaves + as before. +- Unsafe code is forbidden across the workspace. + +## [0.1.0] - 2026-10-23 + +### Added + +- `bench51`, a terminal (TUI) 8051 IDE: editor, two-pass assembler for the + full instruction set with Keil-style listing and Intel HEX output, + simulator with timers, interrupts, UART and ports, and a debugger with + breakpoints, stepping and memory poke. +- Headless assembly with `bench51 --assemble`. +- Opening Intel HEX files as disassembled, re-assemblable source. + +[0.2.0]: https://github.com/krolyxon/bench51/releases/tag/v0.2.0 diff --git a/Cargo.lock b/Cargo.lock index b5d592a..9511814 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -485,7 +485,7 @@ checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" [[package]] name = "bench51" -version = "0.1.0" +version = "0.2.0" dependencies = [ "bench51-core", "clap", @@ -495,11 +495,11 @@ dependencies = [ [[package]] name = "bench51-core" -version = "0.1.0" +version = "0.2.0" [[package]] name = "bench51-gui" -version = "0.1.0" +version = "0.2.0" dependencies = [ "bench51-core", "clap", diff --git a/Cargo.toml b/Cargo.toml index 6e91347..ef8e648 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ members = ["crates/*"] [workspace.package] -version = "0.1.0" +version = "0.2.0" edition = "2024" [workspace.lints.rust] diff --git a/README.md b/README.md index c06f301..5e360f4 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,13 @@ # bench51 — an 8051 assembler, simulator & debugger [![CI](https://img.shields.io/github/actions/workflow/status/krolyxon/bench51/ci.yml?branch=master&style=flat-square&label=CI&labelColor=000000)](https://github.com/krolyxon/bench51/actions/workflows/ci.yml) -[![Version](https://img.shields.io/badge/dynamic/toml?url=https%3A%2F%2Fraw.githubusercontent.com%2Fkrolyxon%2Fbench51%2Fmaster%2FCargo.toml&query=%24.workspace.package.version&label=version&style=flat-square&labelColor=000000&color=333333)](Cargo.toml) +[![Release](https://img.shields.io/github/v/release/krolyxon/bench51?style=flat-square&label=release&labelColor=000000&color=333333)](https://github.com/krolyxon/bench51/releases/latest) +[![Downloads](https://img.shields.io/github/downloads/krolyxon/bench51/total?style=flat-square&labelColor=000000&color=333333)](https://github.com/krolyxon/bench51/releases) [![Top language](https://img.shields.io/github/languages/top/krolyxon/bench51?style=flat-square&logo=rust&logoColor=white&labelColor=000000&color=333333)](https://github.com/krolyxon/bench51) [![Lines of code](https://img.shields.io/badge/lines%20of%20code-9.8k-333333?style=flat-square&labelColor=000000)](crates) [![unsafe forbidden](https://img.shields.io/badge/unsafe-forbidden-333333?style=flat-square&labelColor=000000)](Cargo.toml) [![License](https://img.shields.io/github/license/krolyxon/bench51?style=flat-square&labelColor=000000&color=333333)](LICENSE) -[![Platforms](https://img.shields.io/badge/platform-Linux%20%7C%20Windows%20%7C%20macOS-333333?style=flat-square&labelColor=000000)](#usage) +[![Platforms](https://img.shields.io/badge/platform-Linux%20%7C%20Windows%20%7C%20macOS-333333?style=flat-square&labelColor=000000)](#install) [![Target](https://img.shields.io/badge/target-Intel%208051%20%28MCS--51%29-D71921?style=flat-square&labelColor=000000)](https://en.wikipedia.org/wiki/Intel_8051) [![egui](https://img.shields.io/badge/GUI-egui-333333?style=flat-square&labelColor=000000)](https://github.com/emilk/egui) [![ratatui](https://img.shields.io/badge/TUI-ratatui-333333?style=flat-square&labelColor=000000)](https://ratatui.rs) @@ -88,32 +89,57 @@ Linux, in a window or right in the terminal. - **Dark and light themes** in a monochrome, dot-matrix design (Space Grotesk, Space Mono and Doto, bundled). -## Usage +## Install + +Linux and macOS: ```bash -cargo install --path crates/bench51-gui # installs `bench51-gui` +curl -fsSL https://raw.githubusercontent.com/krolyxon/bench51/master/install.sh | sh +``` + +Windows (PowerShell): -cargo run --release -p bench51-gui # welcome screen -cargo run --release -p bench51-gui -- examples/*.asm # open several files -cargo run --release -p bench51-gui -- firmware.hex # disassemble & debug a HEX file -cargo run --release -p bench51-gui -- --theme light +```powershell +irm https://raw.githubusercontent.com/krolyxon/bench51/master/install.ps1 | iex ``` -`--theme system|dark|light` overrides the theme chosen in View → Theme, and -`--clock ` the Xtal set in Project → Options for Target (default -11.0592), which is used for the elapsed-time display. +Both install `bench51-gui` and `bench51` from the +[latest release](https://github.com/krolyxon/bench51/releases/latest) and +verify the download against its SHA-256 checksum: -On Linux it runs on Wayland and X11 and uses the XDG desktop portal for file -dialogs. To add it to your application launcher: +- **Linux and macOS:** the binaries go into `~/.local/bin`, and on Linux the + app is added to your application menu. Options go after `sh -s --`: + `--version v0.2.0` pins a release, `--dir /usr/local/bin` picks another + directory, `--archive ` installs a downloaded archive offline + (handy on lab PCs), and `--uninstall` removes it. +- **Windows:** it installs to `%LOCALAPPDATA%\Programs\bench51`, adds that to + your PATH and adds a Start menu entry. `-Uninstall` removes it. + +Prebuilt binaries cover Linux (x86_64, aarch64), Windows (x86_64) and macOS +(Apple silicon, Intel). To build from source instead, with a Rust toolchain: ```bash -install -Dm644 crates/bench51-gui/assets/bench51-gui.desktop ~/.local/share/applications/bench51-gui.desktop -install -Dm644 crates/bench51-gui/assets/bench51-gui.svg ~/.local/share/icons/hicolor/scalable/apps/bench51-gui.svg +cargo install --locked --git https://github.com/krolyxon/bench51 bench51-gui # the desktop app +cargo install --locked --git https://github.com/krolyxon/bench51 bench51 # the terminal app ``` -It also builds for Windows and macOS. On Debian or Ubuntu, first install the -packages egui needs: `libxcb-render0-dev libxcb-shape0-dev -libxcb-xfixes0-dev libxkbcommon-dev libssl-dev`. +## Usage + +```bash +bench51-gui # welcome screen +bench51-gui examples/*.asm # open several files +bench51-gui firmware.hex # disassemble & debug a HEX file +bench51-gui --theme light +``` + +`--theme system|dark|light` overrides the theme chosen in View → Theme, and +`--clock ` the Xtal set in Project → Options for Target (default +11.0592), which is used for the elapsed-time display. + +On Linux it runs on Wayland and X11 and uses the XDG desktop portal for file +dialogs. Building it from source on Debian or Ubuntu needs the packages egui +links against: `libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev +libxkbcommon-dev libssl-dev`. ## Keys @@ -168,15 +194,13 @@ Makefiles. ```bash -cargo install --path . # installs the `bench51` binary - -cargo run --release -- examples/serial_hello.asm # open in the TUI -cargo run --release # start with a template -cargo run --release -- firmware.hex # disassemble & debug a HEX file +bench51 examples/serial_hello.asm # open in the TUI +bench51 # start with a template +bench51 firmware.hex # disassemble & debug a HEX file # Headless assembly: writes prog.hex and prog.lst -cargo run --release -- --assemble prog.asm -cargo run --release -- --assemble prog.asm -o out.hex --lst out.lst +bench51 --assemble prog.asm +bench51 --assemble prog.asm -o out.hex --lst out.lst ``` `--clock ` sets the oscillator frequency used for the elapsed-time display @@ -235,10 +259,24 @@ Letter shortcuts work too, for terminals that swallow function keys: ## Development ```bash -cargo test --workspace # assembler, CPU, peripheral, session and example-program tests +cargo run --release -p bench51-gui # the desktop app +cargo run --release -p bench51 # the terminal app +cargo test --workspace # assembler, CPU, peripheral, session and example-program tests cargo clippy --workspace --all-targets ``` +Releasing: bump `version` in `Cargo.toml`, add a section to +[CHANGELOG.md](CHANGELOG.md), merge, then tag and push: + +```bash +git tag v0.3.0 && git push origin v0.3.0 +``` + +The release workflow checks that the tag matches `Cargo.toml` and builds +every target. It publishes the archives and `SHA256SUMS` with that +changelog section as the release notes, then installs the result with the +one-liners on Linux, macOS and Windows. + Code layout: - `crates/bench51-gui/` is the `bench51-gui` desktop app (egui). diff --git a/install.ps1 b/install.ps1 new file mode 100644 index 0000000..9ab0a8d --- /dev/null +++ b/install.ps1 @@ -0,0 +1,112 @@ +# Installs bench51 (the bench51-gui desktop app and the bench51 terminal app) +# from the GitHub releases, on Windows. +# +# irm https://raw.githubusercontent.com/krolyxon/bench51/master/install.ps1 | iex +# +# With options: +# +# & ([scriptblock]::Create((irm https://raw.githubusercontent.com/krolyxon/bench51/master/install.ps1))) -Version v0.2.0 +# +# Options: -Version (default latest), -InstallDir (default +# %LOCALAPPDATA%\Programs\bench51), -Archive .zip>, +# -NoShortcut, -Uninstall. BENCH51_VERSION and BENCH51_INSTALL_DIR set the +# defaults for -Version and -InstallDir when piping into iex. + +param( + [string]$Version = $(if ($env:BENCH51_VERSION) { $env:BENCH51_VERSION } else { 'latest' }), + [string]$InstallDir = $(if ($env:BENCH51_INSTALL_DIR) { $env:BENCH51_INSTALL_DIR } else { Join-Path $env:LOCALAPPDATA 'Programs\bench51' }), + [string]$Archive, + [switch]$NoShortcut, + [switch]$Uninstall +) + +$ErrorActionPreference = 'Stop' +# Invoke-WebRequest is much slower with the progress bar on. +$ProgressPreference = 'SilentlyContinue' +[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 + +$Repo = 'krolyxon/bench51' +$Asset = 'bench51-x86_64-pc-windows-msvc.zip' +$Shortcut = Join-Path ([Environment]::GetFolderPath('Programs')) 'bench51.lnk' + +function Write-Step([string]$Message) { + Write-Host "bench51: $Message" +} + +# Adds or removes $Dir in the user's PATH. +function Edit-UserPath([string]$Dir, [bool]$Add) { + $current = [Environment]::GetEnvironmentVariable('Path', 'User') + $parts = @(($current -split ';') | Where-Object { $_ -and ($_.TrimEnd('\') -ne $Dir.TrimEnd('\')) }) + if ($Add) { + $parts += $Dir + } + [Environment]::SetEnvironmentVariable('Path', ($parts -join ';'), 'User') +} + +if ($Uninstall) { + Remove-Item -Recurse -Force -ErrorAction SilentlyContinue $InstallDir + Remove-Item -Force -ErrorAction SilentlyContinue $Shortcut + Edit-UserPath $InstallDir $false + Write-Step "removed bench51 from $InstallDir" + return +} + +$Temp = Join-Path ([IO.Path]::GetTempPath()) ("bench51-" + [guid]::NewGuid()) +New-Item -ItemType Directory -Path $Temp | Out-Null +try { + if (-not $Archive) { + if ($Version -eq 'latest') { + $Base = "https://github.com/$Repo/releases/latest/download" + } else { + if (-not $Version.StartsWith('v')) { + $Version = "v$Version" + } + $Base = "https://github.com/$Repo/releases/download/$Version" + } + Write-Step "downloading $Asset ($Version)" + $Archive = Join-Path $Temp $Asset + $Sums = Join-Path $Temp 'SHA256SUMS' + Invoke-WebRequest -UseBasicParsing -Uri "$Base/$Asset" -OutFile $Archive + Invoke-WebRequest -UseBasicParsing -Uri "$Base/SHA256SUMS" -OutFile $Sums + $line = Get-Content $Sums | Where-Object { $_ -match ('\s\*?' + [regex]::Escape($Asset) + '$') } | Select-Object -First 1 + if (-not $line) { + throw "$Asset is not listed in SHA256SUMS" + } + $expected = ($line -split '\s+')[0].ToLowerInvariant() + $actual = (Get-FileHash -Algorithm SHA256 -Path $Archive).Hash.ToLowerInvariant() + if ($actual -ne $expected) { + throw "checksum mismatch for $Asset" + } + } + if (-not (Test-Path $Archive)) { + throw "no such archive: $Archive" + } + + $Extracted = Join-Path $Temp 'x' + Expand-Archive -Path $Archive -DestinationPath $Extracted -Force + $gui = Get-ChildItem -Path $Extracted -Recurse -Filter 'bench51-gui.exe' | Select-Object -First 1 + if (-not $gui) { + throw 'the archive has no bench51-gui.exe' + } + + New-Item -ItemType Directory -Force -Path $InstallDir | Out-Null + Copy-Item -Path (Join-Path $gui.DirectoryName '*') -Destination $InstallDir -Recurse -Force + Edit-UserPath $InstallDir $true + $env:Path = "$env:Path;$InstallDir" + Write-Step "installed bench51 and bench51-gui to $InstallDir" + + if (-not $NoShortcut) { + $shell = New-Object -ComObject WScript.Shell + $link = $shell.CreateShortcut($Shortcut) + $link.TargetPath = Join-Path $InstallDir 'bench51-gui.exe' + $link.WorkingDirectory = $env:USERPROFILE + $link.Description = 'Intel 8051 assembler, simulator and debugger' + $link.Save() + Write-Step 'added bench51 to the Start menu' + } + + & (Join-Path $InstallDir 'bench51.exe') --version + Write-Step 'open a new terminal to use bench51 and bench51-gui from PATH' +} finally { + Remove-Item -Recurse -Force -ErrorAction SilentlyContinue $Temp +} diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..38d8b3a --- /dev/null +++ b/install.sh @@ -0,0 +1,167 @@ +#!/bin/sh +# Installs bench51 (the bench51-gui desktop app and the bench51 terminal app) +# from the GitHub releases, on Linux and macOS. +# +# curl -fsSL https://raw.githubusercontent.com/krolyxon/bench51/master/install.sh | sh +# curl -fsSL https://raw.githubusercontent.com/krolyxon/bench51/master/install.sh | sh -s -- --dir /usr/local/bin +# +# Run with --help for all options. On Windows, use install.ps1. + +set -eu + +REPO=krolyxon/bench51 +VERSION=${BENCH51_VERSION:-latest} +DIR=${BENCH51_INSTALL_DIR:-$HOME/.local/bin} +ARCHIVE= +DESKTOP=1 +UNINSTALL=0 + +DATA=${XDG_DATA_HOME:-$HOME/.local/share} +APPS=$DATA/applications +ICONS=$DATA/icons/hicolor/scalable/apps + +usage() { + cat < release to install, e.g. v0.2.0 (default: latest) + --dir where to put the binaries (default: ~/.local/bin) + --archive install from a downloaded bench51-.tar.gz + --no-desktop on Linux, skip the application menu entry and icon + --uninstall remove bench51 from --dir and the menu + -h, --help show this help + +The environment variables BENCH51_VERSION and BENCH51_INSTALL_DIR set the +defaults for --version and --dir. +EOF +} + +say() { printf 'bench51: %s\n' "$*"; } +die() { + printf 'bench51: error: %s\n' "$*" >&2 + exit 1 +} + +while [ $# -gt 0 ]; do + case $1 in + --version) [ $# -ge 2 ] || die "--version needs a value"; VERSION=$2; shift 2 ;; + --version=*) VERSION=${1#*=}; shift ;; + --dir) [ $# -ge 2 ] || die "--dir needs a value"; DIR=$2; shift 2 ;; + --dir=*) DIR=${1#*=}; shift ;; + --archive) [ $# -ge 2 ] || die "--archive needs a value"; ARCHIVE=$2; shift 2 ;; + --archive=*) ARCHIVE=${1#*=}; shift ;; + --no-desktop) DESKTOP=0; shift ;; + --uninstall) UNINSTALL=1; shift ;; + -h | --help) usage; exit 0 ;; + *) die "unknown option: $1 (see --help)" ;; + esac +done + +refresh_menu() { + if command -v update-desktop-database >/dev/null 2>&1; then + update-desktop-database -q "$APPS" 2>/dev/null || true + fi +} + +if [ "$UNINSTALL" = 1 ]; then + rm -f "$DIR/bench51" "$DIR/bench51-gui" "$APPS/bench51-gui.desktop" "$ICONS/bench51-gui.svg" + refresh_menu + say "removed bench51 from $DIR" + exit 0 +fi + +# ---- Which build fits this machine ---- + +os=$(uname -s) +arch=$(uname -m) +case $os in +Linux) os=unknown-linux-gnu ;; +Darwin) os=apple-darwin ;; +*) die "no prebuilt binaries for $os; on Windows use install.ps1" ;; +esac +case $arch in +x86_64 | amd64) arch=x86_64 ;; +aarch64 | arm64) arch=aarch64 ;; +*) die "no prebuilt binaries for $arch; build from source with: cargo install --git https://github.com/$REPO bench51-gui" ;; +esac +TARGET=$arch-$os +NAME=bench51-$TARGET.tar.gz + +download() { + if command -v curl >/dev/null 2>&1; then + curl --proto '=https' --tlsv1.2 -fsSL -o "$2" "$1" + elif command -v wget >/dev/null 2>&1; then + wget -q --https-only -O "$2" "$1" + else + die "neither curl nor wget is installed" + fi +} + +sha256() { + if command -v sha256sum >/dev/null 2>&1; then + sha256sum "$1" | cut -d ' ' -f 1 + elif command -v shasum >/dev/null 2>&1; then + shasum -a 256 "$1" | cut -d ' ' -f 1 + else + die "neither sha256sum nor shasum is installed to verify the download" + fi +} + +TMP=$(mktemp -d 2>/dev/null || mktemp -d -t bench51) +trap 'rm -rf "$TMP"' EXIT +trap 'exit 130' INT TERM + +# ---- Download and verify ---- + +if [ -z "$ARCHIVE" ]; then + if [ "$VERSION" = latest ]; then + BASE=https://github.com/$REPO/releases/latest/download + else + case $VERSION in v*) ;; *) VERSION=v$VERSION ;; esac + BASE=https://github.com/$REPO/releases/download/$VERSION + fi + say "downloading $NAME ($VERSION)" + download "$BASE/$NAME" "$TMP/$NAME" || die "could not download $BASE/$NAME" + download "$BASE/SHA256SUMS" "$TMP/SHA256SUMS" || die "could not download the checksums" + expected=$(grep " [* ]*$NAME\$" "$TMP/SHA256SUMS" | cut -d ' ' -f 1) + [ -n "$expected" ] || die "$NAME is not listed in SHA256SUMS" + [ "$(sha256 "$TMP/$NAME")" = "$expected" ] || die "checksum mismatch for $NAME" + ARCHIVE=$TMP/$NAME +fi +[ -f "$ARCHIVE" ] || die "no such archive: $ARCHIVE" + +mkdir "$TMP/x" +tar -xzf "$ARCHIVE" -C "$TMP/x" +SRC=$(find "$TMP/x" -type f -name bench51-gui | head -n 1) +[ -n "$SRC" ] || die "the archive has no bench51-gui" +SRC=$(dirname "$SRC") +[ -f "$SRC/bench51" ] || die "the archive has no bench51" + +# ---- Install ---- + +mkdir -p "$DIR" +for bin in bench51 bench51-gui; do + cp "$SRC/$bin" "$DIR/$bin.tmp" + chmod 755 "$DIR/$bin.tmp" + mv -f "$DIR/$bin.tmp" "$DIR/$bin" +done +say "installed bench51 and bench51-gui to $DIR" + +if [ "$DESKTOP" = 1 ] && [ "$(uname -s)" = Linux ] && [ -f "$SRC/share/applications/bench51-gui.desktop" ]; then + mkdir -p "$APPS" "$ICONS" + # Launchers don't always see ~/.local/bin on PATH: point at the binary. + exec_path=$(printf '%s' "$DIR/bench51-gui" | sed 's/[\\&|]/\\&/g') + sed "s|^Exec=bench51-gui|Exec=\"$exec_path\"|" \ + "$SRC/share/applications/bench51-gui.desktop" >"$APPS/bench51-gui.desktop" + cp "$SRC/share/icons/hicolor/scalable/apps/bench51-gui.svg" "$ICONS/bench51-gui.svg" + refresh_menu + say "added bench51 to the application menu" +fi + +"$DIR/bench51" --version +case ":$PATH:" in +*":$DIR:"*) say "run bench51-gui for the desktop app, or bench51 in a terminal" ;; +*) say "$DIR is not on your PATH; add it, e.g. in ~/.profile: export PATH=\"$DIR:\$PATH\"" ;; +esac