-
Notifications
You must be signed in to change notification settings - Fork 201
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·345 lines (300 loc) · 10.4 KB
/
setup.sh
File metadata and controls
executable file
·345 lines (300 loc) · 10.4 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
333
334
335
336
337
338
339
340
341
342
343
344
345
#!/bin/bash
# Lemonade development environment setup script
# This script prepares the development environment for building Lemonade
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
# Helper functions
print_info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Check if running as root
is_root() {
[ "$(id -u)" -eq 0 ]
}
# Use sudo only if not root
maybe_sudo() {
if is_root; then
"$@"
else
sudo "$@"
fi
}
# Detect OS
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
OS="linux"
elif [[ "$OSTYPE" == "darwin"* ]]; then
OS="macos"
else
print_error "Unsupported OS: $OSTYPE"
exit 1
fi
print_info "Lemonade Development Setup"
print_info "Operating System: $OS"
echo ""
# Arrays to track missing dependencies
missing_packages=()
install_commands=()
# Check pre-commit
print_info "Checking pre-commit installation..."
if ! command_exists pre-commit; then
print_warning "pre-commit not found"
if [ "$OS" = "linux" ] && command_exists pacman; then
missing_packages+=("pre-commit")
elif [ "$OS" = "linux" ] && command_exists apt; then
missing_packages+=("pre-commit")
elif [ "$OS" = "linux" ] && command_exists dnf; then
missing_packages+=("pre-commit")
elif [ "$OS" = "macos" ] && command_exists brew; then
missing_packages+=("pre-commit")
elif command_exists pip || command_exists pip3; then
missing_packages+=("pre-commit (via pip)")
else
print_error "No package manager found to install pre-commit"
exit 1
fi
else
print_success "pre-commit is already installed"
fi
# Check required build tools
print_info "Checking required build tools..."
required_tools=("git" "cmake" "ninja" "gcc" "g++")
missing_tools=()
for tool in "${required_tools[@]}"; do
if command_exists "$tool"; then
print_success "$tool is installed"
else
print_warning "$tool not found"
missing_tools+=("$tool")
fi
done
if [ ${#missing_tools[@]} -gt 0 ]; then
if [ "$OS" = "linux" ]; then
if command_exists apt; then
missing_packages+=("git" "cmake" "ninja-build" "build-essential")
elif command_exists pacman; then
missing_packages+=("git" "cmake" "ninja" "base-devel")
elif command_exists dnf; then
missing_packages+=("git" "cmake" "ninja-build" "gcc" "gcc-c++" "make")
fi
elif [ "$OS" = "macos" ]; then
missing_packages+=("git" "cmake" "ninja")
fi
fi
# Check pkg-config and required libraries
print_info "Checking pkg-config and required libraries..."
if command_exists pkg-config; then
print_success "pkg-config is installed"
# Check for required libraries using pkg-config
libs_to_check=("libcurl" "openssl" "zlib" "libsystemd")
missing_libs=()
for lib in "${libs_to_check[@]}"; do
if pkg-config --exists "$lib" 2>/dev/null; then
print_success "$lib is installed"
else
print_warning "$lib not found"
missing_libs+=("$lib")
fi
done
if [ ${#missing_libs[@]} -gt 0 ]; then
if [ "$OS" = "linux" ]; then
if command_exists apt; then
missing_packages+=("libcurl4-openssl-dev" "libssl-dev" "zlib1g-dev" "libsystemd-dev")
elif command_exists pacman; then
missing_packages+=("curl" "openssl" "zlib" "systemd")
elif command_exists dnf; then
missing_packages+=("libcurl-devel" "openssl-devel" "zlib-devel" "systemd-devel")
fi
elif [ "$OS" = "macos" ]; then
# macOS typically has these via Xcode Command Line Tools
# but can be explicitly installed via brew if needed
for lib in "${missing_libs[@]}"; do
case "$lib" in
libcurl) missing_packages+=("curl") ;;
openssl) missing_packages+=("openssl") ;;
zlib) missing_packages+=("zlib") ;;
esac
done
fi
fi
else
print_warning "pkg-config not found, assuming libraries need to be installed"
if [ "$OS" = "linux" ]; then
if command_exists apt; then
missing_packages+=("pkg-config" "libcurl4-openssl-dev" "libssl-dev" "zlib1g-dev" "libsystemd-dev")
elif command_exists pacman; then
missing_packages+=("pkgconf" "curl" "openssl" "zlib" "systemd")
elif command_exists dnf; then
missing_packages+=("pkgconfig" "libcurl-devel" "openssl-devel" "zlib-devel" "systemd-devel")
fi
elif [ "$OS" = "macos" ]; then
missing_packages+=("pkg-config" "curl" "openssl" "zlib")
fi
fi
# Check Node.js and npm
print_info "Checking Node.js and npm installation..."
if ! command_exists node; then
print_warning "Node.js not found"
if [ "$OS" = "linux" ]; then
if command_exists apt || command_exists pacman || command_exists dnf; then
missing_packages+=("nodejs" "npm")
fi
elif [ "$OS" = "macos" ]; then
if command_exists brew; then
missing_packages+=("node")
else
print_error "Homebrew not found. Please install Homebrew first: https://brew.sh/"
exit 1
fi
fi
else
print_success "Node.js is already installed"
fi
if command_exists node && ! command_exists npm; then
print_warning "npm not found"
missing_packages+=("npm")
fi
# Check for KaTeX fonts (optional but recommended for packaging)
print_info "Checking KaTeX fonts installation..."
if [ "$OS" = "linux" ]; then
KATEX_FONTS_DIR="/usr/share/fonts/truetype/katex"
if [ -d "$KATEX_FONTS_DIR" ]; then
print_success "KaTeX fonts are already installed"
else
print_warning "KaTeX fonts not found (optional, enables symlinks in packages)"
if command_exists apt; then
missing_packages+=("fonts-katex")
fi
fi
fi
echo ""
# If there are missing packages, prompt for installation
if [ ${#missing_packages[@]} -gt 0 ]; then
print_warning "Missing dependencies detected:"
for pkg in "${missing_packages[@]}"; do
echo " - $pkg"
done
echo ""
# Build installation command
if [ "$OS" = "linux" ]; then
if command_exists apt; then
if is_root; then
install_cmd="apt update && apt install -y ${missing_packages[*]}"
else
install_cmd="sudo apt update && sudo apt install -y ${missing_packages[*]}"
fi
elif command_exists pacman; then
if is_root; then
install_cmd="pacman -Syu --needed --noconfirm ${missing_packages[*]}"
else
install_cmd="sudo pacman -Syu --needed --noconfirm ${missing_packages[*]}"
fi
elif command_exists dnf; then
if is_root; then
install_cmd="dnf install -y ${missing_packages[*]}"
else
install_cmd="sudo dnf install -y ${missing_packages[*]}"
fi
fi
elif [ "$OS" = "macos" ]; then
install_cmd="brew install ${missing_packages[*]}"
fi
print_info "The following command will be executed:"
echo " $install_cmd"
echo ""
# Check if running in CI environment
if [ -n "$CI" ] || [ -n "$GITHUB_ACTIONS" ]; then
print_info "CI environment detected, proceeding with automatic installation..."
else
read -p "Do you want to install these dependencies? (y/N): " -n 1 -r
echo ""
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
print_error "Installation aborted by user"
exit 1
fi
fi
print_info "Installing dependencies..."
# Install based on OS and package manager
if [ "$OS" = "linux" ]; then
if command_exists apt; then
maybe_sudo apt update
# Check if pre-commit needs pip
if [[ " ${missing_packages[*]} " =~ " pre-commit " ]]; then
maybe_sudo apt install -y pre-commit
fi
# Install other packages
other_packages=("${missing_packages[@]}")
other_packages=("${other_packages[@]/pre-commit/}")
if [ ${#other_packages[@]} -gt 0 ]; then
maybe_sudo apt install -y ${other_packages[@]}
fi
elif command_exists pacman; then
maybe_sudo pacman -Syu --needed --noconfirm ${missing_packages[@]}
elif command_exists dnf; then
maybe_sudo dnf install -y ${missing_packages[@]}
fi
elif [ "$OS" = "macos" ]; then
brew install ${missing_packages[@]}
fi
# Install pre-commit via pip if no package manager version available
if [[ " ${missing_packages[*]} " =~ " pre-commit (via pip) " ]]; then
if command_exists pip; then
pip install pre-commit
elif command_exists pip3; then
pip3 install pre-commit
fi
fi
print_success "Dependencies installed successfully"
echo ""
else
print_success "All dependencies are already installed"
echo ""
fi
# Install pre-commit hooks
if [ -f ".pre-commit-config.yaml" ] && [ ! -f ".git/hooks/pre-commit" ] && [ -z "$CI" ] && [ -z "$GITHUB_ACTIONS" ]; then
print_info "Installing pre-commit hooks..."
pre-commit install
print_success "pre-commit hooks installed"
fi
echo ""
# Clean and create build directory
print_info "Preparing build directory..."
if [ -d "build" ]; then
print_warning "Removing existing build directory..."
rm -rf build
fi
mkdir -p build
print_success "Build directory created"
echo ""
# Configure with CMake presets
print_info "Configuring CMake with presets..."
cmake --preset default
print_success "CMake configured successfully"
echo ""
echo "=========================================="
print_success "Setup completed successfully!"
echo "=========================================="
echo ""
print_info "Next steps:"
echo " Build the project: cmake --build --preset default"
echo " Build the electron app: cmake --build --preset default --target electron-app"
echo " Build AppImage (Linux): cmake --build --preset default --target appimage"
echo ""
print_info "For more information, see the docs/dev-getting-started.md file"