-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·147 lines (130 loc) · 4.54 KB
/
install.sh
File metadata and controls
executable file
·147 lines (130 loc) · 4.54 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
#!/bin/bash
set -euo pipefail
# GMGUI Installation Script
# Robust, error-handled installation with proper cleanup
# Enable error handling and cleanup
TMPDIR=""
EXIT_CODE=0
cleanup() {
local code=$?
if [ -n "$TMPDIR" ] && [ -d "$TMPDIR" ]; then
rm -rf "$TMPDIR" 2>/dev/null || true
fi
if [ $code -ne 0 ] && [ $code -ne 130 ]; then
echo "Error: Installation failed. Check messages above." >&2
fi
exit $code
}
# Handle interrupts gracefully
handle_interrupt() {
echo ""
echo "Installation interrupted. Cleaning up..." >&2
exit 130
}
trap cleanup EXIT
trap handle_interrupt SIGINT SIGTERM
# Detect runtime (prefer bun, fall back to node)
RUNTIME=""
if command -v bun &> /dev/null; then
RUNTIME=bun
elif command -v node &> /dev/null; then
RUNTIME=node
else
echo "Error: Neither bun nor node is installed." >&2
echo "Install one with:" >&2
echo " • Bun (recommended, 3-4x faster):" >&2
echo " curl -fsSL https://bun.sh/install | bash" >&2
echo " • Node.js:" >&2
echo " curl https://nodejs.org/en/download/" >&2
exit 1
fi
# Verify curl or wget is available
if ! command -v curl &> /dev/null && ! command -v wget &> /dev/null; then
echo "Error: Neither curl nor wget found. Install one to download gmgui." >&2
exit 1
fi
# Create temp directory with secure permissions
TMPDIR=$(mktemp -d) || {
echo "Error: Could not create temporary directory." >&2
exit 1
}
# Verify we have write access to temp directory
if ! [ -w "$TMPDIR" ]; then
echo "Error: No write permission to temporary directory." >&2
exit 1
fi
# Check disk space (need at least 200MB)
AVAILABLE_KB=$(df "$TMPDIR" 2>/dev/null | tail -1 | awk '{print $4}' || echo 0)
if [ "$AVAILABLE_KB" -lt 200000 ]; then
echo "Warning: Low disk space. At least 200MB recommended." >&2
fi
echo "Downloading gmgui from GitHub..."
cd "$TMPDIR"
# Use git if available, otherwise use curl/wget to download tarball
if command -v git &> /dev/null; then
# Git clone with error handling
if ! git clone --depth=1 https://github.com/AnEntrypoint/gmgui.git . 2>&1 | grep -v "^Cloning"; then
echo "Warning: Git clone failed, trying tarball download..." >&2
# Fallback to tarball
if command -v curl &> /dev/null; then
curl -fsSL https://github.com/AnEntrypoint/gmgui/archive/refs/heads/main.tar.gz | tar xz --strip-components=1 || {
echo "Error: Could not download gmgui from GitHub." >&2
exit 1
}
else
wget -qO- https://github.com/AnEntrypoint/gmgui/archive/refs/heads/main.tar.gz | tar xz --strip-components=1 || {
echo "Error: Could not download gmgui from GitHub." >&2
exit 1
}
fi
fi
else
echo "Downloading tarball (git not available)..."
# Download tarball with curl or wget
if command -v curl &> /dev/null; then
curl -fsSL https://github.com/AnEntrypoint/gmgui/archive/refs/heads/main.tar.gz | tar xz --strip-components=1 || {
echo "Error: Could not download gmgui from GitHub." >&2
exit 1
}
else
wget -qO- https://github.com/AnEntrypoint/gmgui/archive/refs/heads/main.tar.gz | tar xz --strip-components=1 || {
echo "Error: Could not download gmgui from GitHub." >&2
exit 1
}
fi
fi
# Verify essential files were downloaded
if [ ! -f server.js ] || [ ! -f package.json ]; then
echo "Error: Downloaded files appear corrupted. Missing server.js or package.json." >&2
exit 1
fi
echo "Installing dependencies with $RUNTIME..."
if [ "$RUNTIME" = "bun" ]; then
if ! bun install --frozen-lockfile 2>&1 | grep -E "added|removed|found|vulnerabilities" | tail -1; then
# Warn but don't fail if grep doesn't match
bun install --frozen-lockfile 2>&1 | tail -3
fi
else
if ! npm install 2>&1 | grep -E "added|removed|found|vulnerabilities" | tail -1; then
# Warn but don't fail if grep doesn't match
npm install 2>&1 | tail -3
fi
# For Node.js, install better-sqlite3 if not already present
echo "Installing better-sqlite3 for Node.js..."
if ! npm install better-sqlite3 2>&1 | grep -E "added|removed|found|vulnerabilities" | tail -1; then
# Warn but don't fail - may already be installed
echo "Note: better-sqlite3 installation completed." >&2
fi
fi
echo ""
echo "✓ Installation complete!"
echo ""
echo "Starting gmgui server on http://localhost:3000"
echo "Press Ctrl+C to stop"
echo ""
# Start server with proper error handling
if [ "$RUNTIME" = "bun" ]; then
exec bun run server.js
else
exec node server.js
fi