-
-
Notifications
You must be signed in to change notification settings - Fork 162
Expand file tree
/
Copy pathinstall.sh
More file actions
341 lines (295 loc) · 8.17 KB
/
install.sh
File metadata and controls
341 lines (295 loc) · 8.17 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
#!/bin/bash
set -euo pipefail
trap 'cleanup' EXIT
# Global variables
METHOD="" # user-requested method (snap|flatpak|aur|deb|nix|tarball)
DRY_RUN=false
AUTO_YES=false
TEMP_DIR=""
SCRIPT_NAME="$(basename "$0")"
# Default .deb URL
DEB_URL="https://processing.org/download/processing-latest-amd64.deb" # placeholder
# Helper functions
usage() {
cat <<EOF
Usage: $SCRIPT_NAME [options]
Options:
--method snap|flatpak|aur|deb|nix|tarball Force a specific installation method
--dry-run Show actions without executing
--yes, -y Automatic yes to prompts
--list-methods List available installation methods and exit
--help Show this help message
EOF
exit 0
}
list_methods() {
echo "Available installation methods:"
echo " snap – Snap package (auto-updating)"
echo " flatpak – Flatpak from Flathub (auto-updating)"
echo " aur – Arch User Repository (community package)"
echo " deb – Direct .deb download (Debian/Ubuntu native)"
echo " nix – Nix package (NixOS / Nix package manager)"
echo " tarball – Manual download (fallback)"
exit 0
}
error() {
echo "Error: $*" >&2
exit 1
}
confirm() {
if [ "$AUTO_YES" = true ]; then
return 0
fi
local prompt="$1"
local response
read -r -p "$prompt [Y/n] " response || true
case "$response" in
[nN][oO]|[nN]) return 1 ;;
*) return 0 ;;
esac
}
run() {
if [ "$DRY_RUN" = true ]; then
echo "[DRY RUN] $*"
else
"$@"
fi
}
command_exists() {
command -v "$1" >/dev/null 2>&1
}
sudo_run() {
if [ "$DRY_RUN" = true ]; then
echo "[DRY RUN] sudo $*"
return 0
fi
if command_exists sudo; then
sudo "$@"
else
error "sudo is required but not available."
fi
}
cleanup() {
if [ -n "$TEMP_DIR" ] && [ -d "$TEMP_DIR" ]; then
rm -rf "$TEMP_DIR"
fi
}
# Check if Processing is already installed
check_existing() {
if command_exists processing || command_exists Processing; then
echo "Processing appears to already be installed."
if ! confirm "Continue with installation anyway?"; then
echo "Installation aborted."
exit 0
fi
fi
}
# Installation method functions
install_snap() {
check_existing
echo "Installing Processing via Snap..."
if confirm "This will run 'sudo snap install processing --classic'. Continue?"; then
run sudo snap install processing --classic
echo "Snap installation complete."
else
echo "Aborted."
fi
}
install_flatpak() {
check_existing
echo "Installing Processing via Flatpak..."
if confirm "This will run 'flatpak install flathub org.processing.processingide'. Continue?"; then
run flatpak install flathub org.processing.processingide
echo "Flatpak installation complete."
else
echo "Aborted."
fi
}
install_aur() {
check_existing
echo "Installing Processing from AUR..."
local helper=""
if command_exists yay; then
helper="yay"
elif command_exists paru; then
helper="paru"
fi
if [ -n "$helper" ]; then
if confirm "This will run '$helper -S processing'. Continue?"; then
run "$helper" -S processing
echo "AUR installation complete."
else
echo "Aborted."
fi
else
echo "No AUR helper found. Install manually from AUR:"
echo " git clone https://aur.archlinux.org/processing.git"
echo " cd processing && makepkg -si"
fi
}
install_deb_direct() {
check_existing
echo "Installing Processing via direct .deb download..."
local deb_file="$TEMP_DIR/processing.deb"
if confirm "This will download and install the latest .deb package. Continue?"; then
run curl -L -o "$deb_file" "$DEB_URL"
run sudo dpkg -i "$deb_file"
run sudo apt-get install -f -y
echo "Debian package installation complete."
else
echo "Aborted."
fi
}
install_nix() {
check_existing
echo "Installing Processing via Nix..."
if ! command_exists nix; then
echo "Nix package manager not found. Please install Nix first: https://nixos.org/download/"
return 1
fi
if confirm "This will run 'nix profile install nixpkgs#processing'. Continue?"; then
run nix profile install nixpkgs#processing
echo "Nix installation complete. The binary is available as 'Processing' (or 'processing' via symlink)."
else
echo "Aborted."
fi
}
install_tarball() {
check_existing
echo "Installing Processing via direct download..."
echo "This feature is coming soon! For now, you can manually download from:"
echo " https://processing.org/download/"
}
# Distribution detection helpers
is_debian_based() {
if [ -f /etc/debian_version ]; then
return 0
fi
if [ -f /etc/os-release ]; then
. /etc/os-release
case "${ID:-}" in
debian|ubuntu|linuxmint|pop) return 0 ;;
esac
fi
return 1
}
is_arch_based() {
if [ -f /etc/arch-release ]; then
return 0
fi
if [ -f /etc/os-release ]; then
. /etc/os-release
case "${ID:-}" in
arch|manjaro|endeavouros) return 0 ;;
esac
fi
return 1
}
is_nixos() {
if [ -f /etc/NIXOS ] || command_exists nixos-version; then
return 0
fi
return 1
}
has_flathub() {
command_exists flatpak || return 1
flatpak remote-list 2>/dev/null | grep -q flathub
}
has_snap() {
command_exists snap
}
# Main
TEMP_DIR="$(mktemp -d)"
# Parse command-line arguments
while [ $# -gt 0 ]; do
case "$1" in
--method)
[ $# -ge 2 ] || error "--method requires an argument"
METHOD="$2"
shift 2
;;
--dry-run)
DRY_RUN=true
shift
;;
--yes|-y)
AUTO_YES=true
shift
;;
--list-methods)
list_methods
;;
--help)
usage
;;
*)
error "Unknown option: $1"
;;
esac
done
# If override method is provided, use it directly
if [ -n "$METHOD" ]; then
case "$METHOD" in
snap) install_snap ;;
flatpak) install_flatpak ;;
aur) install_aur ;;
deb) install_deb_direct ;;
nix) install_nix ;;
tarball) install_tarball ;;
*) error "Invalid method: $METHOD. Use snap, flatpak, aur, deb, nix, or tarball." ;;
esac
exit 0
fi
# Auto-detection – try most native first
echo "Detecting best installation method for your system..."
# NixOS
if is_nixos; then
echo "NixOS detected."
if confirm "Install Processing via Nix (official package)?"; then
install_nix
exit 0
fi
fi
# Debian/Ubuntu – prefer .deb over snap/flatpak
if is_debian_based; then
echo "Debian/Ubuntu-based system detected."
if confirm "Install Processing via .deb package (native)?"; then
install_deb_direct
exit 0
fi
fi
# Arch Linux – AUR
if is_arch_based; then
echo "Arch-based distribution detected."
if command_exists yay || command_exists paru; then
if confirm "Install Processing from AUR (community package)?"; then
install_aur
exit 0
fi
else
echo "No AUR helper found. You can install manually from AUR:"
echo " git clone https://aur.archlinux.org/processing.git"
echo " cd processing && makepkg -si"
exit 0
fi
fi
# Snap (universal, auto-updating)
if has_snap; then
echo "Snap is available."
if confirm "Install Processing via Snap (auto-updating)?"; then
install_snap
exit 0
fi
fi
# Flatpak (universal, auto-updating)
if has_flathub; then
echo "Flatpak (Flathub) is available."
if confirm "Install Processing via Flatpak (auto-updating)?"; then
install_flatpak
exit 0
fi
fi
# Fallback
echo "No suitable package manager found. Falling back to direct download."
install_tarball
exit 0