#!/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 </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" <"$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