Skip to content

Commit 1ea13fe

Browse files
Add installation script for Processing
1 parent 4206874 commit 1ea13fe

1 file changed

Lines changed: 341 additions & 0 deletions

File tree

install.sh

Lines changed: 341 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,341 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
trap 'cleanup' EXIT
5+
6+
7+
# Global variables
8+
METHOD="" # user-requested method (snap|flatpak|aur|deb|nix|tarball)
9+
DRY_RUN=false
10+
AUTO_YES=false
11+
TEMP_DIR=""
12+
SCRIPT_NAME="$(basename "$0")"
13+
14+
# Default .deb URL
15+
DEB_URL="https://processing.org/download/processing-latest-amd64.deb" # placeholder
16+
17+
18+
# Helper functions
19+
usage() {
20+
cat <<EOF
21+
Usage: $SCRIPT_NAME [options]
22+
23+
Options:
24+
--method snap|flatpak|aur|deb|nix|tarball Force a specific installation method
25+
--dry-run Show actions without executing
26+
--yes, -y Automatic yes to prompts
27+
--list-methods List available installation methods and exit
28+
--help Show this help message
29+
EOF
30+
exit 0
31+
}
32+
33+
list_methods() {
34+
echo "Available installation methods:"
35+
echo " snap – Snap package (auto-updating)"
36+
echo " flatpak – Flatpak from Flathub (auto-updating)"
37+
echo " aur – Arch User Repository (community package)"
38+
echo " deb – Direct .deb download (Debian/Ubuntu native)"
39+
echo " nix – Nix package (NixOS / Nix package manager)"
40+
echo " tarball – Manual download (fallback)"
41+
exit 0
42+
}
43+
44+
error() {
45+
echo "Error: $*" >&2
46+
exit 1
47+
}
48+
49+
confirm() {
50+
if [ "$AUTO_YES" = true ]; then
51+
return 0
52+
fi
53+
local prompt="$1"
54+
local response
55+
read -r -p "$prompt [Y/n] " response || true
56+
case "$response" in
57+
[nN][oO]|[nN]) return 1 ;;
58+
*) return 0 ;;
59+
esac
60+
}
61+
62+
run() {
63+
if [ "$DRY_RUN" = true ]; then
64+
echo "[DRY RUN] $*"
65+
else
66+
"$@"
67+
fi
68+
}
69+
70+
command_exists() {
71+
command -v "$1" >/dev/null 2>&1
72+
}
73+
74+
sudo_run() {
75+
if [ "$DRY_RUN" = true ]; then
76+
echo "[DRY RUN] sudo $*"
77+
return 0
78+
fi
79+
if command_exists sudo; then
80+
sudo "$@"
81+
else
82+
error "sudo is required but not available."
83+
fi
84+
}
85+
86+
cleanup() {
87+
if [ -n "$TEMP_DIR" ] && [ -d "$TEMP_DIR" ]; then
88+
rm -rf "$TEMP_DIR"
89+
fi
90+
}
91+
92+
# Check if Processing is already installed
93+
check_existing() {
94+
if command_exists processing || command_exists Processing; then
95+
echo "Processing appears to already be installed."
96+
if ! confirm "Continue with installation anyway?"; then
97+
echo "Installation aborted."
98+
exit 0
99+
fi
100+
fi
101+
}
102+
103+
104+
# Installation method functions
105+
106+
install_snap() {
107+
check_existing
108+
echo "Installing Processing via Snap..."
109+
if confirm "This will run 'sudo snap install processing --classic'. Continue?"; then
110+
run sudo snap install processing --classic
111+
echo "Snap installation complete."
112+
else
113+
echo "Aborted."
114+
fi
115+
}
116+
117+
install_flatpak() {
118+
check_existing
119+
echo "Installing Processing via Flatpak..."
120+
if confirm "This will run 'flatpak install flathub org.processing.processingide'. Continue?"; then
121+
run flatpak install flathub org.processing.processingide
122+
echo "Flatpak installation complete."
123+
else
124+
echo "Aborted."
125+
fi
126+
}
127+
128+
install_aur() {
129+
check_existing
130+
echo "Installing Processing from AUR..."
131+
132+
local helper=""
133+
if command_exists yay; then
134+
helper="yay"
135+
elif command_exists paru; then
136+
helper="paru"
137+
fi
138+
139+
if [ -n "$helper" ]; then
140+
if confirm "This will run '$helper -S processing'. Continue?"; then
141+
run "$helper" -S processing
142+
echo "AUR installation complete."
143+
else
144+
echo "Aborted."
145+
fi
146+
else
147+
echo "No AUR helper found. Install manually from AUR:"
148+
echo " git clone https://aur.archlinux.org/processing.git"
149+
echo " cd processing && makepkg -si"
150+
fi
151+
}
152+
153+
install_deb_direct() {
154+
check_existing
155+
echo "Installing Processing via direct .deb download..."
156+
local deb_file="$TEMP_DIR/processing.deb"
157+
if confirm "This will download and install the latest .deb package. Continue?"; then
158+
run curl -L -o "$deb_file" "$DEB_URL"
159+
run sudo dpkg -i "$deb_file"
160+
run sudo apt-get install -f -y
161+
echo "Debian package installation complete."
162+
else
163+
echo "Aborted."
164+
fi
165+
}
166+
167+
install_nix() {
168+
check_existing
169+
echo "Installing Processing via Nix..."
170+
if ! command_exists nix; then
171+
echo "Nix package manager not found. Please install Nix first: https://nixos.org/download/"
172+
return 1
173+
fi
174+
if confirm "This will run 'nix profile install nixpkgs#processing'. Continue?"; then
175+
run nix profile install nixpkgs#processing
176+
echo "Nix installation complete. The binary is available as 'Processing' (or 'processing' via symlink)."
177+
else
178+
echo "Aborted."
179+
fi
180+
}
181+
182+
install_tarball() {
183+
check_existing
184+
echo "Installing Processing via direct download..."
185+
echo "This feature is coming soon! For now, you can manually download from:"
186+
echo " https://processing.org/download/"
187+
}
188+
189+
190+
# Distribution detection helpers
191+
192+
is_debian_based() {
193+
if [ -f /etc/debian_version ]; then
194+
return 0
195+
fi
196+
if [ -f /etc/os-release ]; then
197+
. /etc/os-release
198+
case "${ID:-}" in
199+
debian|ubuntu|linuxmint|pop) return 0 ;;
200+
esac
201+
fi
202+
return 1
203+
}
204+
205+
is_arch_based() {
206+
if [ -f /etc/arch-release ]; then
207+
return 0
208+
fi
209+
if [ -f /etc/os-release ]; then
210+
. /etc/os-release
211+
case "${ID:-}" in
212+
arch|manjaro|endeavouros) return 0 ;;
213+
esac
214+
fi
215+
return 1
216+
}
217+
218+
is_nixos() {
219+
if [ -f /etc/NIXOS ] || command_exists nixos-version; then
220+
return 0
221+
fi
222+
return 1
223+
}
224+
225+
has_flathub() {
226+
command_exists flatpak || return 1
227+
flatpak remote-list 2>/dev/null | grep -q flathub
228+
}
229+
230+
has_snap() {
231+
command_exists snap
232+
}
233+
234+
235+
# Main
236+
237+
TEMP_DIR="$(mktemp -d)"
238+
239+
# Parse command-line arguments
240+
while [ $# -gt 0 ]; do
241+
case "$1" in
242+
--method)
243+
[ $# -ge 2 ] || error "--method requires an argument"
244+
METHOD="$2"
245+
shift 2
246+
;;
247+
--dry-run)
248+
DRY_RUN=true
249+
shift
250+
;;
251+
--yes|-y)
252+
AUTO_YES=true
253+
shift
254+
;;
255+
--list-methods)
256+
list_methods
257+
;;
258+
--help)
259+
usage
260+
;;
261+
*)
262+
error "Unknown option: $1"
263+
;;
264+
esac
265+
done
266+
267+
# If override method is provided, use it directly
268+
if [ -n "$METHOD" ]; then
269+
case "$METHOD" in
270+
snap) install_snap ;;
271+
flatpak) install_flatpak ;;
272+
aur) install_aur ;;
273+
deb) install_deb_direct ;;
274+
nix) install_nix ;;
275+
tarball) install_tarball ;;
276+
*) error "Invalid method: $METHOD. Use snap, flatpak, aur, deb, nix, or tarball." ;;
277+
esac
278+
exit 0
279+
fi
280+
281+
282+
# Auto-detection – try most native first
283+
284+
echo "Detecting best installation method for your system..."
285+
286+
# NixOS
287+
if is_nixos; then
288+
echo "NixOS detected."
289+
if confirm "Install Processing via Nix (official package)?"; then
290+
install_nix
291+
exit 0
292+
fi
293+
fi
294+
295+
# Debian/Ubuntu – prefer .deb over snap/flatpak
296+
if is_debian_based; then
297+
echo "Debian/Ubuntu-based system detected."
298+
if confirm "Install Processing via .deb package (native)?"; then
299+
install_deb_direct
300+
exit 0
301+
fi
302+
fi
303+
304+
# Arch Linux – AUR
305+
if is_arch_based; then
306+
echo "Arch-based distribution detected."
307+
if command_exists yay || command_exists paru; then
308+
if confirm "Install Processing from AUR (community package)?"; then
309+
install_aur
310+
exit 0
311+
fi
312+
else
313+
echo "No AUR helper found. You can install manually from AUR:"
314+
echo " git clone https://aur.archlinux.org/processing.git"
315+
echo " cd processing && makepkg -si"
316+
exit 0
317+
fi
318+
fi
319+
320+
# Snap (universal, auto-updating)
321+
if has_snap; then
322+
echo "Snap is available."
323+
if confirm "Install Processing via Snap (auto-updating)?"; then
324+
install_snap
325+
exit 0
326+
fi
327+
fi
328+
329+
# Flatpak (universal, auto-updating)
330+
if has_flathub; then
331+
echo "Flatpak (Flathub) is available."
332+
if confirm "Install Processing via Flatpak (auto-updating)?"; then
333+
install_flatpak
334+
exit 0
335+
fi
336+
fi
337+
338+
# Fallback
339+
echo "No suitable package manager found. Falling back to direct download."
340+
install_tarball
341+
exit 0

0 commit comments

Comments
 (0)