Skip to content

Commit 346fc47

Browse files
authored
chore: Add install script for prebuilt binaries
2 parents cbd1d15 + 7add27d commit 346fc47

4 files changed

Lines changed: 172 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.9.0] - 2026-03-15
9+
10+
### Added
11+
- `install.sh` script for downloading and installing prebuilt binaries with checksum verification
12+
813
## [0.8.0] - 2026-03-15
914

1015
### Added
@@ -102,6 +107,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
102107
### Added
103108
- Initial release
104109

110+
[0.9.0]: https://github.com/gooddata/gooddata-goodmock/compare/v0.8.0...v0.9.0
105111
[0.8.0]: https://github.com/gooddata/gooddata-goodmock/compare/v0.7.0...v0.8.0
106112
[0.7.0]: https://github.com/gooddata/gooddata-goodmock/compare/v0.6.0...v0.7.0
107113
[0.6.0]: https://github.com/gooddata/gooddata-goodmock/compare/v0.5.1...v0.6.0

README.md

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,30 @@ A lightweight, high-performance mock server written in Go, powered by [fasthttp]
1111
- Detailed mismatch logging (WireMock-style diagnostics)
1212
- Minimal Docker image (built from `scratch`)
1313

14-
## Installation
14+
## Install
15+
16+
```bash
17+
# latest version
18+
curl -fsSL https://raw.githubusercontent.com/gooddata/gooddata-goodmock/master/install.sh | sh
19+
20+
# specific version
21+
curl -fsSL https://raw.githubusercontent.com/gooddata/gooddata-goodmock/master/install.sh | sh -s v0.9.0
22+
23+
# custom install directory
24+
curl -fsSL https://raw.githubusercontent.com/gooddata/gooddata-goodmock/master/install.sh | BINDIR=~/.local/bin sh
25+
```
26+
27+
Or run locally:
28+
29+
```bash
30+
BINDIR=~/.local/bin ./install.sh v0.9.0
31+
```
1532

1633
### Docker
1734

1835
```bash
19-
docker build -t goodmock .
20-
docker run -p 8080:8080 goodmock
36+
docker pull gooddata/gooddata-goodmock:latest
37+
docker run -p 8080:8080 gooddata/gooddata-goodmock:latest
2138
```
2239

2340
### Building from Source
@@ -32,8 +49,10 @@ go build -o goodmock .
3249

3350
## Usage
3451

35-
```
52+
```bash
3653
goodmock <mode>
54+
goodmock -v # print version
55+
goodmock --version # print version
3756
```
3857

3958
### Modes

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.8.0
1+
0.9.0

install.sh

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
#!/bin/sh
2+
set -e
3+
4+
OWNER="gooddata"
5+
REPO="gooddata-goodmock"
6+
BINARY="goodmock"
7+
BINDIR="${BINDIR:-/usr/local/bin}"
8+
9+
usage() {
10+
cat <<EOF
11+
Usage: $0 [version]
12+
13+
Install ${BINARY} binary.
14+
15+
[version] Tag to install (e.g. v0.2.5). Defaults to latest release.
16+
17+
Environment:
18+
BINDIR Installation directory (default: /usr/local/bin)
19+
20+
Examples:
21+
$0 # install latest
22+
$0 v0.2.5 # install specific version
23+
BINDIR=~/.local/bin $0
24+
EOF
25+
exit 2
26+
}
27+
28+
case "${1:-}" in
29+
-h|--help) usage ;;
30+
esac
31+
32+
# --- detect os/arch ---
33+
34+
detect_os() {
35+
os=$(uname -s | tr '[:upper:]' '[:lower:]')
36+
case "$os" in
37+
darwin|linux) ;;
38+
mingw*|msys*|cygwin*) os="windows" ;;
39+
*) echo "error: unsupported OS: $os" >&2; exit 1 ;;
40+
esac
41+
echo "$os"
42+
}
43+
44+
detect_arch() {
45+
arch=$(uname -m)
46+
case "$arch" in
47+
x86_64|amd64) arch="amd64" ;;
48+
arm64|aarch64) arch="arm64" ;;
49+
*) echo "error: unsupported architecture: $arch" >&2; exit 1 ;;
50+
esac
51+
echo "$arch"
52+
}
53+
54+
# --- resolve version ---
55+
56+
resolve_version() {
57+
if [ -n "${1:-}" ]; then
58+
echo "$1"
59+
return
60+
fi
61+
# GitHub redirects /releases/latest to the latest tag; grab it from the JSON response
62+
tag=$(curl -sSL "https://api.github.com/repos/${OWNER}/${REPO}/releases/latest" \
63+
| grep '"tag_name"' | head -1 | sed 's/.*"tag_name": *"//;s/".*//')
64+
if [ -z "$tag" ]; then
65+
echo "error: could not determine latest release" >&2
66+
exit 1
67+
fi
68+
echo "$tag"
69+
}
70+
71+
# --- download helpers ---
72+
73+
download() {
74+
if command -v curl >/dev/null 2>&1; then
75+
curl -fsSL -o "$1" "$2"
76+
elif command -v wget >/dev/null 2>&1; then
77+
wget -qO "$1" "$2"
78+
else
79+
echo "error: curl or wget required" >&2
80+
exit 1
81+
fi
82+
}
83+
84+
verify_checksum() {
85+
target="$1"
86+
checksum_file="$2"
87+
want=$(cut -d ' ' -f 1 < "$checksum_file")
88+
if command -v sha256sum >/dev/null 2>&1; then
89+
got=$(sha256sum "$target" | cut -d ' ' -f 1)
90+
elif command -v shasum >/dev/null 2>&1; then
91+
got=$(shasum -a 256 "$target" | cut -d ' ' -f 1)
92+
else
93+
echo "error: no sha256 tool found (need sha256sum or shasum), cannot verify download" >&2
94+
exit 1
95+
fi
96+
if [ "$want" != "$got" ]; then
97+
echo "error: checksum mismatch" >&2
98+
echo " expected: $want" >&2
99+
echo " got: $got" >&2
100+
exit 1
101+
fi
102+
}
103+
104+
# --- main ---
105+
106+
OS=$(detect_os)
107+
ARCH=$(detect_arch)
108+
VERSION=$(resolve_version "${1:-}")
109+
110+
case "$OS" in
111+
windows) ext="zip" ;;
112+
*) ext="tar.gz" ;;
113+
esac
114+
115+
asset="${BINARY}-${OS}-${ARCH}.${ext}"
116+
base_url="https://github.com/${OWNER}/${REPO}/releases/download/${VERSION}"
117+
118+
tmpdir=$(mktemp -d)
119+
trap 'rm -rf "$tmpdir"' EXIT
120+
121+
echo "Installing ${BINARY} ${VERSION} (${OS}/${ARCH})..."
122+
123+
download "${tmpdir}/${asset}" "${base_url}/${asset}"
124+
download "${tmpdir}/${asset}.sha256" "${base_url}/${asset}.sha256"
125+
verify_checksum "${tmpdir}/${asset}" "${tmpdir}/${asset}.sha256"
126+
127+
# extract
128+
case "$ext" in
129+
tar.gz) tar -xzf "${tmpdir}/${asset}" -C "$tmpdir" ;;
130+
zip) unzip -oq "${tmpdir}/${asset}" -d "$tmpdir" ;;
131+
esac
132+
133+
# install
134+
mkdir -p "$BINDIR" 2>/dev/null || sudo mkdir -p "$BINDIR"
135+
srcname="${BINARY}-${OS}-${ARCH}"
136+
binexe="${BINARY}"
137+
[ "$OS" = "windows" ] && srcname="${srcname}.exe" && binexe="${binexe}.exe"
138+
139+
mv "${tmpdir}/${srcname}" "${BINDIR}/${binexe}" 2>/dev/null \
140+
|| sudo mv "${tmpdir}/${srcname}" "${BINDIR}/${binexe}"
141+
142+
echo "Installed ${BINDIR}/${binexe}"

0 commit comments

Comments
 (0)