Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·114 lines (100 loc) · 2.77 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·114 lines (100 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env bash
#
# opcode-kit installer
#
# Builds the opcode-kit Go binary from source and installs it (plus
# optional legacy wrappers) into $PREFIX/bin (default: ~/.local/bin).
#
# Usage:
# ./install.sh # build + install opcode-kit + both wrappers
# ./install.sh all # same as above
# ./install.sh opcode-kit # build + install opcode-kit only
# ./install.sh opcode-switch # build + install opcode-kit + opcode-switch wrapper
# ./install.sh opcode-last # build + install opcode-kit + opcode-last wrapper
# ./install.sh --help # show usage
#
# Environment:
# PREFIX install prefix (default: $HOME/.local)
# GOPROXY passed through to go build
set -euo pipefail
PREFIX="${PREFIX:-$HOME/.local}"
BIN_DIR="$PREFIX/bin"
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
usage() {
cat <<'EOF'
Usage:
./install.sh
./install.sh all
./install.sh opcode-kit
./install.sh opcode-switch
./install.sh opcode-last
PREFIX=/custom/prefix ./install.sh
Notes:
- Default installs the opcode-kit binary and both wrappers.
- The binary is built from source, so `go` must be installed.
- Wrappers (opcode-switch, opcode-last) exec `opcode-kit switch|last`.
EOF
}
command -v go >/dev/null 2>&1 || {
printf 'install.sh: `go` not found on PATH (required to build opcode-kit)\n' >&2
exit 1
}
need_binary=0
need_switch_wrapper=0
need_last_wrapper=0
if [ "$#" -eq 0 ] || [ "$1" = "all" ]; then
need_binary=1
need_switch_wrapper=1
need_last_wrapper=1
else
for tool in "$@"; do
case "$tool" in
--help|-h)
usage
exit 0
;;
opcode-kit)
need_binary=1
;;
opcode-switch)
need_binary=1
need_switch_wrapper=1
;;
opcode-last)
need_binary=1
need_last_wrapper=1
;;
*)
printf 'install.sh: unknown tool: %s\n' "$tool" >&2
usage >&2
exit 1
;;
esac
done
fi
mkdir -p "$BIN_DIR"
if [ "$need_binary" -eq 1 ]; then
tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT
printf 'Building opcode-kit from source...\n'
(cd "$ROOT" && go build -trimpath -o "$tmp/opcode-kit" ./cmd/opcode-kit)
install -m 0755 "$tmp/opcode-kit" "$BIN_DIR/opcode-kit"
printf 'Installed %s\n' "$BIN_DIR/opcode-kit"
fi
if [ "$need_switch_wrapper" -eq 1 ]; then
cat > "$BIN_DIR/opcode-switch" <<'EOF'
#!/usr/bin/env bash
exec opcode-kit switch "$@"
EOF
chmod +x "$BIN_DIR/opcode-switch"
printf 'Installed wrapper %s\n' "$BIN_DIR/opcode-switch"
fi
if [ "$need_last_wrapper" -eq 1 ]; then
cat > "$BIN_DIR/opcode-last" <<'EOF'
#!/usr/bin/env bash
exec opcode-kit last "$@"
EOF
chmod +x "$BIN_DIR/opcode-last"
printf 'Installed wrapper %s\n' "$BIN_DIR/opcode-last"
fi
printf 'Done. Run `opcode-kit help` for usage.\n'