-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·126 lines (111 loc) · 3.12 KB
/
install.sh
File metadata and controls
executable file
·126 lines (111 loc) · 3.12 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
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/sh
# agent-doc installer — downloads prebuilt binary from GitHub Releases
#
# Usage:
# curl -sSf https://raw.githubusercontent.com/btakita/agent-doc/main/install.sh | sh
# curl -sSf ... | sh -s -- --system # install to /usr/local/bin
# curl -sSf ... | sh -s -- --version 0.1.0 # specific version
set -eu
REPO="btakita/agent-doc"
INSTALL_DIR="$HOME/.local/bin"
USE_SUDO=""
VERSION=""
usage() {
cat <<EOF
Usage: install.sh [OPTIONS]
Options:
--system Install to /usr/local/bin (requires sudo)
--version VER Install a specific version (e.g. 0.1.0)
--help Show this help
EOF
exit 0
}
while [ $# -gt 0 ]; do
case "$1" in
--system)
INSTALL_DIR="/usr/local/bin"
USE_SUDO="sudo"
shift
;;
--version)
VERSION="$2"
shift 2
;;
--help)
usage
;;
*)
echo "Unknown option: $1" >&2
usage
;;
esac
done
# Detect OS
OS="$(uname -s)"
case "$OS" in
Linux) OS_TARGET="unknown-linux-gnu" ;;
Darwin) OS_TARGET="apple-darwin" ;;
*)
echo "Unsupported OS: $OS" >&2
echo "See https://github.com/$REPO/releases for manual download." >&2
exit 1
;;
esac
# Detect architecture
ARCH="$(uname -m)"
case "$ARCH" in
x86_64|amd64) ARCH_TARGET="x86_64" ;;
aarch64|arm64) ARCH_TARGET="aarch64" ;;
*)
echo "Unsupported architecture: $ARCH" >&2
echo "See https://github.com/$REPO/releases for manual download." >&2
exit 1
;;
esac
TARGET="${ARCH_TARGET}-${OS_TARGET}"
# Resolve version
if [ -z "$VERSION" ]; then
echo "Fetching latest release..."
VERSION="$(curl -sSf "https://api.github.com/repos/$REPO/releases/latest" \
| grep '"tag_name"' \
| sed 's/.*"tag_name": *"v\{0,1\}\([^"]*\)".*/\1/')"
if [ -z "$VERSION" ]; then
echo "Failed to determine latest version." >&2
exit 1
fi
fi
TAG="v$VERSION"
ARCHIVE="agent-doc-${TARGET}.tar.gz"
URL="https://github.com/$REPO/releases/download/$TAG/$ARCHIVE"
echo "Installing agent-doc $VERSION for $TARGET..."
echo " From: $URL"
echo " To: $INSTALL_DIR/agent-doc"
# Create temp directory
TMPDIR="$(mktemp -d)"
trap 'rm -rf "$TMPDIR"' EXIT
# Download and extract
curl -sSfL "$URL" -o "$TMPDIR/$ARCHIVE"
tar xzf "$TMPDIR/$ARCHIVE" -C "$TMPDIR"
# Install binary
mkdir -p "$INSTALL_DIR"
$USE_SUDO install -m 755 "$TMPDIR/agent-doc" "$INSTALL_DIR/agent-doc"
# Verify
if "$INSTALL_DIR/agent-doc" --version >/dev/null 2>&1; then
echo "agent-doc $VERSION installed successfully."
"$INSTALL_DIR/agent-doc" --version
else
echo "Warning: agent-doc installed but failed to run." >&2
echo "Check that $INSTALL_DIR/agent-doc is executable." >&2
fi
# PATH hint
case ":$PATH:" in
*":$INSTALL_DIR:"*) ;;
*)
echo ""
echo "Note: $INSTALL_DIR is not in your PATH."
echo "Add it with:"
echo " export PATH=\"$INSTALL_DIR:\$PATH\""
echo ""
echo "To make this permanent, add the line above to your ~/.bashrc or ~/.zshrc."
;;
esac