Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ builds:
goos: [darwin]
goarch: [arm64, amd64]

# The name has no version, so that the link of the latest release works in
# the curl command of the README:
# https://github.com/frinfo702/rexdiff/releases/latest/download/rexdiff-darwin-arm64.tar.gz
# update/update.go builds the same name.
archives:
- formats: [tar.gz]
name_template: "{{ .ProjectName }}-v{{ .Version }}-{{ .Os }}-{{ .Arch }}"
name_template: "{{ .ProjectName }}-{{ .Os }}-{{ .Arch }}"

checksum:
name_template: sha256sums.txt
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ brew trust frinfo702/rexdiff
brew install --cask rexdiff
```

With curl:

```sh
curl -fsSL https://raw.githubusercontent.com/frinfo702/rexdiff/main/install.sh | sh
```

The script downloads the release for this Mac, checks its checksum, and puts
the binary in `~/.local/bin`, or in `REXDIFF_BIN_DIR`. It also says how to add
the directory to `PATH` if it is not there.

With Go:

```sh
Expand Down
54 changes: 54 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/sh
# install.sh installs the latest rexdiff release for this Mac:
#
# curl -fsSL https://raw.githubusercontent.com/frinfo702/rexdiff/main/install.sh | sh
#
# It puts the binary in ~/.local/bin, or in REXDIFF_BIN_DIR, and checks the
# checksum of the archive.

set -eu

repo=frinfo702/rexdiff
base="https://github.com/$repo/releases/latest/download"
dir=${REXDIFF_BIN_DIR:-"$HOME/.local/bin"}

fail() {
printf 'install.sh: %s\n' "$*" >&2
exit 1
}

[ "$(uname -s)" = Darwin ] || fail "rexdiff runs on macOS only"

case $(uname -m) in
arm64) arch=arm64 ;;
x86_64) arch=amd64 ;;
*) fail "unsupported machine: $(uname -m)" ;;
esac

name="rexdiff-darwin-$arch.tar.gz"
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT HUP INT TERM

curl -fsSL "$base/$name" -o "$tmp/$name" ||
fail "cannot download $base/$name"
curl -fsSL "$base/sha256sums.txt" -o "$tmp/sha256sums.txt" ||
fail "cannot download $base/sha256sums.txt"

want=$(awk -v name="$name" '$2 == name { print $1 }' "$tmp/sha256sums.txt")
[ -n "$want" ] || fail "the checksums have no $name"
got=$(shasum -a 256 "$tmp/$name" | awk '{ print $1 }')
[ "$want" = "$got" ] || fail "$name does not match its checksum"

tar -xzf "$tmp/$name" -C "$tmp" rexdiff || fail "cannot unpack $name"
mkdir -p "$dir"
install -m 0755 "$tmp/rexdiff" "$dir/.rexdiff-new"
mv -f "$dir/.rexdiff-new" "$dir/rexdiff"
printf 'installed %s\n' "$dir/rexdiff"

case ":$PATH:" in
*":$dir:"*) ;;
*)
printf 'add %s to PATH, for example in ~/.zshrc:\n' "$dir"
printf ' export PATH="%s:$PATH"\n' "$dir"
;;
esac
2 changes: 1 addition & 1 deletion update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func lastLine(out []byte) string {
// checksums of r, and puts its binary in place of the file that u.bin
// links to.
func (u *Updater) download(ctx context.Context, r Release) error {
name := fmt.Sprintf("rexdiff-%s-%s-%s.tar.gz", r.Tag, runtime.GOOS, runtime.GOARCH)
name := fmt.Sprintf("rexdiff-%s-%s.tar.gz", runtime.GOOS, runtime.GOARCH)
archiveURL, sumsURL := assetURL(r, name), assetURL(r, "sha256sums.txt")
if archiveURL == "" || sumsURL == "" {
return fmt.Errorf("release %s has no %s or sha256sums.txt", r.Tag, name)
Expand Down
2 changes: 1 addition & 1 deletion update/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func archive(t *testing.T, content string) []byte {
// TestDownload checks the download of a release: the checksum, the binary
// in the archive, and the replacement of the target file of a link.
func TestDownload(t *testing.T) {
name := fmt.Sprintf("rexdiff-v0.2.0-%s-%s.tar.gz", runtime.GOOS, runtime.GOARCH)
name := fmt.Sprintf("rexdiff-%s-%s.tar.gz", runtime.GOOS, runtime.GOARCH)
good := archive(t, "new binary")
sum := sha256.Sum256(good)
files := map[string][]byte{
Expand Down
Loading