-
-
Notifications
You must be signed in to change notification settings - Fork 96
Expand file tree
/
Copy pathinstall_opendeck.sh
More file actions
executable file
·349 lines (313 loc) · 9.9 KB
/
install_opendeck.sh
File metadata and controls
executable file
·349 lines (313 loc) · 9.9 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
#!/usr/bin/env bash
set -euo pipefail
GITHUB_REPO="nekename/OpenDeck"
FLATHUB_APP_ID="me.amankhanna.opendeck"
UDEV_RULES_URL="https://raw.githubusercontent.com/nekename/OpenDeck/refs/heads/release/src-tauri/bundle/40-streamdeck.rules"
if [ -t 1 ]; then
RED="\033[0;31m"
GREEN="\033[0;32m"
YELLOW="\033[0;33m"
BLUE="\033[0;34m"
BOLD="\033[1m"
RESET="\033[0m"
else
RED=""
GREEN=""
YELLOW=""
BLUE=""
RESET=""
fi
trap 'echo -e "${YELLOW}Need help? Join the Discord: ${BLUE}https://discord.gg/26Nf8rHvaj${RESET}"' EXIT
msg_info() { echo -e "${BLUE}[*]${RESET} $*"; }
msg_ok() { echo -e "${GREEN}[✓] $*${RESET}"; }
msg_warn() { echo -e "${YELLOW}[!] $*${RESET}"; }
msg_error() { echo -e "${RED}[✗] $*${RESET}" >&2; }
has_cmd() { command -v "$1" >/dev/null 2>&1; }
confirm() {
printf "%b$1 [y/N]: %b" "$YELLOW$BOLD" "$RESET"
read -r ans
case "$ans" in
[yY] | [yY][eE][sS]) return 0 ;;
*) return 1 ;;
esac
}
detect_family() {
if has_cmd rpm-ostree || grep -qi "universal blue" /etc/os-release 2>/dev/null; then
echo "ublue"
elif has_cmd pacman; then
echo "arch"
elif has_cmd zypper || has_cmd dnf || has_cmd rpm; then
echo "rpm"
elif has_cmd apt-get || has_cmd dpkg; then
echo "debian"
else
echo "unknown"
fi
}
fetch_latest_asset() {
local ext="$1"
local api_url="https://api.github.com/repos/${GITHUB_REPO}/releases/latest"
local arch arch_deb arch_rpm arch_pattern download_url
arch="$(uname -m)"
case "$arch" in
x86_64)
arch_deb="amd64"
arch_rpm="x86_64"
;;
aarch64)
arch_deb="arm64"
arch_rpm="aarch64"
;;
*)
msg_error "Unsupported architecture $arch"
exit 1
;;
esac
if [ "$ext" = "deb" ]; then
arch_pattern="${arch_deb}"
else
arch_pattern="${arch_rpm}"
fi
if has_cmd curl; then
download_url=$(curl -s --retry 3 --retry-delay 3 "$api_url" |
grep -Eo "https://[^ \"]+${arch_pattern}\.${ext}([^\"]*)" |
head -n1 || true)
elif has_cmd wget; then
download_url=$(wget -qO- --tries=3 "$api_url" |
grep -Eo "https://[^ \"]+${arch_pattern}\.${ext}([^\"]*)" |
head -n1 || true)
fi
if [ -n "$download_url" ]; then
echo "$download_url"
else
msg_error "Failed to find a .${ext} release asset for arch $arch"
return 1
fi
}
download_with_retry() {
local url="$1"
local dest="$2"
if has_cmd curl; then
curl -L --retry 3 --retry-delay 3 -o "$dest" "$url"
else
wget --tries=3 -O "$dest" "$url"
fi
}
reload_udev_rules() {
msg_info "Reloading udev rules"
if ! sudo udevadm control --reload-rules || ! sudo udevadm trigger; then
msg_error "Failed to reload udev rules; you may be able to restart your computer instead"
return 0
fi
msg_ok "Reloaded udev rules"
}
install_flatpak() {
msg_info "Installing ${FLATHUB_APP_ID} from Flathub"
if confirm "Install OpenDeck system-wide? (No = user install)"; then
if ! flatpak remote-list | grep -q flathub; then
msg_error "Flathub remote not found; please add Flathub before running this script"
exit 1
fi
flatpak install flathub "${FLATHUB_APP_ID}"
else
if ! flatpak remote-list --user | grep -q flathub; then
msg_error "Flathub remote not found; please add Flathub before running this script or try installing system-wide"
exit 1
fi
flatpak install --user flathub "${FLATHUB_APP_ID}"
fi
msg_ok "Installed ${FLATHUB_APP_ID} from Flathub"
msg_info "Installing udev rules"
tmp_rules="$(mktemp --suffix=.rules)"
download_with_retry "$UDEV_RULES_URL" "$tmp_rules"
sudo mv "$tmp_rules" /etc/udev/rules.d/40-streamdeck.rules
sudo chmod 644 /etc/udev/rules.d/40-streamdeck.rules
msg_ok "Installed udev rules"
reload_udev_rules
}
install_deb() {
local dl tmpf
dl=$(fetch_latest_asset "deb")
msg_info "Downloading ${dl##*/}"
tmpf="$(mktemp --suffix=.deb)"
download_with_retry "$dl" "$tmpf"
msg_ok "Downloaded ${dl##*/}"
msg_info "Installing .deb package"
sudo apt-get install --fix-broken "$tmpf"
rm -f "$tmpf"
msg_ok "Installed .deb package"
reload_udev_rules
}
install_rpm() {
local dl tmpf
dl=$(fetch_latest_asset "rpm")
msg_info "Downloading ${dl##*/}"
tmpf="$(mktemp --suffix=.rpm)"
download_with_retry "$dl" "$tmpf"
msg_ok "Downloaded ${dl##*/}"
msg_info "Installing .rpm package"
if has_cmd zypper; then
sudo zypper install --allow-unsigned-rpm "$tmpf"
elif has_cmd dnf; then
sudo dnf install --nogpgcheck "$tmpf"
else
sudo rpm -i --nosignature "$tmpf"
fi
rm -f "$tmpf"
msg_ok "Installed .rpm package"
reload_udev_rules
}
install_aur() {
msg_info "Installing from AUR"
msg_info "${BOLD}This script will attempt to use yay, paru, aura, pikaur, or trizen, in that order"
confirm "If you use another AUR helper, you should install OpenDeck manually. Continue?"
if has_cmd yay; then
yay -Sy opendeck
elif has_cmd paru; then
paru -Sy opendeck
elif has_cmd aura; then
aura -Ak opendeck
elif has_cmd pikaur; then
pikaur -Sy opendeck
elif has_cmd trizen; then
trizen -Sy opendeck
else
msg_error "No AUR helper found; install yay, paru, aura, pikaur, or trizen, or install manually"
return 1
fi
msg_ok "Installed from AUR"
reload_udev_rules
}
install_wine_if_needed() {
if has_cmd wine; then
msg_info "Wine already installed"
return
fi
if confirm "Wine is required for some plugins. If you're not sure if you need to install Wine, you can run this script again later. Install Wine now?"; then
msg_info "Installing Wine"
case "$PKG_FAMILY" in
debian)
sudo apt-get update && sudo apt-get install wine
;;
rpm | ublue)
if has_cmd rpm-ostree; then
sudo rpm-ostree install wine wine-mono
elif has_cmd zypper; then
sudo zypper install wine wine-mono
elif has_cmd dnf; then
sudo dnf install wine wine-mono
else
msg_error "No supported package manager found to install Wine; please install it manually"
fi
;;
arch)
sudo pacman -Sy wine wine-mono
;;
*)
msg_error "No supported package manager found to install Wine; please install it manually"
;;
esac
msg_ok "Installed Wine"
else
msg_warn "Not installing Wine"
fi
}
install_node_if_needed() {
if has_cmd node; then
msg_info "Node.js already installed"
return
fi
if confirm "Node.js is required for some plugins. If you're not sure if you need to install Node.js, you can run this script again later. Install Node.js now?"; then
msg_info "Installing Node.js"
case "$PKG_FAMILY" in
debian)
sudo apt-get update && sudo apt-get install nodejs npm
;;
rpm | ublue)
if has_cmd rpm-ostree; then
sudo rpm-ostree install nodejs npm
elif has_cmd zypper; then
sudo zypper install nodejs npm
elif has_cmd dnf; then
sudo dnf install nodejs npm
else
msg_error "No supported package manager found to install Node.js; please install it manually"
fi
;;
arch)
sudo pacman -Sy nodejs npm
;;
*)
msg_error "No supported package manager found to install Node.js; please install it manually"
;;
esac
msg_ok "Installed Node.js"
else
msg_warn "Not installing Node.js"
fi
}
if [ -n "${OPENDECK_PKG_FAMILY:-}" ]; then
PKG_FAMILY="$OPENDECK_PKG_FAMILY"
case "$PKG_FAMILY" in
debian | rpm | arch | ublue)
msg_info "Using package family '${PKG_FAMILY}' from the OPENDECK_PKG_FAMILY environment variable"
;;
*)
msg_error "Invalid OPENDECK_PKG_FAMILY value '${PKG_FAMILY}'"
msg_error "Supported values: debian, rpm, arch, ublue"
exit 1
;;
esac
else
PKG_FAMILY="$(detect_family)"
msg_info "Detected '${PKG_FAMILY}' package family (set the OPENDECK_PKG_FAMILY environment variable to debian, rpm, arch, or ublue to override)"
fi
case "$PKG_FAMILY" in
debian)
install_deb
;;
rpm)
install_rpm
;;
arch)
install_aur
;;
ublue)
install_flatpak
;;
unknown)
if has_cmd flatpak; then
msg_warn "No native package method found"
msg_info "You can continue by installing with Flatpak; if you experience issues, manually install OpenDeck natively"
if confirm "Install with Flatpak?"; then
install_flatpak
else
msg_error "Installation aborted"
exit 1
fi
else
msg_error "No usable installation method found; please install OpenDeck manually"
exit 1
fi
;;
esac
install_wine_if_needed
install_node_if_needed
msg_ok "Installation complete!"
echo -e "${YELLOW}If you enjoy OpenDeck, please consider starring the project on GitHub: ${BLUE}https://github.com/${GITHUB_REPO}${RESET}"
if confirm "Launch OpenDeck now?"; then
if [[ "$PKG_FAMILY" == "ublue" ]] || { [[ "$PKG_FAMILY" == "unknown" ]] && has_cmd flatpak; }; then
flatpak run "${FLATHUB_APP_ID}" &
msg_ok "Launched OpenDeck using Flatpak"
else
if [ -x /bin/opendeck ]; then
/bin/opendeck &
msg_ok "Launched OpenDeck from /bin"
elif has_cmd opendeck; then
opendeck &
msg_ok "Launched OpenDeck from PATH"
else
msg_warn "OpenDeck executable not found"
fi
fi
fi