-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
196 lines (165 loc) · 5.44 KB
/
install.sh
File metadata and controls
196 lines (165 loc) · 5.44 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
#!/bin/sh
# game-ci CLI installer
# Usage: curl -fsSL https://raw.githubusercontent.com/game-ci/orchestrator/main/install.sh | sh
#
# Environment variables:
# GAME_CI_VERSION - Install a specific version (e.g., v2.0.0). Defaults to latest.
# GAME_CI_INSTALL - Installation directory. Defaults to ~/.game-ci/bin.
set -e
REPO="game-ci/orchestrator"
INSTALL_DIR="${GAME_CI_INSTALL:-$HOME/.game-ci/bin}"
BINARY_NAME="game-ci"
# Colors (disabled if not a terminal)
if [ -t 1 ]; then
BOLD='\033[1m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
RED='\033[0;31m'
RESET='\033[0m'
else
BOLD=''
GREEN=''
YELLOW=''
RED=''
RESET=''
fi
info() {
printf "${GREEN}info${RESET}: %s\n" "$1"
}
warn() {
printf "${YELLOW}warn${RESET}: %s\n" "$1"
}
error() {
printf "${RED}error${RESET}: %s\n" "$1" >&2
exit 1
}
# Detect OS and architecture
detect_platform() {
OS="$(uname -s)"
ARCH="$(uname -m)"
case "$OS" in
Linux*) PLATFORM="linux" ;;
Darwin*) PLATFORM="macos" ;;
MINGW*|MSYS*|CYGWIN*)
PLATFORM="windows"
warn "For Windows, consider using install.ps1 instead:"
warn " irm https://raw.githubusercontent.com/game-ci/orchestrator/main/install.ps1 | iex"
;;
*) error "Unsupported operating system: $OS" ;;
esac
case "$ARCH" in
x86_64|amd64) ARCH="x64" ;;
aarch64|arm64) ARCH="arm64" ;;
*) error "Unsupported architecture: $ARCH" ;;
esac
ASSET_NAME="game-ci-${PLATFORM}-${ARCH}"
if [ "$PLATFORM" = "windows" ]; then
ASSET_NAME="${ASSET_NAME}.exe"
BINARY_NAME="game-ci.exe"
fi
}
# Get latest release tag from GitHub API
get_latest_version() {
if [ -n "$GAME_CI_VERSION" ]; then
VERSION="$GAME_CI_VERSION"
info "Using specified version: $VERSION"
return
fi
info "Fetching latest release..."
if command -v curl > /dev/null 2>&1; then
VERSION=$(curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" | grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/')
elif command -v wget > /dev/null 2>&1; then
VERSION=$(wget -qO- "https://api.github.com/repos/${REPO}/releases/latest" | grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/')
else
error "Neither curl nor wget found. Please install one of them."
fi
if [ -z "$VERSION" ]; then
error "Could not determine latest version. Check https://github.com/${REPO}/releases"
fi
}
# Download and install the binary
install() {
DOWNLOAD_URL="https://github.com/${REPO}/releases/download/${VERSION}/${ASSET_NAME}"
printf "\n"
info "Installing game-ci ${VERSION} (${PLATFORM}-${ARCH})"
info " from: ${DOWNLOAD_URL}"
info " to: ${INSTALL_DIR}/${BINARY_NAME}"
printf "\n"
mkdir -p "$INSTALL_DIR"
# Download with progress
if command -v curl > /dev/null 2>&1; then
HTTP_CODE=$(curl -fSL "$DOWNLOAD_URL" -o "${INSTALL_DIR}/${BINARY_NAME}" -w "%{http_code}" 2>/dev/null) || true
if [ "$HTTP_CODE" = "404" ]; then
error "Release asset not found: ${ASSET_NAME} (${VERSION}). Check available assets at https://github.com/${REPO}/releases/tag/${VERSION}"
elif [ ! -f "${INSTALL_DIR}/${BINARY_NAME}" ]; then
error "Download failed. URL: ${DOWNLOAD_URL}"
fi
elif command -v wget > /dev/null 2>&1; then
wget -q "$DOWNLOAD_URL" -O "${INSTALL_DIR}/${BINARY_NAME}" || error "Download failed. URL: ${DOWNLOAD_URL}"
fi
chmod +x "${INSTALL_DIR}/${BINARY_NAME}"
# Verify the binary works
if "${INSTALL_DIR}/${BINARY_NAME}" version > /dev/null 2>&1; then
INSTALLED_VERSION=$("${INSTALL_DIR}/${BINARY_NAME}" version 2>&1 | head -1)
info "Verified: ${INSTALLED_VERSION}"
else
warn "Binary downloaded but could not verify. It may still work."
fi
printf "\n"
printf "${BOLD}game-ci installed successfully!${RESET}\n"
printf "\n"
# Check if install dir is in PATH
case ":$PATH:" in
*":${INSTALL_DIR}:"*)
info "game-ci is already in your PATH. Run: game-ci --help"
;;
*)
SHELL_NAME=$(basename "$SHELL" 2>/dev/null || echo "sh")
case "$SHELL_NAME" in
zsh) PROFILE="~/.zshrc" ;;
bash) PROFILE="~/.bashrc" ;;
fish) PROFILE="~/.config/fish/config.fish" ;;
*) PROFILE="~/.profile" ;;
esac
printf "${YELLOW}Add game-ci to your PATH by adding this to ${PROFILE}:${RESET}\n"
printf "\n"
if [ "$SHELL_NAME" = "fish" ]; then
printf " set -gx PATH \"%s\" \$PATH\n" "$INSTALL_DIR"
else
printf " export PATH=\"%s:\$PATH\"\n" "$INSTALL_DIR"
fi
printf "\n"
info "Then restart your shell or run: source ${PROFILE}"
;;
esac
}
# Verify checksum if checksums.txt is available
verify_checksum() {
if ! command -v sha256sum > /dev/null 2>&1; then
return 0
fi
CHECKSUM_URL="https://github.com/${REPO}/releases/download/${VERSION}/checksums.txt"
CHECKSUMS=""
if command -v curl > /dev/null 2>&1; then
CHECKSUMS=$(curl -fsSL "$CHECKSUM_URL" 2>/dev/null) || return 0
elif command -v wget > /dev/null 2>&1; then
CHECKSUMS=$(wget -qO- "$CHECKSUM_URL" 2>/dev/null) || return 0
fi
if [ -z "$CHECKSUMS" ]; then
return 0
fi
EXPECTED=$(echo "$CHECKSUMS" | grep "$ASSET_NAME" | awk '{print $1}')
if [ -z "$EXPECTED" ]; then
return 0
fi
ACTUAL=$(sha256sum "${INSTALL_DIR}/${BINARY_NAME}" | awk '{print $1}')
if [ "$EXPECTED" != "$ACTUAL" ]; then
error "Checksum verification failed!\n Expected: ${EXPECTED}\n Got: ${ACTUAL}"
fi
info "Checksum verified (SHA256)"
}
# Main
detect_platform
get_latest_version
install
verify_checksum