#!/bin/sh # Installs UniConn on Linux: # # curl -fsSL https://uniconn.live/install.sh | sh # # Run it as yourself, not with sudo; it asks for sudo once, to install the # package. What it does, in order: # 1. checks this is a 64-bit Debian, Ubuntu, Fedora or Arch computer (or # one built on them); # 2. downloads the newest UniConn package for it (.deb, .rpm or the Arch # package) and checks its SHA-256; # 3. moves a developer install of UniConn aside, if there is one; # 4. installs the package with apt, dnf or pacman, which brings what it # needs; with apt it then adds the webcam's kernel module if this kernel # has none and can take one; # 5. starts UniConn's two background services for you. # Your UniConn data (pairings, copies, files) is kept across installs. # # Everything is inside main(), called on the last line, so a download cut # short runs nothing. set -eu main() { base=${UNICONN_DOWNLOADS:-https://downloads.uniconn.live} say() { printf '%s\n' "$*"; } has_module() { /sbin/modinfo v4l2loopback >/dev/null 2>&1 || modinfo v4l2loopback >/dev/null 2>&1; } step() { printf '\n\033[1m%s\033[0m\n' "$*"; } fail() { printf '\nuniconn: %s\n' "$*" >&2 exit 1 } [ "$(uname -s)" = Linux ] || fail "this installer is for Linux. For Windows and Android see https://uniconn.live/download" case "$(uname -m)" in x86_64 | amd64) arch=amd64 ;; *) fail "UniConn's Linux package is for 64-bit Intel and AMD computers for now; this one is $(uname -m)." ;; esac id="" like="" if [ -r /etc/os-release ]; then # shellcheck disable=SC1091 id=$(. /etc/os-release && printf '%s' "${ID:-}") # shellcheck disable=SC1091 like=$(. /etc/os-release && printf '%s' "${ID_LIKE:-}") fi # Which package, by the distribution or the one it is built on. case " $id $like " in *" debian "* | *" ubuntu "*) kind=deb tool=apt-get ;; *" fedora "*) kind=rpm tool=dnf ;; *" arch "*) kind=arch tool=pacman ;; *) fail "UniConn has packages for Debian, Ubuntu, Fedora and Arch. For another distribution, unpack the tarball from https://uniconn.live/download#linux" ;; esac command -v "$tool" >/dev/null 2>&1 || fail "$tool was not found." if [ "$(id -u)" = 0 ]; then if [ -n "${SUDO_USER:-}" ]; then fail "run this as yourself, without sudo: curl -fsSL https://uniconn.live/install.sh | sh" fi sudo="" as_root=1 else command -v sudo >/dev/null 2>&1 || fail "sudo was not found; install the package as root instead." sudo="sudo" as_root=0 fi for tool in curl sha256sum; do command -v "$tool" >/dev/null 2>&1 || fail "$tool was not found." done work=$(mktemp -d) trap 'rm -rf "$work"' EXIT INT TERM # apt reads the package as its own unprivileged user. chmod 755 "$work" step "Finding the newest UniConn" curl -fsSL "$base/linux/$arch/LATEST" -o "$work/LATEST" || fail "could not reach $base; check the internet connection and try again." version=$(sed -n 's/^version=//p' "$work/LATEST") case "$kind" in deb) file=$(sed -n 's/^file=//p' "$work/LATEST") sum=$(sed -n 's/^sha256=//p' "$work/LATEST") pattern="uniconn_*_$arch.deb" ;; *) file=$(sed -n "s/^$kind=//p" "$work/LATEST") sum=$(sed -n "s/^${kind}_sha256=//p" "$work/LATEST") [ -n "$file" ] || fail "UniConn $version has no package for this distribution yet." if [ "$kind" = rpm ]; then pattern="uniconn-*-1.x86_64.rpm"; else pattern="uniconn-*-1-x86_64.pkg.tar.xz"; fi ;; esac # shellcheck disable=SC2254 case "$file" in $pattern) ;; *) fail "the download list is not what was expected; try again later." ;; esac case "$file" in */* | .*) fail "the download list is not what was expected; try again later." ;; esac [ ${#sum} -eq 64 ] || fail "the download list has no checksum; try again later." say "UniConn $version" step "Downloading" curl -fL --progress-bar "$base/linux/$arch/$file" -o "$work/$file" || fail "the download did not finish; try again." printf '%s %s\n' "$sum" "$work/$file" | sha256sum -c --status - || fail "the download does not match its checksum, so it was not installed. Try again." chmod 644 "$work/$file" say "Checked: SHA-256 $sum" # A developer install (scripts/install-linux-*.sh) runs UniConn from the # home directory: its units would hide the package's, and its menu entry # the package's app. It is moved aside, not deleted; the data it used is # the same and stays. Any part of it left behind counts, so a run that # stopped half way is finished by the next. units="${XDG_CONFIG_HOME:-$HOME/.config}/systemd/user" entry="$HOME/.local/share/applications/app.uniconn.client.desktop" if [ "$as_root" = 0 ] && { grep -qs '\.local/libexec/uniconn' "$units/uniconnd.service" "$units/uniconn-session-agent.service" || [ -e "$HOME/.local/libexec/uniconn" ] || [ -e "$HOME/.local/lib/uniconn" ] || grep -qs '\.local/lib/uniconn' "$entry" }; then keep="$HOME/.local/share/uniconn-developer-install-$(date +%Y%m%d-%H%M%S)" step "Moving the developer install aside, to $keep" systemctl --user disable --now uniconnd.service uniconn-session-agent.service >/dev/null 2>&1 || true mkdir -p "$keep" # Each under a name of its own: libexec/uniconn and lib/uniconn share a # base name, and moving the second onto the first failed, which stopped # the install with the app and its menu entry still in place. aside() { if [ -e "$1" ]; then mv "$1" "$keep/$2"; fi; } if grep -qs '\.local/libexec/uniconn' "$units/uniconnd.service"; then aside "$units/uniconnd.service" uniconnd.service fi if grep -qs '\.local/libexec/uniconn' "$units/uniconn-session-agent.service"; then aside "$units/uniconn-session-agent.service" uniconn-session-agent.service fi aside "$HOME/.local/libexec/uniconn" libexec-uniconn aside "$HOME/.local/lib/uniconn" lib-uniconn if grep -qs '\.local/lib/uniconn' "$entry"; then aside "$entry" app.uniconn.client.desktop fi systemctl --user daemon-reload >/dev/null 2>&1 || true fi step "Installing (this asks for your password)" case "$kind" in deb) $sudo apt-get update -qq || say "apt-get update had problems; trying the install anyway." $sudo env DEBIAN_FRONTEND=noninteractive apt-get install -y "$work/$file" || fail "apt could not install the package; the messages above say why." ;; rpm) $sudo dnf install -y "$work/$file" || fail "dnf could not install the package; the messages above say why." ;; arch) $sudo pacman -U --noconfirm --needed "$work/$file" || fail "pacman could not install the package; the messages above say why." ;; esac # The webcam needs the v4l2loopback kernel module. Most Ubuntu kernels have # it; where this one does not, it is built for it, but only when this # kernel's headers can be installed too, since a build that cannot finish # would leave apt half-done. Everything else works without it. # Fedora's module comes from RPM Fusion, and Arch's needs this kernel's # headers: the package says what to install there, rather than this adding # a repository or a kernel package unasked. if [ "$kind" = deb ] && [ "${UNICONN_SKIP_WEBCAM:-0}" != 1 ] && ! has_module; then headers="linux-headers-$(uname -r)" step "Adding the webcam's kernel module" if apt-cache show "$headers" >/dev/null 2>&1 && $sudo env DEBIAN_FRONTEND=noninteractive apt-get install -y "$headers" v4l2loopback-dkms && has_module; then $sudo /usr/lib/uniconn/uniconn-webcam-setup || say "The webcam is not set up yet; the message above says why." else say "This kernel has no webcam module UniConn can add, so the webcam is off; everything else works." fi fi if [ "$as_root" = 0 ]; then step "Starting UniConn's background services" systemctl --user daemon-reload >/dev/null 2>&1 || true systemctl --user enable uniconnd.service uniconn-session-agent.service >/dev/null 2>&1 || true systemctl --user restart uniconnd.service || say "The core service did not start; see: systemctl --user status uniconnd" systemctl --user restart uniconn-session-agent.service >/dev/null 2>&1 || say "The session agent starts with your next desktop sign-in." fi step "UniConn $version is installed" say "Open UniConn from your applications, or run: uniconn" say "Get it on your phone too: https://uniconn.live/download" } main "$@"