#!/bin/sh # Install the latest Linux AppImage for the current user. # Usage: curl -q -fsSL https://myssh.app/install.sh | sh # # What this script changes: # - Creates ~/Applications if needed and downloads MySSH into a temporary folder. # - Installs the file as ~/Applications/MySSH.AppImage with permission to run. # - Replaces an existing MySSH.AppImage there only after the download and checks. # - Removes its own temporary folder on exit (except an uncatchable interruption). # # No sudo or root access: no system packages, services or shell profiles change. # This script does not read or change SSH keys, passwords or MySSH settings. # The downloaded app is NOT executed; you choose when to open it yourself. # See the download and validation comments below for what the checks guarantee. # To inspect before running, download this script to a file and read it first. # Stop on command failures and unset variables rather than continuing blindly. set -eu main() { # Check compatibility before creating folders or making network requests. if [ "$(uname -s)" != Linux ]; then printf '%s\n' 'This installer is for Linux only.' >&2 exit 1 fi case "$(uname -m)" in x86_64|amd64) ;; *) printf '%s\n' 'MySSH currently provides a Linux build for x86_64 only.' >&2; exit 1 ;; esac # Refuse root: this is a per-user installation and never elevates privileges. if [ "$(id -u)" -eq 0 ]; then printf '%s\n' 'Run this installer as your regular user, without sudo.' >&2 exit 1 fi case "${HOME:-}" in /*) ;; *) printf '%s\n' 'HOME must be an absolute path.' >&2; exit 1 ;; esac # Use existing tools only; do not install dependencies or call a package manager. for tool in curl mkdir mktemp od tr chmod mv rm; do if ! command -v "$tool" >/dev/null 2>&1; then printf 'Required command not found: %s\n' "$tool" >&2 exit 1 fi done install_dir="$HOME/Applications" app="$install_dir/MySSH.AppImage" # Refuse a symlink or directory at the destination instead of replacing it. if [ -L "$app" ] || { [ -e "$app" ] && [ ! -f "$app" ]; }; then printf 'Cannot replace this path: %s\n' "$app" >&2 exit 1 fi mkdir -p "$install_dir" # mktemp creates a private staging folder beside the destination. Download # failures leave the existing app in place; the final move is atomic. stage=$(mktemp -d "$install_dir/.myssh-install.XXXXXX") # Delete only the temporary folder created above, including on handled signals. trap 'rm -rf "$stage"' 0 trap 'exit 1' HUP INT TERM package="$stage/MySSH.AppImage" printf '%s\n' 'Downloading the latest MySSH for Linux...' # Download from MySSH's cloud endpoint. HTTPS is required for the initial # request AND redirects; curl verifies TLS certificates by default. # Keep -q FIRST: ignore user curl config files, which could enable insecure # TLS or otherwise override these download settings. # HTTP errors fail the install. The response is saved as a file, never run. curl -q --fail --show-error --location --proto '=https' --proto-redir '=https' \ --connect-timeout 15 --max-time 600 --retry 2 \ --output "$package" 'https://cloud.myssh.app/download?os=linux' # Reject HTML/error pages, other installers and incompatible architectures. # ELF64 little-endian, AppImage type 2, and the x86_64 ELF machine ID. header=$(od -An -tx1 -N20 "$package" | tr -d ' \n') case "$header" in 7f454c46020101??414902??????????????3e00) ;; *) printf '%s\n' 'The download is not an x86_64 AppImage. Nothing was installed.' >&2; exit 1 ;; esac # Allow this app file to run without changing ownership or granting setuid. chmod 755 "$package" # Only now replace the installed file. Do not launch the downloaded program. mv -f "$package" "$app" printf '\nInstalled: %s\n' "$app" printf '%s\n' 'Open this file to start MySSH. On first launch, it offers to add itself to the applications menu.' printf '%s\n' 'If FUSE 2 is missing, see https://myssh.app/download/#install for the command for your distribution.' } # Define the full installation before calling it: an incomplete function body # from an interrupted curl pipe cannot begin changing files. main "$@"