Skip to content

Commit d4e2302

Browse files
committed
feat(install): add go_bin target_dir for Go tool path convention
Replace ${GOPATH} expansion with a go_bin strategy that: - On update: keeps the binary where it currently is (respects gup) - On fresh install: best-guesses Go bin folder via GOPATH env, `go env GOPATH`, or ~/go/bin fallback (no Go runtime required) Apply to golangci-lint and gosec to avoid duplicate installations in both ~/.local/bin and ~/go/bin. Signed-off-by: Sebastian Mendel <sebastian.mendel@netresearch.de> Signed-off-by: Sebastian Mendel <info@sebastianmendel.de>
1 parent ca6a9ae commit d4e2302

3 files changed

Lines changed: 42 additions & 0 deletions

File tree

catalog/golangci-lint.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"homepage": "https://github.com/golangci/golangci-lint",
77
"github_repo": "golangci/golangci-lint",
88
"binary_name": "golangci-lint",
9+
"target_dir": "go_bin",
910
"download_url_template": "https://github.com/golangci/golangci-lint/releases/download/{version}/golangci-lint-{version_nov}-linux-{arch}.tar.gz",
1011
"arch_map": {
1112
"x86_64": "amd64",

catalog/gosec.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"homepage": "https://github.com/securego/gosec",
77
"github_repo": "securego/gosec",
88
"binary_name": "gosec",
9+
"target_dir": "go_bin",
910
"download_url_template": "https://github.com/securego/gosec/releases/download/{version}/gosec_{version_nov}_linux_{arch}.tar.gz",
1011
"arch_map": {
1112
"x86_64": "amd64",

scripts/lib/install_strategy.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,46 @@ get_install_dir() {
1010
local prefix="${PREFIX:-$HOME/.local}"
1111
local bin_dir=""
1212

13+
# Check for per-tool target_dir override from catalog
14+
if [ -n "$tool_name" ] && [ -n "${CATALOG_FILE:-}" ] && [ -f "${CATALOG_FILE:-}" ]; then
15+
local target_dir
16+
target_dir="$(jq -r '.target_dir // empty' "$CATALOG_FILE" 2>/dev/null || true)"
17+
if [ -n "$target_dir" ]; then
18+
case "$target_dir" in
19+
go_bin)
20+
# Go binary convention: update in place, fresh install to best-guess GOPATH/bin
21+
local current_path
22+
current_path="$(command -v "$tool_name" 2>/dev/null || true)"
23+
if [ -n "$current_path" ]; then
24+
# Already installed - keep it where it is
25+
echo "$(dirname "$current_path")"
26+
else
27+
# Fresh install - best-guess Go bin folder:
28+
# 1. GOPATH/bin if GOPATH is set
29+
# 2. `go env GOPATH`/bin if go is available
30+
# 3. ~/go/bin (Go's default GOPATH)
31+
if [ -n "${GOPATH:-}" ]; then
32+
echo "$GOPATH/bin"
33+
elif command -v go >/dev/null 2>&1; then
34+
echo "$(go env GOPATH 2>/dev/null)/bin"
35+
else
36+
echo "$HOME/go/bin"
37+
fi
38+
fi
39+
return
40+
;;
41+
*)
42+
# Generic target_dir: expand ~ and $HOME
43+
target_dir="${target_dir/#\~/$HOME}"
44+
target_dir="${target_dir//\$\{HOME\}/$HOME}"
45+
target_dir="${target_dir//\$HOME/$HOME}"
46+
echo "$target_dir"
47+
return
48+
;;
49+
esac
50+
fi
51+
fi
52+
1353
case "$strategy" in
1454
CURRENT)
1555
# Keep tool where it is currently installed

0 commit comments

Comments
 (0)