#!/usr/bin/env bash
# ghrelnotes REL - generate github release notes for REL.   -*- markdown -*-

cd "$(dirname $0)"

cat <<'END'

<details>
<summary>

## Release notes

</summary>

END

export REL=$1
# extract REL notes from relnotes.md
awk "/^## .*-${REL//./'\.'}$/{p=1;next} /^## /{p=0} p" relnotes.md

envsubst '$REL' <<'END'
</details>

<details>
<summary>

## Install

</summary>

The [hledger Install page](https://hledger.org/install) lists the easiest ways to install a recent release,
such as `brew` on macos, `choco`/`scoop`/`winget` on Windows, or `eget` on all platforms.

Or, follow these instructions to install the specific release binaries below:


Updates to binaries:
- 2026-01-12: Fixed the hledger-linux-x64.tar.gz asset below, it previously contained a dev build. [#2526](https://github.com/hledgerorg/hledger/issues/2526)
<!--
-->

<!--
If github releases are immutable, they can be verified as follows:

```
gh --version  # ensure you have github CLI 2.81.0+
gh release verify $REL  # check the $REL github release is immutable
curl -fLO https://github.com/hledgerorg/hledger/releases/download/$REL/hledger-linux-x64.tar.gz  # eg
gh release verify-asset $REL ./hledger-linux-x64.tar.gz  # check the tarball is correct
tar xzv -f hledger-linux-x64.tar.gz -C/usr/local/bin hledger hledger-ui hledger-web
```
-->

### GNU/Linux, 64-bit Intel

At the command line:

```
curl -fL https://github.com/hledgerorg/hledger/releases/download/$REL/hledger-linux-x64.tar.gz | tar -xzv -f- -C/usr/local/bin hledger hledger-ui hledger-web
hledger --version; hledger-ui --version; hledger-web --version    # should show $REL
```

Prefix `tar` with `sudo` if `/usr/local/bin` is not writable.

### Mac, 64-bit ARM or Intel

Open a terminal window.
(Don't download these binaries with your web browser - they won't get authorised.)

On ARM macs:
```
sudo mkdir -p /usr/local/bin
curl -fL https://github.com/hledgerorg/hledger/releases/download/$REL/hledger-mac-arm64.tar.gz | sudo tar -xzv -f- -C/usr/local/bin hledger hledger-ui hledger-web
hledger --version; hledger-ui --version; hledger-web --version    # should show $REL
```

On Intel macs:
```
sudo mkdir -p /usr/local/bin
curl -fL https://github.com/hledgerorg/hledger/releases/download/$REL/hledger-mac-x64.tar.gz | sudo tar -xzv -f- -C/usr/local/bin hledger hledger-ui hledger-web
hledger --version; hledger-ui --version; hledger-web --version    # should show $REL
```

If the version check shows an older version, you have another hledger earlier in `$PATH`; `which -a hledger` will find it.

### Windows, 64-bit ARM or Intel

In a powershell window (press `WINDOWS-R`, `powershell`, `ENTER`).
(Don't download the zip with your web browser - programs downloaded that way may be blocked when you run them.)

```
cd ~
curl.exe -fLO https://github.com/hledgerorg/hledger/releases/download/$REL/hledger-windows-x64.zip
Expand-Archive hledger-windows-x64.zip -Force -DestinationPath "$env:LOCALAPPDATA\Programs\hledger"
```

`$env:LOCALAPPDATA\Programs\hledger` (ie `C:\Users\YOURNAME\AppData\Local\Programs\hledger`) is not in `$env:Path` by default,
so if `$env:Path` doesn't show it, add it once:
```
[Environment]::SetEnvironmentVariable('Path', "$env:LOCALAPPDATA\Programs\hledger;" + [Environment]::GetEnvironmentVariable('Path','User'), 'User')
$env:Path = "$env:LOCALAPPDATA\Programs\hledger;$env:Path"    # for this window; new windows will pick it up automatically
```

Then:
```
hledger --version; hledger-ui --version; hledger-web --version    # should show $REL
```

If the version check shows an older version, you have another hledger earlier in `$env:Path`; `where.exe hledger` will find it.

These are 64-bit Intel binaries; they also run on ARM machines (emulated).

They may also work on Windows 7:
use Windows Explorer to extract `hledger-windows-x64.zip` into a folder of your choice,
then open a command window (`WINDOWS-R`, `cmd`, `ENTER`) and run the hledger programs.

<!--
And ensure a default journal file exists, and without a problematic encoding (I'm not sure if/why "ascii" was needed here).
This will allow you to start hledger-web by double-clicking on its icon if you wish.
```
out-file -append -encoding ascii $HOME/.hledger.journal
```
-->

### Next steps
Once installed, run `hledger`,
and see the [hledger Docs](https://hledger.org/doc.html).

</details>
END
