-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlazarusInstaller.sh
More file actions
353 lines (294 loc) · 11.4 KB
/
lazarusInstaller.sh
File metadata and controls
353 lines (294 loc) · 11.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
346
347
348
349
350
351
352
353
#!/bin/bash
# --------------------------------------------
# LAZARUS INSTALLER 2.8 - COMPLETE CLEAN INSTALL
# Author: Mohammed Alotaibi
# Last Update: 2025-08-03
# --------------------------------------------
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
WHITE='\033[1;37m'
CYAN='\033[0;36m'
MAGENTA='\033[0;35m'
NC='\033[0m' # No Color
# Configuration
LAZARUS_SOURCE_DIR="$HOME/lazarus-source"
DESKTOP_FILE="$HOME/.local/share/applications/lazarus.desktop"
INSTALL_LOG="/tmp/lazarus_install_$(date +%Y%m%d_%H%M%S).log"
LAZARUS_EXEC="/usr/local/bin/lazarus"
ICON_PATH="/usr/local/share/lazarus/images/icons/lazarus.ico"
BUILD_JOBS=$(nproc)
MIN_DISK_SPACE=2000 # Minimum disk space needed in MB
# Initialize log file
init_log() {
echo "=== Lazarus Installation Log ===" > "$INSTALL_LOG"
echo "Started at: $(date)" >> "$INSTALL_LOG"
echo "System Info:" >> "$INSTALL_LOG"
lsb_release -d >> "$INSTALL_LOG" 2>&1
uname -a >> "$INSTALL_LOG" 2>&1
echo "CPU Cores: $BUILD_JOBS" >> "$INSTALL_LOG"
# Log disk space
echo -e "\nDisk Space:" >> "$INSTALL_LOG"
df -h >> "$INSTALL_LOG" 2>&1
# Log memory
echo -e "\nMemory:" >> "$INSTALL_LOG"
free -h >> "$INSTALL_LOG" 2>&1
}
# Status functions
status_msg() { echo -e "${CYAN}[*] ${WHITE}$1${NC}"; echo "[*] $1" >> "$INSTALL_LOG"; }
success_msg() { echo -e "${GREEN}[✓] ${WHITE}$1${NC}"; echo "[✓] $1" >> "$INSTALL_LOG"; }
warning_msg() { echo -e "${YELLOW}[!] ${WHITE}$1${NC}"; echo "[!] $1" >> "$INSTALL_LOG"; }
error_msg() { echo -e "${RED}[✗] ${WHITE}$1${NC}"; echo "[✗] $1" >> "$INSTALL_LOG"; exit 1; }
# Check if command exists
command_exists() { command -v "$1" >/dev/null 2>&1; }
# Get sudo privileges
get_sudo() {
status_msg "Checking sudo privileges..."
sudo -v || error_msg "Failed to get sudo privileges"
success_msg "Sudo privileges confirmed"
}
# Show banner
show_banner() {
clear
echo -e "${MAGENTA}# --------------------------------------------${NC}"
echo -e "${MAGENTA}# ${WHITE}LAZARUS INSTALLER 2.8${NC}"
echo -e "${MAGENTA}# ${WHITE}Complete Clean Installation${NC}"
echo -e "${MAGENTA}# ${WHITE}Author: Mohammed Alotaibi${NC}"
echo -e "${MAGENTA}# ${WHITE}Last Update: 2025-08-03${NC}"
echo -e "${MAGENTA}# --------------------------------------------${NC}\n"
}
# Check root
check_root() {
[ "$EUID" -eq 0 ] && error_msg "Please run as normal user (not root)"
success_msg "User check passed (normal user)"
}
# Comprehensive cleanup
cleanup_old_install() {
status_msg "Starting complete Lazarus/FPC removal..."
# Remove all package variants
local packages=($(dpkg -l | grep -E '^ii.*(fpc|lazarus)' | awk '{print $2}'))
if [ ${#packages[@]} -gt 0 ]; then
status_msg "Removing packages: ${packages[*]}"
sudo apt-get remove --purge -y "${packages[@]}" >> "$INSTALL_LOG" 2>&1 || {
warning_msg "Some packages couldn't be removed"
}
sudo apt-get remove --purge -y fp-compiler* >> "$INSTALL_LOG" 2>&1 || {
warning_msg "Some packages couldn't be removed"
}
sudo apt-get autoremove -y >> "$INSTALL_LOG" 2>&1 || {
warning_msg "Some packages couldn't be removed"
}
else
warning_msg "No Lazarus/FPC packages found"
fi
# Remove all known directories
local dirs=(
"/usr/lib/fpc" "/usr/lib/lazarus"
"/usr/share/fpcsrc" "/usr/share/fpc"
"/usr/share/doc/fpc" "/usr/share/lazarus"
"/etc/lazarus" "$HOME/.lazarus" "$HOME/.fppkg" "$HOME/.fpc"
)
for dir in "${dirs[@]}"; do
if [ -e "$dir" ]; then
status_msg "Removing directory: $dir"
sudo rm -rf "$dir" >> "$INSTALL_LOG" 2>&1 || warning_msg "Failed to remove $dir"
fi
done
# Remove all configuration files
local configs=(
"/etc/fpc.cfg" "$HOME/.fpc.cfg"
"/etc/fppkg.cfg" "/etc/lazarus.cfg"
"/etc/fpc-*.cfg" "/etc/fpc-*.bak"
)
for cfg in "${configs[@]}"; do
if [ -e "$cfg" ]; then
status_msg "Removing config: $cfg"
sudo rm -f "$cfg" >> "$INSTALL_LOG" 2>&1
fi
done
# Clean up binaries
status_msg "Cleaning up binaries..."
sudo find /usr/bin -name "fpc*" -delete >> "$INSTALL_LOG" 2>&1
sudo find /usr/bin -name "pp*" -delete >> "$INSTALL_LOG" 2>&1
sudo find /usr/bin -name "lazarus*" -delete >> "$INSTALL_LOG" 2>&1
# Final cleanup
sudo apt-get autoremove -y >> "$INSTALL_LOG" 2>&1
sudo apt-get clean >> "$INSTALL_LOG" 2>&1
success_msg "Complete cleanup finished"
}
# Install dependencies
install_deps() {
status_msg "Installing required dependencies..."
local deps=(
git build-essential binutils gdb make
libgtk2.0-dev libx11-dev libgpm-dev
libglib2.0-dev libpango1.0-dev
zlib1g-dev libncurses5-dev libssl-dev
libsqlite3-dev libpq-dev
fp-compiler fp-utils-3.2.2 fpc-source
)
# Check system resources first
status_msg "Checking system resources..."
local disk_space=$(df -m / | awk 'NR==2 {print $4}')
local free_mem=$(free -m | awk '/Mem:/ {print $4}')
echo -e "\n${YELLOW}System Resources:${NC}"
echo -e " Disk Space Available: ${disk_space}MB"
echo -e " Free Memory: ${free_mem}MB"
if [ "$disk_space" -lt "$MIN_DISK_SPACE" ]; then
error_msg "Insufficient disk space (need ${MIN_DISK_SPACE}MB, found ${disk_space}MB)"
fi
# Install FPC and utilities first
status_msg "Installing Free Pascal Compiler and utilities..."
sudo apt-get install -y fp-compiler fp-utils-3.2.2 fpc-source >> "$INSTALL_LOG" 2>&1 || {
error_msg "FPC installation failed"
}
# Install remaining dependencies
status_msg "Installing build dependencies..."
sudo apt-get install -y "${deps[@]}" >> "$INSTALL_LOG" 2>&1 || {
error_msg "Dependency installation failed"
}
# Verify FPC installation
if ! command_exists fpc; then
error_msg "FPC compiler not found after installation"
fi
success_msg "All dependencies installed"
}
# Install from source
install_source() {
status_msg "Installing from source..."
# Verify minimum disk space
local available_space=$(df -m / | awk 'NR==2 {print $4}')
[ "$available_space" -lt "$MIN_DISK_SPACE" ] && error_msg "Insufficient disk space"
# Clone/update repo
if [ -d "$LAZARUS_SOURCE_DIR" ]; then
status_msg "Updating existing repository..."
cd "$LAZARUS_SOURCE_DIR" || error_msg "Cannot access source directory"
git pull >> "$INSTALL_LOG" 2>&1 || error_msg "Git pull failed"
else
status_msg "Cloning repository..."
git clone --depth 1 https://gitlab.com/freepascal.org/lazarus/lazarus.git "$LAZARUS_SOURCE_DIR" >> "$INSTALL_LOG" 2>&1 || error_msg "Git clone failed"
cd "$LAZARUS_SOURCE_DIR" || error_msg "Cannot access source directory"
fi
# Step 1: Build the IDE first (crucial step)
status_msg "Building IDE components (Step 1/3)..."
make -C ide clean ide >> "$INSTALL_LOG" 2>&1 || {
echo -e "\n${RED}=== IDE BUILD FAILURE ==="
tail -n 30 "$INSTALL_LOG"
echo -e "\n${YELLOW}Troubleshooting:"
echo -e "1. Verify FPC is installed: fpc -v"
echo -e "2. Check dependencies: dpkg -l | grep 'libgtk2.0-dev\|libx11-dev'"
echo -e "3. Clean and retry: make -C ide clean ide"
echo -e "========================${NC}"
error_msg "IDE build failed"
}
# Step 2: Build the LCL (Lazarus Component Library)
status_msg "Building LCL components (Step 2/3)..."
make -C lcl clean all >> "$INSTALL_LOG" 2>&1 || {
echo -e "\n${RED}=== LCL BUILD FAILURE ==="
tail -n 30 "$INSTALL_LOG"
echo -e "\n${YELLOW}Troubleshooting:"
echo -e "1. Check disk space: df -h"
echo -e "2. Try with single core: make -j1 -C lcl all"
echo -e "========================${NC}"
error_msg "LCL build failed"
}
# Step 3: Build everything
status_msg "Building complete system (Step 3/3)..."
make -j$BUILD_JOBS all >> "$INSTALL_LOG" 2>&1 || {
echo -e "\n${RED}=== BUILD FAILURE ==="
tail -n 30 "$INSTALL_LOG"
echo -e "\n${YELLOW}Troubleshooting:"
echo -e "1. Try with single core: make -j1 all"
echo -e "2. Check memory: free -h"
echo -e "3. Clean and restart: make clean all"
echo -e "========================${NC}"
error_msg "Main build failed"
}
# Install
status_msg "Installing system-wide..."
sudo make install >> "$INSTALL_LOG" 2>&1 || error_msg "Installation failed"
# Verify
[ -x "$LAZARUS_EXEC" ] || error_msg "Lazarus executable not found"
sudo ln -sf "$LAZARUS_EXEC" /usr/bin/lazarus
# Final checks
status_msg "Verifying installation..."
if ! command_exists lazarus; then
warning_msg "Lazarus not in PATH, you may need to log out and back in"
else
lazarus --version >> "$INSTALL_LOG" 2>&1 || warning_msg "Version check failed"
fi
success_msg "Lazarus successfully installed to $LAZARUS_EXEC"
}
# Create desktop file
create_desktop() {
status_msg "Creating desktop shortcut..."
mkdir -p "$(dirname "$DESKTOP_FILE")"
# Find suitable icon
local icon_path="$ICON_PATH"
[ -f "$icon_path" ] || icon_path="/usr/share/pixmaps/lazarus.xpm"
[ -f "$icon_path" ] || icon_path="/usr/share/icons/hicolor/48x48/apps/lazarus.png"
[ -f "$icon_path" ] || icon_path=""
cat > "$DESKTOP_FILE" <<EOL
[Desktop Entry]
Name=Lazarus IDE
GenericName=IDE
Comment=Free Pascal IDE
Exec=$LAZARUS_EXEC --pcp=\$HOME/.lazarus
Icon=$icon_path
Terminal=false
Type=Application
Categories=Development;IDE;Programming;
StartupWMClass=lazarus
Keywords=editor;Pascal;IDE;FreePascal;fpc;design;delphi;
EOL
[ -f "$DESKTOP_FILE" ] || warning_msg "Desktop file creation failed"
update-desktop-database "$HOME/.local/share/applications" >> "$INSTALL_LOG" 2>&1
success_msg "Desktop shortcut created"
}
# Main installation menu
show_menu() {
echo -e "\n${YELLOW}Installation Method:${NC}"
echo -e "1) Clean Install from Source (Recommended)"
echo -e "2) Install from System Repositories"
echo -e "3) Install from Local .deb Packages"
echo -e "4) Exit"
echo -ne "\n${CYAN}Select option [1-4]: ${NC}"
}
# Main function
main() {
show_banner
init_log
check_root
get_sudo
# Cleanup existing installations
cleanup_old_install
# Install dependencies
install_deps
# Installation method selection
while true; do
show_menu
read -r choice
case $choice in
1) install_source; break ;;
2) sudo apt-get install -y lazarus; break ;;
3) sudo dpkg -i ./*.deb; sudo apt-get -f install; break ;;
4) echo -e "\n${YELLOW}Installation cancelled.${NC}"; exit 0 ;;
*) echo -e "${RED}Invalid choice!${NC}" ;;
esac
done
# Final setup
create_desktop
# Completion message
echo -e "\n${GREEN}# ====================================${NC}"
echo -e "${GREEN}# LAZARUS INSTALLATION COMPLETE! ${NC}"
echo -e "${GREEN}# ====================================${NC}"
echo -e "Launch with: ${CYAN}lazarus${NC}"
echo -e "Install log: ${CYAN}$INSTALL_LOG${NC}"
echo -e "\n${YELLOW}System Status:${NC}"
df -h /
free -h
}
# Start installation
main "$@"