-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·235 lines (194 loc) · 6.43 KB
/
install.sh
File metadata and controls
executable file
·235 lines (194 loc) · 6.43 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
#!/bin/bash
# JuliaHub CLI (jh) installer script
# This script downloads and installs the latest release of jh from GitHub
set -e
# Configuration
REPO_OWNER="JuliaComputing"
REPO_NAME="jh"
BINARY_NAME="jh"
INSTALL_DIR="${INSTALL_DIR:-$HOME/.local/bin}"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Logging functions
info() {
echo -e "${BLUE}INFO${NC}: $1"
}
success() {
echo -e "${GREEN}SUCCESS${NC}: $1"
}
warning() {
echo -e "${YELLOW}WARNING${NC}: $1"
}
error() {
echo -e "${RED}ERROR${NC}: $1" >&2
exit 1
}
# Detect OS and architecture
detect_platform() {
local os arch
# Detect OS
case "$(uname -s)" in
Linux*) os="linux";;
Darwin*) os="darwin";;
CYGWIN*|MINGW*|MSYS*) os="windows";;
*) error "Unsupported operating system: $(uname -s)";;
esac
# Detect architecture
case "$(uname -m)" in
x86_64|amd64) arch="amd64";;
aarch64|arm64) arch="arm64";;
*) error "Unsupported architecture: $(uname -m)";;
esac
echo "${os}-${arch}"
}
# Check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Get latest release version from GitHub API
get_latest_version() {
local api_url="https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/releases/latest"
if command_exists curl; then
curl -s "$api_url" | grep '"tag_name":' | sed -E 's/.*"tag_name": "([^"]+)".*/\1/'
elif command_exists wget; then
wget -qO- "$api_url" | grep '"tag_name":' | sed -E 's/.*"tag_name": "([^"]+)".*/\1/'
else
error "curl or wget is required to download the release"
fi
}
# Download and install binary
install_binary() {
local platform="$1"
local version="$2"
local os_part="${platform%-*}"
local arch_part="${platform#*-}"
# Construct download URL
local binary_name="${BINARY_NAME}-${os_part}-${arch_part}"
if [ "$os_part" = "windows" ]; then
binary_name="${binary_name}.exe"
fi
local download_url="https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/download/${version}/${binary_name}"
info "Downloading ${BINARY_NAME} ${version} for ${platform}..."
info "Download URL: $download_url"
# Create install directory if it doesn't exist
mkdir -p "$INSTALL_DIR"
# Download binary
local temp_file="${INSTALL_DIR}/${binary_name}.tmp"
local final_file="${INSTALL_DIR}/${BINARY_NAME}"
if [ "$os_part" = "windows" ]; then
final_file="${final_file}.exe"
fi
if command_exists curl; then
curl -L -o "$temp_file" "$download_url"
elif command_exists wget; then
wget -O "$temp_file" "$download_url"
else
error "curl or wget is required to download the release"
fi
# Verify download was successful
if [ ! -f "$temp_file" ] || [ ! -s "$temp_file" ]; then
rm -f "$temp_file"
error "Failed to download binary from $download_url"
fi
# Move to final location and make executable
mv "$temp_file" "$final_file"
chmod +x "$final_file"
success "Installed ${BINARY_NAME} to $final_file"
# Check if install directory is in PATH
case ":$PATH:" in
*":$INSTALL_DIR:"*) ;;
*) warning "$INSTALL_DIR is not in your PATH. Add it to your shell profile:"
echo " echo 'export PATH=\"$INSTALL_DIR:\$PATH\"' >> ~/.bashrc"
echo " echo 'export PATH=\"$INSTALL_DIR:\$PATH\"' >> ~/.zshrc"
;;
esac
}
# Verify installation
verify_installation() {
local binary_path="${INSTALL_DIR}/${BINARY_NAME}"
if [ "$(uname -s)" = "CYGWIN" ] || [ "$(uname -s)" = "MINGW" ] || [ "$(uname -s)" = "MSYS" ]; then
binary_path="${binary_path}.exe"
fi
if [ -x "$binary_path" ]; then
local version_output
if version_output=$("$binary_path" --version 2>/dev/null); then
success "Installation verified: $version_output"
info "Run '$BINARY_NAME --help' to get started"
else
warning "Binary installed but version check failed"
fi
else
error "Installation failed: binary not found or not executable"
fi
}
# Main installation function
main() {
echo "JuliaHub CLI (${BINARY_NAME}) Installer"
echo "======================================"
# Detect platform
local platform
platform=$(detect_platform)
info "Detected platform: $platform"
# Get latest version
info "Fetching latest release information..."
local version
version=$(get_latest_version)
if [ -z "$version" ]; then
error "Failed to get latest version information"
fi
info "Latest version: $version"
# Check if binary already exists
local existing_binary="${INSTALL_DIR}/${BINARY_NAME}"
if [ "$(uname -s | tr '[:upper:]' '[:lower:]')" = "windows" ]; then
existing_binary="${existing_binary}.exe"
fi
if [ -f "$existing_binary" ]; then
if current_version=$("$existing_binary" --version 2>/dev/null); then
info "Current installation: $current_version"
if echo "$current_version" | grep -q "$version"; then
info "Latest version is already installed"
exit 0
fi
fi
warning "Existing installation found. It will be replaced."
fi
# Install binary
install_binary "$platform" "$version"
# Verify installation
verify_installation
echo ""
success "Installation complete!"
info "You can now use '${BINARY_NAME}' to interact with JuliaHub"
info "Start with: ${BINARY_NAME} auth login"
}
# Parse command line arguments
while [ $# -gt 0 ]; do
case $1 in
--install-dir)
INSTALL_DIR="$2"
shift 2
;;
--help|-h)
echo "JuliaHub CLI Installer"
echo ""
echo "Usage: $0 [options]"
echo ""
echo "Options:"
echo " --install-dir DIR Install directory (default: \$HOME/.local/bin)"
echo " --help, -h Show this help message"
echo ""
echo "Environment variables:"
echo " INSTALL_DIR Same as --install-dir"
exit 0
;;
*)
error "Unknown option: $1. Use --help for usage information."
;;
esac
done
# Run main installation
main