Repository navigation
Expand file tree
/
Copy pathinstall-linux.sh
More file actions
807 lines (744 loc) · 29.9 KB
/
Copy pathinstall-linux.sh
File metadata and controls
807 lines (744 loc) · 29.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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
#!/usr/bin/env bash
#
# OpenMouse Desktop Linux installer.
#
# curl -fsSL https://raw.githubusercontent.com/OpenMouse-Project/Desktop/main/install-linux.sh | bash
#
# Flags go after `--`:
#
# curl -fsSL https://raw.githubusercontent.com/OpenMouse-Project/Desktop/main/install-linux.sh | bash -s -- --tag v1.1.0 --yes
#
# What it does:
# 1. Detects the distro package manager and checks for the runtime
# libraries OpenMouse Desktop needs (udev, XCB/XKB/Wayland, Vulkan,
# polkit, tar, curl).
# Missing packages are installed with sudo (or skipped with --no-deps).
# 2. Downloads the Linux release tarball of the latest stable release (or of
# --tag, which also takes the Arch dev prereleases), verifies its SHA-256
# checksum, and extracts it to the install dir.
# 3. Installs the mouse-only hidraw udev rule + helper so mice are accessible
# without root (same rule the app's built-in "Fix permissions" prompt uses).
# 4. Optionally registers login autostart (~/.config/autostart/openmouse.desktop,
# matching gpui/src/autostart.rs), unless --no-autostart.
# 5. Installs a GNOME/KDE launcher entry
# (~/.local/share/applications/app.openmouse.desktop.desktop), unless --no-launcher.
set -euo pipefail
REPO="OpenMouse-Project/Desktop"
TAG="" # empty = latest stable release
INSTALL_DIR=""
BIN_LINK_DIR=""
SYSTEM=false
WITH_DEPS=true
WITH_UDEV=true
WITH_AUTOSTART=false
WITH_LAUNCHER=true
START=false
UNINSTALL=false
ASSUME_YES=false
PREVIEW=false
# The hidraw udev rule and its helper. Kept byte-identical to RULE_TEMPLATE and
# HELPER in gpui/src/hid_access.rs (a Rust unit test checks they match).
UDEV_RULE="/etc/udev/rules.d/69-openmouse-desktop.rules"
UDEV_HELPER="/etc/udev/openmouse-desktop-is-mouse"
# Terminal styling (auto-disabled when stdout is not a TTY or NO_COLOR is set).
if [ -z "${NO_COLOR:-}" ] && { [ -t 1 ] || [ "${FORCE_COLOR:-}" = "1" ]; }; then
C_RESET=$'\033[0m'
C_BOLD=$'\033[1m'
C_DIM=$'\033[2m'
C_ACCENT=$'\033[38;2;93;222;137m'
C_CYAN=$'\033[38;2;125;211;252m'
C_WARN=$'\033[38;2;251;191;36m'
C_ERR=$'\033[38;2;248;113;113m'
else
C_RESET="" C_BOLD="" C_DIM="" C_ACCENT="" C_CYAN="" C_WARN="" C_ERR=""
fi
term_cols() {
local c=""
if [ -n "${COLUMNS:-}" ] && [ "${COLUMNS:-0}" -gt 0 ] 2>/dev/null; then
c="$COLUMNS"
elif command -v tput >/dev/null 2>&1; then
c="$(tput cols 2>/dev/null || true)"
fi
case "$c" in
''|*[!0-9]*) c=80 ;;
esac
[ "$c" -lt 40 ] && c=40
printf '%s' "$c"
}
repeat_ch() {
local ch="$1" n="$2" out="" i=0
while [ "$i" -lt "$n" ]; do out="${out}${ch}"; i=$((i + 1)); done
printf '%s' "$out"
}
box_inner_width() {
local cols inner
cols="$(term_cols)"
inner=$((cols - 6))
[ "$inner" -gt 72 ] && inner=72
[ "$inner" -lt 36 ] && inner=36
printf '%s' "$inner"
}
print_banner() {
local cols
cols="$(term_cols)"
printf '\n'
if [ "$cols" -ge 62 ]; then
printf ' %s ____ __ __ %s\n' "$C_ACCENT" "$C_RESET"
printf ' %s / __ \\____ ___ ____ / |/ /___ __ __________ %s\n' "$C_ACCENT" "$C_RESET"
printf ' %s / / / / __ \\/ _ \\/ __ \\/ /|_/ / __ \\/ / / / ___/ _ \\ %s\n' "$C_ACCENT" "$C_RESET"
printf ' %s/ /_/ / /_/ / __/ / / / / / / /_/ / /_/ (__ ) __/ %s\n' "$C_ACCENT" "$C_RESET"
printf ' %s\\____/ .___/\\___/_/ /_/_/ /_/\\____/\\__,_/____/\\___/ %s\n' "$C_ACCENT" "$C_RESET"
printf ' %s /_/ %sDesktop Installer %s· Linux x86_64 · openmouse.app%s\n' "$C_ACCENT" "$C_BOLD" "$C_DIM" "$C_RESET"
else
printf ' %s● %sOpenMouse Desktop%s %s· Linux x86_64%s\n' "$C_ACCENT" "$C_BOLD" "$C_RESET" "$C_DIM" "$C_RESET"
fi
printf '\n'
}
print_card_row() {
local inner="$1" label="$2" val="$3" val_color="${4:-}"
local val_w=$((inner - 15))
[ "$val_w" -lt 10 ] && val_w=10
local v_short="${val:0:$val_w}"
printf ' %s│%s %s%-11s%s %s%-*s%s %s│%s\n' \
"$C_DIM" "$C_RESET" "$C_DIM" "$label" "$C_RESET" "$val_color" "$val_w" "$v_short" "$C_RESET" "$C_DIM" "$C_RESET"
}
print_env_card() {
local distro="$1" session="$2" pm="$3" channel="$4" dir="$5" perm="$6"
local inner dash_top dash_bot
inner="$(box_inner_width)"
dash_top="$(repeat_ch '─' "$((inner - 16))")"
dash_bot="$(repeat_ch '─' "$inner")"
printf ' %s┌─ System & Plan %s┐%s\n' "$C_DIM" "$dash_top" "$C_RESET"
if [ "$inner" -ge 58 ]; then
local left_w=$((inner - 38))
local d_short="${distro:0:$left_w}" s_short="${session:0:$left_w}"
printf ' %s│%s %s%-11s%s %s%-*s%s %s%-9s%s %-12s %s│%s\n' \
"$C_DIM" "$C_RESET" "$C_DIM" "Distro" "$C_RESET" "$C_BOLD" "$left_w" "$d_short" "$C_RESET" "$C_DIM" "Arch" "$C_RESET" "x86_64" "$C_DIM" "$C_RESET"
printf ' %s│%s %s%-11s%s %-*s %s%-9s%s %-12s %s│%s\n' \
"$C_DIM" "$C_RESET" "$C_DIM" "Session" "$C_RESET" "$left_w" "$s_short" "$C_DIM" "Pkg Mgr" "$C_RESET" "$pm" "$C_DIM" "$C_RESET"
else
print_card_row "$inner" "Distro" "$distro" "$C_BOLD"
print_card_row "$inner" "Session" "$session" ""
print_card_row "$inner" "Pkg Mgr" "$pm (x86_64)" ""
fi
print_card_row "$inner" "Release" "$channel" "$C_CYAN"
print_card_row "$inner" "Install" "$dir" "$C_CYAN"
print_card_row "$inner" "Permissions" "$perm" ""
printf ' %s└%s┘%s\n' "$C_DIM" "$dash_bot" "$C_RESET"
}
detect_distro() {
if [ -r /etc/os-release ]; then
local name
name="$(sed -n 's/^PRETTY_NAME=//p' /etc/os-release | head -n1 | tr -d '"')"
if [ -n "$name" ]; then
printf '%s' "$name"
return
fi
fi
uname -sr
}
detect_session() {
local stype="${XDG_SESSION_TYPE:-unknown}"
local desktop="${XDG_CURRENT_DESKTOP:-}"
if [ -n "$desktop" ]; then
printf '%s (%s)' "$stype" "$desktop"
else
printf '%s' "$stype"
fi
}
step() {
local idx="$1" total="$2" msg="$3"
printf '\n %s[%s/%s]%s %s%s%s\n' "$C_ACCENT" "$idx" "$total" "$C_RESET" "$C_BOLD" "$msg" "$C_RESET"
}
ok() { printf ' %s✓%s %s\n' "$C_ACCENT" "$C_RESET" "$*"; }
info() { printf ' %s·%s %s%s%s\n' "$C_DIM" "$C_RESET" "$C_DIM" "$*" "$C_RESET"; }
note() { printf ' %s›%s %s\n' "$C_CYAN" "$C_RESET" "$*"; }
log() { printf ' %s==>%s %s\n' "$C_ACCENT" "$C_RESET" "$*"; }
warn() { printf ' %s!%s %s%s%s\n' "$C_WARN" "$C_RESET" "$C_WARN" "$*" "$C_RESET" >&2; }
die() { printf '\n %s✗ Error:%s %s\n\n' "$C_ERR" "$C_RESET" "$*" >&2; exit 1; }
print_summary() {
local dir="$1" link="$2" udev_status="$3" launcher_status="$4" autostart_status="$5" elapsed="$6"
local inner dash line1_pad line2_text line2_pad timing
inner="$(box_inner_width)"
dash="$(repeat_ch '─' "$inner")"
timing="(${elapsed}s)"
# " ✓ OpenMouse Desktop installed! " is 33 display cols
line1_pad=$((inner - 34))
[ "$line1_pad" -lt 0 ] && line1_pad=0
line2_text="Run openmouse-desktop or open it from your app menu."
line2_pad=$((inner - 3 - ${#line2_text}))
printf '\n'
printf ' %s╭%s╮%s\n' "$C_ACCENT" "$dash" "$C_RESET"
if [ "$inner" -ge 44 ]; then
printf ' %s│%s %s✓ OpenMouse Desktop installed!%s %s%-*s%s %s│%s\n' \
"$C_ACCENT" "$C_RESET" "$C_BOLD$C_ACCENT" "$C_RESET" "$C_DIM" "$line1_pad" "$timing" "$C_RESET" "$C_ACCENT" "$C_RESET"
else
printf ' %s│%s %s%-*s%s %s│%s\n' \
"$C_ACCENT" "$C_RESET" "$C_BOLD$C_ACCENT" "$((inner - 3))" "✓ Installed! (${elapsed}s)" "$C_RESET" "$C_ACCENT" "$C_RESET"
fi
if [ "$line2_pad" -ge 0 ]; then
printf ' %s│%s Run %sopenmouse-desktop%s or open it from your app menu.%s %s│%s\n' \
"$C_ACCENT" "$C_RESET" "$C_BOLD" "$C_RESET" "$(repeat_ch ' ' "$line2_pad")" "$C_ACCENT" "$C_RESET"
else
printf ' %s│%s %-*s %s│%s\n' \
"$C_ACCENT" "$C_RESET" "$((inner - 3))" "Run: openmouse-desktop" "$C_ACCENT" "$C_RESET"
fi
printf ' %s╰%s╯%s\n' "$C_ACCENT" "$dash" "$C_RESET"
printf '\n'
printf ' %sInstall dir%s %s\n' "$C_DIM" "$C_RESET" "$dir"
printf ' %sCommand%s %s%s%s\n' "$C_DIM" "$C_RESET" "$C_CYAN" "$link" "$C_RESET"
printf ' %sHID access%s %s\n' "$C_DIM" "$C_RESET" "$udev_status"
printf ' %sApp menu%s %s\n' "$C_DIM" "$C_RESET" "$launcher_status"
printf ' %sAutostart%s %s\n' "$C_DIM" "$C_RESET" "$autostart_status"
printf '\n'
printf ' %sTip:%s Re-run this script anytime to update, or pass %s--uninstall%s to remove.\n\n' \
"$C_DIM" "$C_RESET" "$C_DIM" "$C_RESET"
}
usage() {
cat <<USAGE
Usage: install-linux.sh [options]
Options:
--tag TAG Install release TAG, e.g. v1.1.2 or an Arch dev build such as
v1.0.3-arch-dev.1 (default: the latest stable release)
--dir DIR Install files to DIR (default: ~/.local/share/openmouse-desktop)
--system System-wide install to /opt/openmouse-desktop with a
/usr/local/bin symlink (needs root/sudo)
--no-deps Do not install missing system packages, just skip them
--no-udev Skip the hidraw udev rule (the app will prompt via pkexec instead)
--autostart Enable launch on login (~/.config/autostart/openmouse.desktop)
--no-launcher Skip the GNOME/KDE app-launcher entry
--start Launch OpenMouse Desktop after installing
--uninstall Remove a previous install (dir, symlink, autostart, launcher, udev rule)
--yes Assume yes for package installs
--preview Dry-run visual preview of the installer UI (no changes made)
-h, --help Show this help
USAGE
}
while [ $# -gt 0 ]; do
case "$1" in
--tag) TAG="${2:?--tag needs a value}"; shift 2 ;;
--dir) INSTALL_DIR="${2:?--dir needs a value}"; shift 2 ;;
--system) SYSTEM=true; shift ;;
--no-deps) WITH_DEPS=false; shift ;;
--no-udev) WITH_UDEV=false; shift ;;
--autostart) WITH_AUTOSTART=true; shift ;;
--no-launcher) WITH_LAUNCHER=false; shift ;;
--start) START=true; shift ;;
--uninstall) UNINSTALL=true; shift ;;
--yes) ASSUME_YES=true; shift ;;
--preview) PREVIEW=true; shift ;;
-h|--help) usage; exit 0 ;;
*) die "unknown option: $1 (see --help)" ;;
esac
done
sudo_cmd() {
if [ "$(id -u)" -eq 0 ]; then
echo ""
elif command -v sudo >/dev/null 2>&1; then
echo "sudo"
else
echo "none"
fi
}
detect_pm() {
if command -v pacman >/dev/null 2>&1; then echo "pacman"; return; fi
if command -v apt-get >/dev/null 2>&1; then echo "apt"; return; fi
if command -v dnf >/dev/null 2>&1; then echo "dnf"; return; fi
if command -v zypper >/dev/null 2>&1; then echo "zypper"; return; fi
echo "unknown"
}
pm_packages() {
case "$1" in
pacman) echo "systemd-libs libxkbcommon libxkbcommon-x11 libxcb wayland vulkan-icd-loader polkit curl tar ca-certificates" ;;
apt) echo "libudev1 libxkbcommon0 libxkbcommon-x11-0 libxcb1 libxcb-xkb1 libwayland-client0 libvulkan1 policykit-1 curl tar ca-certificates" ;;
dnf) echo "systemd-libs libxkbcommon libxkbcommon-x11 libxcb libwayland-client vulkan-loader polkit curl tar ca-certificates" ;;
zypper) echo "libudev1 libxkbcommon0 libxkbcommon-x11-0 libxcb1 libxcb-xkb1 libwayland-client0 libvulkan1 polkit curl tar ca-certificates" ;;
*) return 1 ;;
esac
}
pkg_installed() {
case "$1" in
pacman) pacman -Qq "$2" >/dev/null 2>&1 ;;
apt) dpkg-query -W -f='${Status}' "$2" 2>/dev/null | grep -q "install ok installed" ;;
dnf|zypper) rpm -q "$2" >/dev/null 2>&1 ;;
*) return 1 ;;
esac
}
missing_pkgs() {
local pm="$1" pkg
for pkg in $(pm_packages "$pm"); do
if ! pkg_installed "$pm" "$pkg"; then
echo "$pkg"
fi
done
}
install_pkgs() {
local pm="$1"
shift
local sudo="$1"
shift
local yes_flags=""
if [ "$ASSUME_YES" = true ]; then
case "$pm" in
pacman) yes_flags="--noconfirm" ;;
apt) yes_flags="-y" ;;
dnf) yes_flags="-y" ;;
zypper) yes_flags="--non-interactive" ;;
esac
fi
case "$pm" in
pacman)
# shellcheck disable=SC2086
$sudo pacman -S --needed $yes_flags "$@"
;;
apt)
$sudo apt-get update
# shellcheck disable=SC2086
$sudo apt-get install $yes_flags "$@"
;;
dnf)
# shellcheck disable=SC2086
$sudo dnf install $yes_flags "$@"
;;
zypper)
# shellcheck disable=SC2086
$sudo zypper install $yes_flags "$@"
;;
esac
}
download() {
local url="$1" dest="$2" show_progress="${3:-false}"
if command -v curl >/dev/null 2>&1; then
if [ "$show_progress" = true ] && [ -t 1 ]; then
curl -fSL --progress-bar "$url" -o "$dest"
else
curl -fsSL "$url" -o "$dest"
fi
elif command -v wget >/dev/null 2>&1; then
if [ "$show_progress" = true ] && [ -t 1 ]; then
wget --show-progress -qO "$dest" "$url"
else
wget -qO "$dest" "$url"
fi
else
die "neither curl nor wget is installed"
fi
}
VERIFIED_SHA256=""
verify_sha256() {
local file="$1" sumfile="$2" expected actual
expected="$(awk '{print $1}' "$sumfile" | head -n1)"
if command -v sha256sum >/dev/null 2>&1; then
actual="$(sha256sum "$file" | awk '{print $1}')"
elif command -v shasum >/dev/null 2>&1; then
actual="$(shasum -a 256 "$file" | awk '{print $1}')"
else
die "neither sha256sum nor shasum is available to verify download"
fi
[ -n "$expected" ] && [ "$expected" = "$actual" ] || die "SHA-256 mismatch for $file (expected $expected, got $actual)"
VERIFIED_SHA256="$actual"
}
install_root_file() {
local src="$1" dst="$2" sudo="$3"
$sudo install -D -m 0644 "$src" "$dst"
}
write_udev_rule() {
local access
if [ -d /run/systemd/seats ]; then
access='TAG+="uaccess"'
else
access="OWNER=\"$(id -u)\", MODE=\"0600\""
fi
sed "s|@ACCESS@|$access|" >"$1" <<'OPENMOUSE_UDEV_RULE'
# OpenMouse Desktop: let the signed-in user reach mice over hidraw.
# Installed by OpenMouse Desktop; safe to delete on uninstall.
# Every hidraw node of a USB device with a mouse interface (a mouse or its
# receiver), including the vendor interface its settings go through.
SUBSYSTEM=="hidraw", SUBSYSTEMS=="usb", PROGRAM="/bin/sh /etc/udev/openmouse-desktop-is-mouse %S%p", @ACCESS@
OPENMOUSE_UDEV_RULE
}
write_udev_helper() {
cat >"$1" <<'OPENMOUSE_UDEV_HELPER'
#!/bin/sh
# OpenMouse Desktop udev helper for /etc/udev/rules.d/69-openmouse-desktop.rules;
# safe to delete with it. Succeeds when the hidraw device at sysfs path $1
# belongs to a USB device with a mouse interface: a boot-protocol mouse, or a
# HID interface whose report descriptor has a Generic Desktop Mouse collection.
dev=$(readlink -f "$1/device") || exit 1
while [ ! -f "$dev/bNumInterfaces" ]; do
[ "$dev" != / ] || exit 1
dev=$(dirname "$dev")
done
interfaces="$dev/${dev##*/}:"
want=$(($(cat "$dev/bNumInterfaces")))
# Whether report descriptor $1 has a Generic Desktop Mouse application
# collection. Parses HID items, so a Report ID between the Usage Page and the
# Usage, or a 2-byte Usage Page, still counts. Short usages take the Usage
# Page in force at the main item; 4-byte usages carry their own.
is_mouse_descriptor() {
set -- $(od -An -tu1 -v "$1")
page=0
usages=""
while [ "$#" -gt 0 ]; do
prefix=$1
shift
if [ "$prefix" -eq 254 ]; then
[ "$#" -ge 2 ] || return 1
skip=$(($1 + 2))
[ "$#" -ge "$skip" ] || return 1
shift "$skip"
continue
fi
size=$((prefix & 3))
[ "$size" -eq 3 ] && size=4
[ "$#" -ge "$size" ] || return 1
value=0
byte=0
while [ "$byte" -lt "$size" ]; do
value=$((value | ($1 << (8 * byte))))
shift
byte=$((byte + 1))
done
kind=$(((prefix >> 2) & 3))
case "$kind:$((prefix >> 4))" in
1:0) page=$value ;;
2:0)
if [ "$size" -eq 4 ]; then usages="$usages $value"; else usages="$usages s$value"; fi
;;
0:10)
if [ "$value" -eq 1 ]; then
for usage in $usages; do
case "$usage" in s*) usage=$(((page << 16) | ${usage#s})) ;; esac
[ "$usage" -eq 65538 ] && return 0
done
fi
;;
esac
[ "$kind" -eq 0 ] && usages=""
done
return 1
}
# On hotplug the interfaces, and the report descriptors under them, appear
# one by one: wait (up to a second) until every interface and every HID
# interface's descriptor is there.
complete() {
count=0
for interface in "$interfaces"*; do
[ -e "$interface" ] || return 1
count=$((count + 1))
[ "$(cat "$interface/bInterfaceClass" 2>/dev/null)" = 03 ] || continue
for descriptor in "$interface"/*/report_descriptor; do
[ -e "$descriptor" ] || return 1
done
done
[ "$count" -ge "$want" ]
}
tries=0
until complete || [ "$tries" -ge 10 ]; do
tries=$((tries + 1))
sleep 0.1
done
for interface in "$interfaces"*; do
[ "$(cat "$interface/bInterfaceClass" 2>/dev/null)" = 03 ] || continue
[ "$(cat "$interface/bInterfaceProtocol" 2>/dev/null)" = 02 ] && exit 0
for descriptor in "$interface"/*/report_descriptor; do
[ -r "$descriptor" ] && is_mouse_descriptor "$descriptor" && exit 0
done
done
exit 1
OPENMOUSE_UDEV_HELPER
}
missing_libs() {
command -v ldd >/dev/null 2>&1 || return 0
ldd "$1" 2>/dev/null | awk '/=> not found/ {print $1}' | tr '\n' ' '
}
write_autostart() {
local dest="$1" binary="$2"
mkdir -p "$(dirname "$dest")"
cat >"$dest" <<EOF
[Desktop Entry]
Type=Application
Name=OpenMouse Desktop
Exec="$binary" --autostart
X-GNOME-Autostart-enabled=true
EOF
}
write_launcher() {
local dest="$1" binary="$2" icon="$3"
mkdir -p "$(dirname "$dest")"
{
echo "[Desktop Entry]"
echo "Type=Application"
echo "Name=OpenMouse Desktop"
echo "Comment=Configure gaming mice and keyboards"
echo "Exec=\"$binary\""
if [ -f "$icon" ]; then
echo "Icon=$icon"
fi
echo "Terminal=false"
echo "Categories=Utility;Settings;HardwareSettings;"
} >"$dest"
}
update_desktop_database() {
if command -v update-desktop-database >/dev/null 2>&1; then
update-desktop-database -q "$HOME/.local/share/applications" 2>/dev/null || true
fi
if command -v kbuildsycoca6 >/dev/null 2>&1; then
kbuildsycoca6 >/dev/null 2>&1 || true
elif command -v kbuildsycoca5 >/dev/null 2>&1; then
kbuildsycoca5 >/dev/null 2>&1 || true
fi
}
do_uninstall() {
local dir="$1" link="$2" desktop="$3" rule="$4" sudo="$5" root="$6" launcher="$7"
log "Removing ${dir}, ${link}, autostart entry, launcher entry, and udev rule (if present)..."
$root rm -f "$link"
$root rm -rf "$dir"
rm -f "$desktop" "$launcher"
if [ -f "$rule" ] || [ -f "$UDEV_HELPER" ]; then
if [ "$sudo" = "none" ]; then
die "cannot remove $rule and $UDEV_HELPER without root; delete them manually"
fi
$sudo rm -f "$rule" "$UDEV_HELPER"
$sudo udevadm control --reload-rules 2>/dev/null || true
fi
update_desktop_database
log "Uninstalled."
}
run_preview() {
print_banner
print_env_card \
"CachyOS Linux" \
"wayland (KDE)" \
"pacman" \
"${TAG:-latest stable}" \
"~/.local/share/openmouse-desktop" \
"mouse-only hidraw udev rule (uses sudo)"
info "Preview mode - no files or system settings will be modified."
step 1 5 "Checking system dependencies"
info "Required: udev, xkbcommon, xcb, wayland, vulkan, polkit, curl, tar"
ok "All runtime libraries already installed via pacman"
step 2 5 "Downloading OpenMouse Desktop (${TAG:-latest stable})"
info "Source: github.com/${REPO}/releases/latest"
info "Asset: openmouse-desktop-linux-x86_64.tar.gz"
local p=0 bar_w filled empty bar_f bar_e
bar_w=$(( $(box_inner_width) - 24 ))
[ "$bar_w" -lt 16 ] && bar_w=16
while [ "$p" -le 100 ]; do
filled=$((p * bar_w / 100))
empty=$((bar_w - filled))
bar_f="$(repeat_ch '█' "$filled")"
bar_e="$(repeat_ch '░' "$empty")"
printf '\r %s%s%s%s%s %3d%% %s18.4 MB%s' \
"$C_ACCENT" "$bar_f" "$C_DIM" "$bar_e" "$C_RESET" "$p" "$C_DIM" "$C_RESET"
p=$((p + 5))
sleep 0.04
done
printf '\n'
ok "SHA-256 verified (a5814b23…8001782)"
step 3 5 "Installing binary & verifying libraries"
ok "Extracted to ~/.local/share/openmouse-desktop"
ok "Linked command at ~/.local/bin/openmouse-desktop"
ok "All shared libraries resolved (ldd clean)"
step 4 5 "Configuring hidraw mouse permissions (udev)"
note "Password may be requested via sudo to allow non-root mouse access"
ok "Installed /etc/udev/rules.d/69-openmouse-desktop.rules"
ok "Reloaded udev rules - replug your mouse if already connected"
step 5 5 "Setting up desktop integration"
ok "App menu launcher installed (~/.local/share/applications)"
info "Autostart disabled (pass --autostart to enable on login)"
print_summary \
"~/.local/share/openmouse-desktop" \
"~/.local/bin/openmouse-desktop" \
"udev rule active (no root required)" \
"installed (GNOME / KDE)" \
"off (rerun with --autostart to enable)" \
"3"
}
main() {
if [ "$PREVIEW" = true ]; then
run_preview
return 0
fi
local start_ts
start_ts="$(date +%s)"
print_banner
local os arch
os="$(uname -s)"
if [ "$os" = "Darwin" ]; then
die "This script is for Linux. Download the macOS disk image instead: https://github.com/${REPO}/releases/latest/download/OpenMouse.dmg"
fi
arch="$(uname -m)"
[ "$arch" = "x86_64" ] || die "unsupported architecture: $arch (only x86_64 Linux builds are published)"
local data_home="${XDG_DATA_HOME:-$HOME/.local/share}"
local config_home="${XDG_CONFIG_HOME:-$HOME/.config}"
if [ -z "$INSTALL_DIR" ]; then
if [ "$SYSTEM" = true ]; then INSTALL_DIR="/opt/openmouse-desktop"; else INSTALL_DIR="$data_home/openmouse-desktop"; fi
fi
if [ -z "$BIN_LINK_DIR" ]; then
if [ "$SYSTEM" = true ]; then BIN_LINK_DIR="/usr/local/bin"; else BIN_LINK_DIR="$HOME/.local/bin"; fi
fi
local binary="$INSTALL_DIR/openmouse-desktop"
local link="$BIN_LINK_DIR/openmouse-desktop"
local desktop="$config_home/autostart/openmouse.desktop"
local launcher="$data_home/applications/app.openmouse.desktop.desktop"
local icon="$INSTALL_DIR/openmouse-app-icon.png"
local sudo
sudo="$(sudo_cmd)"
local root=""
[ -w "$(dirname "$INSTALL_DIR")" ] || root="$sudo"
if [ "$UNINSTALL" = true ]; then
do_uninstall "$INSTALL_DIR" "$link" "$desktop" "$UDEV_RULE" "$sudo" "$root" "$launcher"
return 0
fi
local pm distro session perm_plan
pm="$(detect_pm)"
distro="$(detect_distro)"
session="$(detect_session)"
if [ "$WITH_UDEV" = true ]; then
perm_plan="mouse-only hidraw udev rule (uses sudo)"
else
perm_plan="skipped (--no-udev; app uses pkexec)"
fi
print_env_card "$distro" "$session" "$pm" "${TAG:-latest stable}" "$INSTALL_DIR" "$perm_plan"
# 1. System dependencies.
step 1 5 "Checking system dependencies"
info "Required: udev, xkbcommon, xcb, wayland, vulkan, polkit, curl, tar"
if [ "$WITH_DEPS" = true ]; then
if [ "$pm" = "unknown" ]; then
warn "no supported package manager found (pacman, apt, dnf, zypper); continuing without installing dependencies"
else
local missing
missing="$(missing_pkgs "$pm")"
if [ -n "$missing" ]; then
note "Installing missing packages via $pm (may prompt for sudo password):"
info "$missing"
if [ "$sudo" = "none" ]; then
die "cannot install packages without root; rerun with sudo or pass --no-deps"
fi
# shellcheck disable=SC2086
if install_pkgs "$pm" "$sudo" $missing; then
ok "System packages installed"
else
warn "package installation via $pm failed; continuing (missing libraries will be checked after extract)"
fi
else
ok "All runtime libraries already installed via $pm"
fi
fi
else
info "Skipped (--no-deps)"
fi
# 2. Download + verify.
# Stable releases carry a fixed-name tarball, so "latest" is a permanent
# URL. Older Arch dev prereleases name it after the tag instead.
step 2 5 "Downloading OpenMouse Desktop (${TAG:-latest stable})"
local asset="openmouse-desktop-linux-x86_64.tar.gz"
local base_url="https://github.com/${REPO}/releases/latest/download"
[ -z "$TAG" ] || base_url="https://github.com/${REPO}/releases/download/${TAG}"
local tmp
tmp="$(mktemp -d)"
trap "rm -rf \"$tmp\"" EXIT
info "Source: $base_url"
info "Asset: $asset"
if ! download "${base_url}/${asset}" "$tmp/$asset" true; then
[ -n "$TAG" ] || die "could not download ${base_url}/${asset}"
asset="openmouse-desktop-${TAG}-arch-x86_64.tar.gz"
info "Retrying with Arch dev archive: $asset"
download "${base_url}/${asset}" "$tmp/$asset" true || die "release $TAG has no Linux tarball (looked for openmouse-desktop-linux-x86_64.tar.gz and $asset)"
fi
download "${base_url}/${asset}.sha256" "$tmp/$asset.sha256" false || die "could not download the checksum for $asset"
verify_sha256 "$tmp/$asset" "$tmp/$asset.sha256"
local short_sha="${VERIFIED_SHA256:0:8}…${VERIFIED_SHA256: -7}"
ok "SHA-256 verified ($short_sha)"
# 3. Extract.
step 3 5 "Installing binary & verifying libraries"
tar -C "$tmp" -xzf "$tmp/$asset"
if [ ! -w "$(dirname "$INSTALL_DIR")" ]; then
[ "$sudo" = "none" ] && die "cannot write to $(dirname "$INSTALL_DIR"); rerun with sudo or pick --dir"
note "Writing to $INSTALL_DIR requires sudo"
$sudo mkdir -p "$INSTALL_DIR"
$sudo cp -r "$tmp/openmouse-desktop/." "$INSTALL_DIR/"
$sudo chmod +x "$binary"
else
mkdir -p "$INSTALL_DIR"
cp -r "$tmp/openmouse-desktop/." "$INSTALL_DIR/"
chmod +x "$binary"
fi
# Symlink into BIN_LINK_DIR.
if [ ! -w "$(dirname "$BIN_LINK_DIR")" ] || { [ -e "$BIN_LINK_DIR" ] && [ ! -w "$BIN_LINK_DIR" ]; }; then
[ "$sudo" = "none" ] && die "cannot write to $BIN_LINK_DIR; rerun with sudo"
$sudo mkdir -p "$BIN_LINK_DIR"
$sudo ln -sf "$binary" "$link"
else
mkdir -p "$BIN_LINK_DIR"
ln -sf "$binary" "$link"
fi
ok "Extracted to $INSTALL_DIR"
ok "Linked command at $link"
# Confirm the dynamic loader resolves everything.
local missing_lib
missing_lib="$(missing_libs "$binary")"
if [ -n "$missing_lib" ]; then
warn "the loader still cannot find: $missing_lib"
warn "install the distro packages providing them, then rerun"
else
ok "All shared libraries resolved (ldd clean)"
fi
# 4. udev rule for non-root hidraw access.
step 4 5 "Configuring hidraw mouse permissions (udev)"
local udev_status="skipped (--no-udev)"
if [ "$WITH_UDEV" = true ]; then
if [ "$sudo" = "none" ]; then
udev_status="will prompt via pkexec on launch"
warn "skipping udev rule without root; OpenMouse Desktop will prompt via pkexec when opened."
else
note "Password may be requested via sudo to allow non-root mouse access"
write_udev_helper "$tmp/openmouse-desktop-is-mouse"
write_udev_rule "$tmp/69-openmouse-desktop.rules"
install_root_file "$tmp/openmouse-desktop-is-mouse" "$UDEV_HELPER" "$sudo" || die "could not install $UDEV_HELPER"
install_root_file "$tmp/69-openmouse-desktop.rules" "$UDEV_RULE" "$sudo" || die "could not install $UDEV_RULE"
$sudo udevadm control --reload-rules 2>/dev/null || true
$sudo udevadm trigger --subsystem-match=hidraw --action=change 2>/dev/null || true
$sudo udevadm settle --timeout=5 2>/dev/null || true
udev_status="udev rule active (no root required)"
ok "Installed $UDEV_RULE"
ok "Reloaded udev rules - replug your mouse if already connected"
fi
else
info "Skipped (--no-udev)"
fi
# 5. Desktop integration (autostart + launcher).
step 5 5 "Setting up desktop integration"
local autostart_status="off (rerun with --autostart to enable)"
if [ "$WITH_AUTOSTART" = true ]; then
write_autostart "$desktop" "$binary"
autostart_status="enabled ($desktop)"
ok "Login autostart enabled ($desktop)"
else
info "Autostart disabled (pass --autostart to enable on login)"
fi
local launcher_status="skipped (--no-launcher)"
if [ "$WITH_LAUNCHER" = true ]; then
write_launcher "$launcher" "$binary" "$icon"
update_desktop_database
launcher_status="installed (GNOME / KDE)"
ok "App menu launcher installed ($(dirname "$launcher"))"
else
info "Launcher entry skipped (--no-launcher)"
fi
if [ "$START" = true ]; then
info "Starting OpenMouse Desktop..."
nohup "$binary" >/dev/null 2>&1 &
disown || true
fi
local elapsed=$(( $(date +%s) - start_ts ))
print_summary "$INSTALL_DIR" "$link" "$udev_status" "$launcher_status" "$autostart_status" "$elapsed"
case ":$PATH:" in
*":$BIN_LINK_DIR:"*) ;;
*) warn "$BIN_LINK_DIR is not on PATH; add it or run $binary directly" ;;
esac
}
if [ -z "${OPENMOUSE_INSTALL_SOURCED:-}" ]; then
main "$@"
fi