-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·157 lines (139 loc) · 4 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·157 lines (139 loc) · 4 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/bin/sh
# corky installer — downloads prebuilt binary from GitHub Releases
#
# Usage:
# curl -sSf https://raw.githubusercontent.com/btakita/corky/main/install.sh | sh
# curl -sSf ... | sh -s -- --system # install to /usr/local/bin
# curl -sSf ... | sh -s -- --version 0.7.0 # specific version
set -eu
REPO="btakita/corky"
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.7.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}"
# Detect GPU-backed release variant for this platform.
GPU_SUFFIX=""
case "$OS" in
Darwin)
echo "macOS detected — requiring Metal-accelerated binary."
GPU_SUFFIX="-metal"
;;
Linux)
if command -v nvidia-smi >/dev/null 2>&1 && nvidia-smi >/dev/null 2>&1; then
echo "NVIDIA GPU detected — requiring CUDA-accelerated binary."
GPU_SUFFIX="-cuda"
fi
;;
esac
# 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"
# Create temp directory
TMPDIR="$(mktemp -d)"
trap 'rm -rf "$TMPDIR"' EXIT
# Install a GPU binary when the local platform requires one.
ARCHIVE="corky-${TARGET}${GPU_SUFFIX}.tar.gz"
URL="https://github.com/$REPO/releases/download/$TAG/$ARCHIVE"
if [ -n "$GPU_SUFFIX" ]; then
echo "Downloading required GPU binary: $ARCHIVE"
if curl -sSfL "$URL" -o "$TMPDIR/$ARCHIVE" 2>/dev/null; then
echo "GPU binary downloaded."
else
echo "Required GPU binary is not available: $URL" >&2
echo "Install from source with the matching GPU feature instead." >&2
exit 1
fi
else
echo "Installing corky $VERSION for $TARGET..."
fi
echo " From: $URL"
echo " To: $INSTALL_DIR/corky"
# Download (if not already downloaded above)
if [ ! -f "$TMPDIR/$ARCHIVE" ]; then
curl -sSfL "$URL" -o "$TMPDIR/$ARCHIVE"
fi
tar xzf "$TMPDIR/$ARCHIVE" -C "$TMPDIR"
# Install binary
mkdir -p "$INSTALL_DIR"
$USE_SUDO install -m 755 "$TMPDIR/corky" "$INSTALL_DIR/corky"
# Verify
if "$INSTALL_DIR/corky" --version >/dev/null 2>&1; then
echo "corky $VERSION installed successfully."
"$INSTALL_DIR/corky" --version
else
echo "Warning: corky installed but failed to run." >&2
echo "Check that $INSTALL_DIR/corky 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