-
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·332 lines (277 loc) · 10.1 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·332 lines (277 loc) · 10.1 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
#!/usr/bin/env bash
# Generic install script for WoW Emulation CLI tools
# Based on cargo-binstall's installation approach
set -euo pipefail
# ============================================================================
# PROJECT CONFIGURATION - Customize these for each project
# ============================================================================
BINARY_NAMES="${BINARY_NAMES:-}" # Required: Space-separated list, e.g., "ribbit-server cli bnet-agent"
BINARY_DEFAULT="${BINARY_DEFAULT:-}" # Required: Default binary to install, must be in BINARY_NAMES
REPO="${REPO:-}" # Required: e.g., "wowemulation-dev/cascette-rs"
TAG_PREFIX="${TAG_PREFIX:-${BINARY_DEFAULT}-}" # e.g., "cascette-ribbit-v", "warcraft-rs-v", "v"
# ============================================================================
# Verify required configuration
if [[ -z "$BINARY_NAMES" ]] || [[ -z "$BINARY_DEFAULT" ]] || [[ -z "$REPO" ]]; then
echo "Error: BINARY_NAMES, BINARY_DEFAULT, and REPO must be configured"
echo "Usage: BINARY_NAMES=\"binary1 binary2\" BINARY_DEFAULT=binary1 REPO=org/repo $0 [OPTIONS] [VERSION]"
exit 1
fi
# Validate that default is in the list
if [[ ! " $BINARY_NAMES " =~ " $BINARY_DEFAULT " ]]; then
echo "Error: BINARY_DEFAULT must be in BINARY_NAMES"
echo "BINARY_NAMES: $BINARY_NAMES"
echo "BINARY_DEFAULT: $BINARY_DEFAULT"
exit 1
fi
# Set BINARY_NAME to default (can be overridden by --binary flag)
BINARY_NAME="$BINARY_DEFAULT"
BASE_URL="https://github.com/${REPO}/releases"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Helper functions
info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
error() {
echo -e "${RED}[ERROR]${NC} $1"
exit 1
}
# Detect OS and architecture
detect_platform() {
local os arch
# Detect OS
case "$(uname -s)" in
Linux*) os="unknown-linux";;
Darwin*) os="apple-darwin";;
MINGW*|MSYS*|CYGWIN*) os="pc-windows";;
*) error "Unsupported operating system: $(uname -s)";;
esac
# Detect architecture
case "$(uname -m)" in
x86_64|amd64) arch="x86_64";;
aarch64|arm64) arch="aarch64";;
*) error "Unsupported architecture: $(uname -m)";;
esac
# Detect libc for Linux
if [[ "$os" == "unknown-linux" ]]; then
if ldd --version 2>&1 | grep -q musl; then
os="${os}-musl"
else
os="${os}-gnu"
fi
fi
# Windows uses different extension
if [[ "$os" == "pc-windows" ]]; then
os="${os}-msvc"
fi
echo "${arch}-${os}"
}
# Download and verify file
download_file() {
local url="$1"
local output="$2"
if command -v curl >/dev/null 2>&1; then
curl -fsSL "$url" -o "$output"
elif command -v wget >/dev/null 2>&1; then
wget -q "$url" -O "$output"
else
error "Neither curl nor wget found. Please install one of them."
fi
}
# Get latest release version
get_latest_version() {
local version
version=$(curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" | grep '"tag_name":' | sed -E "s/.*\"${TAG_PREFIX}([^\"]+)\".*/\1/")
if [[ -z "$version" ]]; then
error "Failed to get latest version"
fi
echo "$version"
}
# Verify binary with ephemeral minisign key
verify_binary() {
local file="$1"
local pubkey_file="$2"
# Check if signature verification tools are available
if command -v rsign >/dev/null 2>&1; then
info "Verifying signature with rsign..."
if rsign verify -p "$pubkey_file" "$file"; then
info "Signature verification successful"
else
error "Signature verification failed"
fi
elif command -v minisign >/dev/null 2>&1; then
info "Verifying signature with minisign..."
if minisign -V -p "$pubkey_file" -m "$file"; then
info "Signature verification successful"
else
error "Signature verification failed"
fi
else
warn "Neither rsign nor minisign found, skipping signature verification"
warn "Install minisign or rsign to verify binary signatures"
fi
}
# Main installation function
install() {
local version="${1:-}"
local install_dir="${INSTALL_DIR:-$HOME/.local/bin}"
local temp_dir
temp_dir=$(mktemp -d)
trap 'rm -rf "$temp_dir"' EXIT
# Get version if not specified
if [[ -z "$version" ]]; then
info "Fetching latest version..."
version=$(get_latest_version)
fi
info "Installing ${BINARY_NAME} v${version}"
# Detect platform
local platform
platform=$(detect_platform)
info "Detected platform: ${platform}"
# Determine file extension and archive format
local ext archive_ext
if [[ "$platform" == *"windows"* ]]; then
ext=".exe"
archive_ext=".zip"
else
ext=""
archive_ext=".tar.gz"
fi
# Download URL
local filename="${BINARY_NAME}-${version}-${platform}${archive_ext}"
local download_url="${BASE_URL}/download/${TAG_PREFIX}${version}/${filename}"
info "Downloading from: ${download_url}"
download_file "$download_url" "${temp_dir}/${filename}"
# Download signature and public key (ephemeral signing uses .sig extension)
download_file "${download_url}.sig" "${temp_dir}/${filename}.sig" || warn "Signature file not found"
download_file "${BASE_URL}/download/${TAG_PREFIX}${version}/minisign.pub" "${temp_dir}/minisign.pub" || warn "Public key not found"
# Verify if signature and public key were downloaded
if [[ -f "${temp_dir}/${filename}.sig" ]] && [[ -f "${temp_dir}/minisign.pub" ]]; then
verify_binary "${temp_dir}/${filename}" "${temp_dir}/minisign.pub"
fi
# Extract binary
info "Extracting binary..."
cd "$temp_dir"
if [[ "$archive_ext" == ".zip" ]]; then
unzip -q "$filename"
else
tar -xzf "$filename"
fi
# Create install directory if it doesn't exist
mkdir -p "$install_dir"
# Install binary
local binary_name="${BINARY_NAME}${ext}"
if [[ -f "$binary_name" ]]; then
info "Installing to ${install_dir}/${binary_name}"
mv "$binary_name" "${install_dir}/"
chmod +x "${install_dir}/${binary_name}"
else
error "Binary ${binary_name} not found in archive"
fi
# Verify installation
if "${install_dir}/${binary_name}" --version >/dev/null 2>&1; then
info "Installation successful!"
info "Binary installed to: ${install_dir}/${binary_name}"
# Check if install_dir is in PATH
if ! echo "$PATH" | grep -q "$install_dir"; then
warn "${install_dir} is not in your PATH"
warn "Add it to your PATH by adding this to your shell configuration:"
warn " export PATH=\"${install_dir}:\$PATH\""
fi
else
error "Installation verification failed"
fi
}
# Show help
show_help() {
cat << EOF
Generic install script for ${REPO}
USAGE:
$0 [OPTIONS] [VERSION]
OPTIONS:
-h, --help Show this help message
-d, --dir DIR Install directory (default: \$HOME/.local/bin)
-t, --tag TAG Install specific release tag
-b, --binary BINARY Binary to install (default: ${BINARY_DEFAULT})
ENVIRONMENT VARIABLES:
BINARY_NAMES Space-separated list of available binaries (required)
BINARY_DEFAULT Default binary to install (required)
REPO GitHub repo (required)
TAG_PREFIX Release tag prefix (default: \${BINARY_DEFAULT}-)
INSTALL_DIR Override default install directory
AVAILABLE BINARIES:
$(for bin in $BINARY_NAMES; do echo " - $bin"; done)
EXAMPLES:
# Install latest version (uses default binary: ${BINARY_DEFAULT})
BINARY_NAMES=\"${BINARY_NAMES}\" BINARY_DEFAULT=${BINARY_DEFAULT} REPO=org/repo $0
# Install specific binary
BINARY_NAMES=\"${BINARY_NAMES}\" BINARY_DEFAULT=${BINARY_DEFAULT} REPO=org/repo $0 --binary cli
# Install specific version
BINARY_NAMES=\"${BINARY_NAMES}\" BINARY_DEFAULT=${BINARY_DEFAULT} REPO=org/repo $0 0.1.0
# Install to custom directory
BINARY_NAMES=\"${BINARY_NAMES}\" BINARY_DEFAULT=${BINARY_DEFAULT} REPO=org/repo INSTALL_DIR=/usr/local/bin $0
# Install specific tag
BINARY_NAMES=\"${BINARY_NAMES}\" BINARY_DEFAULT=${BINARY_DEFAULT} REPO=org/repo $0 --tag ${BINARY_DEFAULT}-v0.1.0
SUPPORTED PROJECTS:
- warcraft-rs BINARY_NAMES=\"warcraft-rs\" BINARY_DEFAULT=warcraft-rs REPO=wowemulation-dev/warcraft-rs
- cascette-rs BINARY_NAMES=\"ribbit-server cli\" BINARY_DEFAULT=ribbit-server REPO=wowemulation-dev/cascette-rs
- rilua BINARY_NAMES=\"rilua\" BINARY_DEFAULT=rilua REPO=wowemulation-dev/rilua
- wow-patcher BINARY_NAMES=\"wow-patcher\" BINARY_DEFAULT=wow-patcher REPO=wowemulation-dev/wow-patcher
- recast-rs BINARY_NAMES=\"recast-cli\" BINARY_DEFAULT=recast-cli REPO=wowemulation-dev/recast-rs
EOF
}
# Parse command line arguments
main() {
local version=""
local tag=""
local binary=""
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
show_help
exit 0
;;
-d|--dir)
INSTALL_DIR="$2"
shift 2
;;
-t|--tag)
tag="$2"
shift 2
;;
-b|--binary)
binary="$2"
shift 2
;;
-*)
error "Unknown option: $1"
;;
*)
version="$1"
shift
;;
esac
done
# Validate binary selection if provided
if [[ -n "$binary" ]]; then
if [[ ! " $BINARY_NAMES " =~ " $binary " ]]; then
echo "Error: Unknown binary '$binary'"
echo "Available binaries: $BINARY_NAMES"
exit 1
fi
BINARY_NAME="$binary"
fi
# Extract version from tag if provided
if [[ -n "$tag" ]]; then
version="${tag#"${TAG_PREFIX}"}"
fi
install "$version"
}
# Run main function
main "$@"