#!/bin/sh # Light Share for Linux: installs or updates the app with one command. # # curl -fsSL https://lightshare.markloc.tech/install.sh | sh # # What it does: # 1. Installs FUSE 2 (libfuse.so.2), which the AppImage needs, with your package manager (asks for # your password through sudo). It installs only the FUSE 2 library, never the `fuse` package that # would replace fuse3 on Ubuntu and Debian. # 2. Downloads the latest Light Share zip and puts its AppImage at # ~/Applications/LightShare-x86_64.AppImage. Light Share updates that file in place later. # 3. Adds Light Share to your applications menu and starts it. # # Uninstall (keeps your settings and received files): # curl -fsSL https://lightshare.markloc.tech/install.sh | sh -s -- --uninstall # # Everything sits in functions and runs from the last line, so a download cut short runs nothing. set -eu ZIP_URL="https://download.lightshare.markloc.tech/LightShare-Linux.zip" ICON_URL="https://lightshare.markloc.tech/linux/lightshare.png" GUIDE_URL="https://lightshare.markloc.tech/download/linux" APP_DIR="$HOME/Applications" APP="$APP_DIR/LightShare-x86_64.AppImage" DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}" DESKTOP_FILE="$DATA_HOME/applications/lightshare.desktop" ICON_FILE="$DATA_HOME/icons/hicolor/256x256/apps/lightshare.png" say() { printf '%s\n' "$*"; } step() { printf '\n==> %s\n' "$*"; } warn() { printf 'Warning: %s\n' "$*" >&2; } die() { printf 'Error: %s\n' "$*" >&2; printf 'Install guide: %s\n' "$GUIDE_URL" >&2; exit 1; } have() { command -v "$1" >/dev/null 2>&1; } # Runs a command as root: directly when already root, else through sudo (or doas). as_root() { if [ "$(id -u)" -eq 0 ]; then "$@" elif have sudo; then sudo "$@" elif have doas; then doas "$@" else return 1 fi } download() { # url file if have curl; then curl -fL --progress-bar --retry 3 -o "$2" "$1" elif have wget; then if wget --help 2>&1 | grep -q -- --show-progress; then wget -q --show-progress -O "$2" "$1"; else wget -q -O "$2" "$1"; fi else die "Install curl or wget, then run this again." fi } has_fuse2() { for dir in /lib /lib64 /usr/lib /usr/lib64 /lib/*-linux-gnu /usr/lib/*-linux-gnu /usr/local/lib; do [ -e "$dir/libfuse.so.2" ] && return 0 done for ldconfig in ldconfig /sbin/ldconfig /usr/sbin/ldconfig; do if have "$ldconfig" && "$ldconfig" -p 2>/dev/null | grep -q 'libfuse\.so\.2'; then return 0; fi done return 1 } # The distribution family from /etc/os-release: debian, fedora, arch, suse or unknown. distro_family() { os_id="" id_like="" if [ -r /etc/os-release ]; then os_id=$(. /etc/os-release && printf "%s" "${ID:-}") id_like=$(. /etc/os-release && printf '%s' "${ID_LIKE:-}") fi for word in $os_id $id_like; do case "$word" in debian|ubuntu) echo debian; return ;; fedora|rhel|centos) echo fedora; return ;; arch|archlinux) echo arch; return ;; suse|opensuse|opensuse-leap|opensuse-tumbleweed|sles) echo suse; return ;; esac done if have apt-get; then echo debian elif have dnf; then echo fedora elif have pacman; then echo arch elif have zypper; then echo suse else echo unknown fi } install_fuse2() { step "Installing FUSE 2, which the AppImage needs" family=$(distro_family) case "$family" in debian) say "Running: sudo apt-get install libfuse2t64 (or libfuse2 on older releases)" as_root apt-get install -y libfuse2t64 /dev/null 2>&1 } uninstall() { step "Removing Light Share" rm -f "$APP" "$DESKTOP_FILE" "$ICON_FILE" have update-desktop-database && update-desktop-database "$DATA_HOME/applications" >/dev/null 2>&1 || true say "Removed the app and its menu entry." say "Your settings and paired devices stay in ~/.lightshare. To remove them too:" say " rm -rf ~/.lightshare ~/.java/.userPrefs/markloc" say "Received files stay in Documents/LightShare/Received." } install() { [ "$(uname -s)" = "Linux" ] || die "This installer is for Linux. Get Light Share for other systems at https://lightshare.markloc.tech/download" case "$(uname -m)" in x86_64|amd64) ;; *) die "Light Share for Linux runs on 64-bit Intel or AMD (x86_64) PCs; this one is $(uname -m)." ;; esac fuse_ok=1 if has_fuse2; then say "FUSE 2 is already installed." elif install_fuse2 && has_fuse2; then say "FUSE 2 installed." else fuse_ok=0 warn "Could not install FUSE 2 (see $GUIDE_URL#install-fuse)." warn "Light Share will start without it, unpacking itself on each launch, which is slower." fi can_unzip || install_unzip || true step "Downloading Light Share" tmp=$(mktemp -d "${TMPDIR:-/tmp}/lightshare-install.XXXXXX") trap 'rm -rf "$tmp"' EXIT INT TERM download "$ZIP_URL" "$tmp/LightShare-Linux.zip" mkdir -p "$tmp/zip" extract_zip "$tmp/LightShare-Linux.zip" "$tmp/zip" # The zip holds one AppImage; take it whatever its name (older zips used lightshare--linux-x86_64.AppImage). found="" count=0 for file in "$tmp/zip"/*.AppImage "$tmp/zip"/*/*.AppImage; do case "$file" in */__MACOSX/*) continue ;; esac [ -f "$file" ] || continue found="$file" count=$((count + 1)) done [ "$count" -gt 0 ] || die "The download holds no AppImage. Try again in a few minutes." [ "$count" -eq 1 ] || die "The download holds more than one AppImage." step "Installing to $APP" mkdir -p "$APP_DIR" chmod 755 "$found" # Move into place: a running copy keeps its old file open, so updating over it is safe. mv -f "$found" "$APP.new" mv -f "$APP.new" "$APP" # Copies saved by an earlier manual install under the zip's old name. for old in "$APP_DIR"/lightshare-*-linux-x86_64.AppImage; do [ -e "$old" ] || continue rm -f "$old" && say "Removed the older copy $old" done exec_line="\"$APP\"" [ "$fuse_ok" -eq 1 ] || exec_line="\"$APP\" --appimage-extract-and-run" mkdir -p "$(dirname "$DESKTOP_FILE")" "$(dirname "$ICON_FILE")" download "$ICON_URL" "$ICON_FILE" 2>/dev/null || { rm -f "$ICON_FILE"; warn "Could not download the menu icon."; } cat >"$DESKTOP_FILE" </dev/null 2>&1 || true say "Added Light Share to your applications menu." step "Done" if is_running; then say "Light Share is running. Quit it and open it again to use the new version." elif [ -n "${DISPLAY:-}${WAYLAND_DISPLAY:-}" ]; then say "Starting Light Share." if [ "$fuse_ok" -eq 1 ]; then nohup "$APP" >/dev/null 2>&1 & else nohup "$APP" --appimage-extract-and-run >/dev/null 2>&1 & fi else say "Open Light Share from your applications menu, or run: $APP" fi } main() { case "${1:-}" in --uninstall) uninstall ;; ""|--install) install ;; *) die "Unknown option $1. Use --uninstall to remove Light Share." ;; esac } main "$@"