-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·58 lines (48 loc) · 1.62 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·58 lines (48 loc) · 1.62 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
#!/usr/bin/env bash
# hydrate installer — builds the binary, installs it, then hands off to the
# interactive `hydrate init` for setup (profile + heartbeat + shell/tmux wiring).
set -euo pipefail
PREFIX="${PREFIX:-$HOME/.local/bin}"
DO_BUILD=1
DO_INIT=1
usage() {
cat <<'EOF'
Usage: ./install.sh [options]
--prefix DIR Install the binary here (default: ~/.local/bin)
--no-build Skip `go build`; install the existing ./hydrate binary
--no-init Just install the binary; skip the interactive `hydrate init`
-h, --help Show this help
EOF
}
while [ $# -gt 0 ]; do
case "$1" in
--prefix) PREFIX="$2"; shift 2 ;;
--prefix=*) PREFIX="${1#*=}"; shift ;;
--no-build) DO_BUILD=0; shift ;;
--no-init) DO_INIT=0; shift ;;
-h|--help) usage; exit 0 ;;
*) echo "unknown option: $1" >&2; usage; exit 2 ;;
esac
done
here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$here"
info() { printf '\033[1;34m==>\033[0m %s\n' "$*"; }
warn() { printf '\033[1;33mwarn:\033[0m %s\n' "$*"; }
if [ "$DO_BUILD" -eq 1 ]; then
command -v go >/dev/null 2>&1 || { echo "go is required (or pass --no-build)"; exit 1; }
info "Building hydrate"
go build -o hydrate ./cmd/hydrate
fi
[ -x ./hydrate ] || { echo "no ./hydrate binary; build first or drop --no-build"; exit 1; }
info "Installing binary to $PREFIX/hydrate"
mkdir -p "$PREFIX"
install -m755 hydrate "$PREFIX/hydrate"
case ":$PATH:" in
*":$PREFIX:"*) ;;
*) warn "$PREFIX is not on your PATH — add it to use \`hydrate\` directly" ;;
esac
if [ "$DO_INIT" -eq 1 ]; then
echo
exec "$PREFIX/hydrate" init
fi
echo "Done. Run \`hydrate init\` to configure."