-
-
Notifications
You must be signed in to change notification settings - Fork 186
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·248 lines (214 loc) · 6.36 KB
/
install.sh
File metadata and controls
executable file
·248 lines (214 loc) · 6.36 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
#!/bin/bash
# GraphJin Installer
# Usage: curl -fsSL https://graphjin.com/install.sh | bash
#
# Environment variables:
# GRAPHJIN_VERSION - Specific version to install (default: latest)
# GRAPHJIN_INSTALL_DIR - Installation directory (default: /usr/local/bin or ~/.local/bin)
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
print_banner() {
echo -e "${BLUE}"
echo ' ____ _ _ _ '
echo ' / ___|_ __ __ _ _ __ | |__ | (_)_ __ '
echo ' | | _| '\''__/ _` | '\''_ \| '\''_ \ | | | '\''_ \ '
echo ' | |_| | | | (_| | |_) | | | |_| | | | | |'
echo ' \____|_| \__,_| .__/|_| |_(_)_|_|_| |_|'
echo ' |_| '
echo -e "${NC}"
echo "Build APIs in 5 minutes with GraphQL"
echo ""
}
info() {
echo -e "${BLUE}==>${NC} $1"
}
success() {
echo -e "${GREEN}==>${NC} $1"
}
warn() {
echo -e "${YELLOW}Warning:${NC} $1"
}
error() {
echo -e "${RED}Error:${NC} $1" >&2
exit 1
}
# Detect OS
detect_os() {
local os
os=$(uname -s | tr '[:upper:]' '[:lower:]')
case "$os" in
linux*) echo "linux" ;;
darwin*) echo "darwin" ;;
mingw*|msys*|cygwin*) echo "windows" ;;
*) error "Unsupported operating system: $os" ;;
esac
}
# Detect architecture
detect_arch() {
local arch
arch=$(uname -m)
case "$arch" in
x86_64|amd64) echo "amd64" ;;
aarch64|arm64) echo "arm64" ;;
armv7l|armv6l) echo "arm" ;;
i386|i686) echo "386" ;;
*) error "Unsupported architecture: $arch" ;;
esac
}
# Get latest version from GitHub
get_latest_version() {
local latest
if command -v curl &> /dev/null; then
latest=$(curl -fsSL "https://api.github.com/repos/dosco/graphjin/releases/latest" | grep '"tag_name"' | sed -E 's/.*"v([^"]+)".*/\1/')
elif command -v wget &> /dev/null; then
latest=$(wget -qO- "https://api.github.com/repos/dosco/graphjin/releases/latest" | grep '"tag_name"' | sed -E 's/.*"v([^"]+)".*/\1/')
else
error "Neither curl nor wget found. Please install one of them."
fi
if [ -z "$latest" ]; then
error "Failed to determine latest version"
fi
echo "$latest"
}
# Download file
download() {
local url=$1
local dest=$2
if command -v curl &> /dev/null; then
curl -fsSL "$url" -o "$dest"
elif command -v wget &> /dev/null; then
wget -q "$url" -O "$dest"
else
error "Neither curl nor wget found"
fi
}
# Determine install directory
get_install_dir() {
if [ -n "$GRAPHJIN_INSTALL_DIR" ]; then
echo "$GRAPHJIN_INSTALL_DIR"
return
fi
# Try /usr/local/bin first (requires sudo)
if [ -w "/usr/local/bin" ]; then
echo "/usr/local/bin"
return
fi
# Fall back to ~/.local/bin
local local_bin="$HOME/.local/bin"
mkdir -p "$local_bin"
echo "$local_bin"
}
# Check if directory is in PATH
check_path() {
local dir=$1
if [[ ":$PATH:" != *":$dir:"* ]]; then
warn "$dir is not in your PATH"
echo ""
echo "Add it to your PATH by adding this to your shell profile:"
echo ""
if [[ "$SHELL" == *"zsh"* ]]; then
echo " echo 'export PATH=\"$dir:\$PATH\"' >> ~/.zshrc"
echo " source ~/.zshrc"
elif [[ "$SHELL" == *"fish"* ]]; then
echo " fish_add_path $dir"
else
echo " echo 'export PATH=\"$dir:\$PATH\"' >> ~/.bashrc"
echo " source ~/.bashrc"
fi
echo ""
fi
}
main() {
print_banner
local os=$(detect_os)
local arch=$(detect_arch)
local version=${GRAPHJIN_VERSION:-$(get_latest_version)}
local install_dir=$(get_install_dir)
info "Detected: $os/$arch"
info "Version: $version"
info "Install directory: $install_dir"
echo ""
# Build download URL candidates. New releases include version in the
# archive filename; keep legacy fallback names for older tags.
local release_base="https://github.com/dosco/graphjin/releases/download/v${version}"
local filenames=()
if [ "$os" = "windows" ]; then
filenames=(
"graphjin_${version}_${os}_${arch}.tar.gz"
"graphjin_${version}_${os}_${arch}.zip"
"graphjin_${os}_${arch}.tar.gz"
"graphjin_${os}_${arch}.zip"
)
else
filenames=(
"graphjin_${version}_${os}_${arch}.tar.gz"
"graphjin_${os}_${arch}.tar.gz"
)
fi
# Create temp directory
local tmp_dir=$(mktemp -d)
trap "rm -rf $tmp_dir" EXIT
local archive_path=""
local selected_filename=""
info "Downloading GraphJin v${version}..."
for filename in "${filenames[@]}"; do
local url="${release_base}/${filename}"
archive_path="$tmp_dir/$filename"
if download "$url" "$archive_path"; then
selected_filename="$filename"
break
fi
rm -f "$archive_path"
done
if [ -z "$selected_filename" ]; then
error "Failed to download GraphJin v${version}. Tried: ${filenames[*]}"
fi
info "Extracting..."
if [[ "$selected_filename" == *.zip ]]; then
unzip -q "$archive_path" -d "$tmp_dir"
else
tar -xzf "$archive_path" -C "$tmp_dir"
fi
# Find the binary
local binary_name="graphjin"
if [ "$os" = "windows" ]; then
binary_name="graphjin.exe"
fi
local binary_path="$tmp_dir/$binary_name"
if [ ! -f "$binary_path" ]; then
error "Binary not found in archive"
fi
# Install
info "Installing to $install_dir..."
local dest="$install_dir/$binary_name"
if [ -w "$install_dir" ]; then
mv "$binary_path" "$dest"
chmod +x "$dest"
else
sudo mv "$binary_path" "$dest"
sudo chmod +x "$dest"
fi
echo ""
success "GraphJin v${version} installed successfully!"
echo ""
# Verify installation
if command -v graphjin &> /dev/null; then
echo "Installed version:"
graphjin version 2>/dev/null || graphjin --version 2>/dev/null || true
else
check_path "$install_dir"
fi
echo ""
echo "Get started:"
echo " graphjin new myapp # Create a new project"
echo " graphjin serve # Start the server"
echo ""
echo "Documentation: https://graphjin.com"
echo ""
}
main "$@"