#!/usr/bin/env bash # MK installer — MK-0 (Luau editor) and MK-661 (Roblox client) for Linux. # # curl -fsSL https://mkcheats.com/install.sh | bash # # Detects the machine (architecture, distro, package manager, glibc, GPU, # Wayland/X11, Vulkan, audio, secret service, disk), installs only the missing # system packages with a single sudo and downloads the signed MK package. The # apps live in the user's home, without root: ~/.local/share/mk/releases/. # # Security: the release manifest is signed with Ed25519 (public key below) and # the package is checked against its SHA-256 before anything is extracted. # No nested "curl | sh": this script is the only remote code that runs. # # After installing: mk update | mk doctor | mk repair | mk uninstall [--purge] # # Everything runs from main(): an interrupted download never executes half of # the instructions. set -Eeuo pipefail # The script's own checks run in the C locale. Regex ranges follow the # locale's collation: under tr_TR [A-Za-z] does not match "i", so every # github.com package URL was refused. apt also translates "Candidate:". MK_USER_LANG="${LC_ALL:-}" export LC_ALL=C main() { umask 077 configure # "mk cli": the terminal mode, a mode of the installed MK-661 binary. The # terminal keeps the user's locale (accents, box drawing), not the C one. if [[ "${1:-}" == "cli" ]]; then [[ -x "$BIN_DIR/mk-661" ]] || die MK-1024 "MK-661 is not installed (mk install --apps=mk-661)." shift if [[ -n "${MK_USER_LANG:-}" ]]; then export LC_ALL="$MK_USER_LANG"; else unset LC_ALL; fi exec "$BIN_DIR/mk-661" --cli "$@" fi # ---------------------------------------------------------------- options ASSUME_YES=0 DRY_RUN=0 SKIP_DEPS=0 VERBOSE=0 PURGE=0 COMMAND="install" APPS_REQUEST="${MK_APPS:-}" ERROR_CODE="" for arg in "$@"; do # "mk error MK-1003": the word after "error" is the code. if [[ "$COMMAND" == error && -z "$ERROR_CODE" ]]; then ERROR_CODE="$arg"; continue; fi case "$arg" in --apps=*) APPS_REQUEST="${arg#--apps=}" ;; install|update|doctor|repair|uninstall|version|links|logs|error) COMMAND="$arg" ;; -y|--yes) ASSUME_YES=1 ;; --dry-run) DRY_RUN=1 ;; --no-deps) SKIP_DEPS=1 ;; --purge) PURGE=1 ;; -v|--verbose) VERBOSE=1 ;; -h|--help) usage; return 0 ;; *) die MK-1012 "Unknown option: $arg (see --help)" ;; esac done mkdir -p "$CACHE_DIR" : >>"$LOG_FILE" log "MK installer $MK_INSTALLER_VERSION · command=$COMMAND · $(date -u +%FT%TZ)" case "$COMMAND" in version) echo "mk-installer $MK_INSTALLER_VERSION"; installed_version_line; return 0 ;; doctor) require_base_tools; detect_system; report_system; local status=0; doctor || status=$?; return "$status" ;; logs) require_base_tools; detect_system; report_system; show_logs; return "$?" ;; uninstall) [[ "$DRY_RUN" == 1 || ! -d "$MK_ROOT" ]] || take_lock; uninstall; return 0 ;; links) [[ -x "$BIN_DIR/mk-661" ]] || die MK-1024 "MK-661 is not installed." write_link_handler; claim_roblox_links force; return 0 ;; error) explain_error "$ERROR_CODE"; return "$?" ;; esac require_base_tools detect_system report_system check_blockers choose_apps # One install, update or repair at a time (a second one waits): two of them # shared the staging folder and the download and broke each other. [[ "$DRY_RUN" == 1 ]] || take_lock [[ "$SKIP_DEPS" == 1 ]] || install_dependencies install_release "$COMMAND" } configure() { # ---------------------------------------------------------------- configuration MK_INSTALLER_VERSION="1.0.1" # The one fixed URL of the signed release manifest. Overridable for testing/QA # only; the signature, not the host, is what makes it trusted. MK_MANIFEST_URL="${MK_MANIFEST_URL:-https://mkcheats.com/manifest.txt}" # Ed25519 public key that signs the manifests (SPKI PEM). The private key is # kept outside the repository (see installer/README.md). MK_RELEASE_PUBKEY="${MK_RELEASE_PUBKEY_OVERRIDE:-$(cat <<'PEM' -----BEGIN PUBLIC KEY----- MCowBQYDK2VwAyEAiTfnzMJFcs0I+jZ1aXRyD9mVXzP27I2tilH/5iX3rF4= -----END PUBLIC KEY----- PEM )}" # The package is built on Ubuntu 22.04: its binaries need glibc 2.35 (GLIBC_MIN). MIN_GLIBC="2.35" # mk-661 loads Roblox's Android library, whose relocations it rewrites as RELR: # the dynamic loader understands them from glibc 2.36 on. mk-0 has no such need. MK661_MIN_GLIBC="2.36" NEED_DISK_MB=1500 NEED_RAM_MB=3000 # Directories (XDG). Everything per user; nothing in /opt or /usr. DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}" MK_ROOT="${MK_INSTALL_ROOT:-$DATA_HOME/mk}" BIN_DIR="${MK_BIN_DIR:-$HOME/.local/bin}" APPS_DIR="${MK_APPS_DIR:-$DATA_HOME/applications}" ICONS_DIR="${MK_ICONS_DIR:-$DATA_HOME/icons/hicolor/scalable/apps}" MIME_DIR="${MK_MIME_DIR:-$DATA_HOME/mime}" CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/mk-installer" LOG_FILE="$CACHE_DIR/install.log" # Tests: replaceable system files. OS_RELEASE="${MK_OS_RELEASE_FILE:-/etc/os-release}" SYS_DRM="${MK_SYSFS_DRM:-/sys/class/drm}" SYS_PCI="${MK_SYSFS_PCI:-/sys/bus/pci/devices}" # The Linux container of ChromeOS (Crostini) has this marker. CROS_MARKER="${MK_CROS_MARKER:-/dev/.cros_milestone}" # Seconds to wait for another install/update holding $MK_ROOT/.lock. LOCK_WAIT="${MK_LOCK_WAIT:-300}" LOCK_HELD=0 DEPS_HINT="" # How to type the commands here: a shell without ~/.local/bin in PATH (the # first install, a curl | bash) needs the full path. case ":$PATH:" in *":$BIN_DIR:"*) BIN_SHOWN="" ;; *) BIN_SHOWN="${BIN_DIR/#"$HOME"/"~"}/" ;; esac MK_CMD="${BIN_SHOWN}mk" } # ==================================================================== output if [[ -t 1 ]]; then B=$'\e[1m'; G=$'\e[32m'; Y=$'\e[33m'; R=$'\e[31m'; D=$'\e[2m'; N=$'\e[0m' else B="" G="" Y="" R="" D="" N=""; fi log() { [[ -n "${LOG_FILE:-}" ]] && printf '%s\n' "$*" >>"$LOG_FILE" 2>/dev/null || true [[ "${VERBOSE:-0}" == 1 ]] && printf '%s%s%s\n' "$D" "$*" "$N" >&2 || true; } say() { printf '%s\n' "$*"; log "$*"; } step() { printf '%s==>%s %s\n' "$B" "$N" "$*"; log "==> $*"; } ok() { printf ' %s✓%s %s\n' "$G" "$N" "$*"; log " ok: $*"; } warn() { printf ' %s!%s %s\n' "$Y" "$N" "$*" >&2; log " warning: $*"; } # Every failure carries an MK error code (die MK-1001 "...", warn_code for a # failed check or a missing requirement), explained with its fix on the site. # The codes are registered in shared/errors/installer.json; write them as # literals here: tools/check_error_codes.py matches the two. ERRORS_URL="https://mkcheats.com/en/docs/errors" die() { local code="MK-1099" if [[ "${1:-}" =~ ^MK-[0-9]{4}$ ]]; then code="$1"; shift; fi printf '%sError %s:%s %s\n' "$R" "$code" "$N" "$*" >&2 printf ' How to fix: %s#%s\n' "$ERRORS_URL" "$code" >&2; log "ERROR $code: $*" [[ -n "${LOG_FILE:-}" ]] && printf '%sDetails in %s%s\n' "$D" "$LOG_FILE" "$N" >&2; exit 1; } warn_code() { local code="$1"; shift printf ' %s!%s Warning %s: %s\n' "$Y" "$N" "$code" "$*" >&2 printf ' How to fix: %s#%s\n' "$ERRORS_URL" "$code" >&2; log " warning $code: $*"; } on_error() { # only the main shell reports; subshells just propagate the failure local status="$1" line="$2" command="$3" [[ "$BASH_SUBSHELL" -gt 0 ]] && exit 1 die MK-1099 "unexpected failure at line $line (exit $status, command: $command)" } trap 'on_error "$?" "$LINENO" "$BASH_COMMAND"' ERR usage() { cat <<'EOF' MK-0 and MK-661 installer curl -fsSL https://mkcheats.com/install.sh | bash curl -fsSL https://mkcheats.com/install.sh | bash -s -- --yes Commands (once installed, use "mk "): install install or reinstall (default) update update to the newest version doctor check the machine and the installation without changing anything repair reinstall the current version and its dependencies uninstall remove the apps (keeps your data; --purge deletes everything) links open Roblox links from the browser ("Play", private servers) in MK-661 logs the last two hours of MK's own log lines, to attach to a support ticket error CODE what an error code means and how to fix it (mk error MK-1003) version show the installed version cli MK-0 and MK-661 in the terminal (mk cli; mk cli /time) Options: --apps=LIST which apps: mk-661, mk-0 or both (mk-0,mk-661). Asked if omitted; updates keep the previous choice -y, --yes don't ask (accept installing dependencies) --no-deps don't install system packages --dry-run only show what would be done -v, --verbose more details EOF } # Prompts read from the terminal, never from curl's pipe. confirm() { [[ "$ASSUME_YES" == 1 ]] && return 0 [[ "$DRY_RUN" == 1 ]] && return 0 if [[ ! -r /dev/tty ]]; then warn_code MK-1014 "No terminal to ask on; use --yes to accept." return 1 fi local answer printf '%s [Y/n] ' "$1" >/dev/tty read -r answer /dev/null 2>&1; then log "flock not found: running without the install lock"; return 0; fi exec 9>"$MK_ROOT/.lock" || die MK-8004 "Cannot create $MK_ROOT/.lock." if ! flock -n 9; then say " Another MK install or update is running; waiting for it to finish (up to ${LOCK_WAIT} s)..." flock -w "$LOCK_WAIT" 9 || die MK-1011 "Another MK install or update is still running ($MK_ROOT/.lock). Let it finish (or close it), then try again." fi LOCK_HELD=1 } run() { log "\$ $*" if [[ "$DRY_RUN" == 1 ]]; then printf ' %s(dry run)%s %s\n' "$D" "$N" "$*"; return 0; fi "$@" } version_ge() { [[ "$(printf '%s\n%s\n' "$2" "$1" | sort -V | head -n1)" == "$2" ]]; } # ==================================================================== detection require_base_tools() { # minimal images can lack these; desktop installs always have them local tool missing=() for tool in awk sed grep sort tar find xargs df uname mktemp sha256sum; do command -v "$tool" >/dev/null 2>&1 || missing+=("$tool") done [[ ${#missing[@]} -eq 0 ]] || die MK-1007 "Basic system tools are missing: ${missing[*]}. Install them (usually the packages gawk, findutils and coreutils) and run the installer again." } detect_system() { ARCH="$(uname -m)" KERNEL="$(uname -r)" DISTRO_ID="unknown" DISTRO_LIKE="" DISTRO_NAME="Linux" DISTRO_VERSION="" if [[ -r "$OS_RELEASE" ]]; then # Read as data, never sourced: os-release is not trusted code. DISTRO_ID="$(os_field ID)"; DISTRO_LIKE="$(os_field ID_LIKE)" DISTRO_NAME="$(os_field PRETTY_NAME)"; DISTRO_VERSION="$(os_field VERSION_ID)" [[ -z "$DISTRO_NAME" ]] && DISTRO_NAME="$DISTRO_ID" fi # Immutable systems: Fedora Atomic/Bazzite/Bluefin (rpm-ostree), openSUSE # Aeon/Kalpa/MicroOS (transactional-update, read-only root) and SteamOS. IMMUTABLE_KIND="${MK_FORCE_IMMUTABLE:-}" if [[ -z "$IMMUTABLE_KIND" ]]; then if [[ -e /run/ostree-booted ]]; then IMMUTABLE_KIND=ostree elif [[ "$DISTRO_ID" == "steamos" ]]; then IMMUTABLE_KIND=steamos elif [[ -x /usr/sbin/transactional-update ]] && awk '$2 == "/" { options = $4 } END { exit !(options ~ /(^|,)ro(,|$)/) }' /proc/mounts 2>/dev/null; then IMMUTABLE_KIND=transactional fi fi IMMUTABLE=0; [[ -n "$IMMUTABLE_KIND" ]] && IMMUTABLE=1 PKG="$(detect_package_manager)" GLIBC="$(detect_glibc)" # musl systems (Void musl, Chimera...) report no glibc at all. LIBC="glibc" if [[ "$GLIBC" == 0 ]] && { compgen -G '/lib/ld-musl-*.so.1' >/dev/null || { ldd --version 2>&1 || true; } | grep -qi musl; }; then LIBC="musl" fi SESSION="${XDG_SESSION_TYPE:-}" [[ -z "$SESSION" && -n "${WAYLAND_DISPLAY:-}" ]] && SESSION="wayland" [[ -z "$SESSION" && -n "${DISPLAY:-}" ]] && SESSION="x11" [[ -z "$SESSION" ]] && SESSION="unknown" DESKTOP="${XDG_CURRENT_DESKTOP:-unknown}" detect_gpus VULKAN=0; has_library libvulkan.so.1 && VULKAN=1 EGL=0; has_library libEGL.so.1 && EGL=1 AUDIO="none" if command -v pipewire >/dev/null 2>&1 || [[ -S "${XDG_RUNTIME_DIR:-/run/user/$UID}/pipewire-0" ]]; then AUDIO="pipewire" elif command -v pulseaudio >/dev/null 2>&1 || [[ -S "${XDG_RUNTIME_DIR:-/run/user/$UID}/pulse/native" ]]; then AUDIO="pulseaudio"; fi # Only a Secret Service that answers on the session bus (running or D-Bus # activatable) counts. An installed kwalletd5/gnome-keyring/keepassxc binary # is not enough: kwalletd5 never provides org.freedesktop.secrets and the # others may be disabled. Trusting the binary skipped gnome-keyring and left # sign-in looping on "could not load or save the session". KEYRING=0; has_secret_service && KEYRING=1 CPU_FLAGS="$(grep -m1 '^flags' /proc/cpuinfo 2>/dev/null || true)" CPU_OK=1 for flag in sse4_2 popcnt ssse3; do [[ "$CPU_FLAGS" == *" $flag"* ]] || CPU_OK=0; done RAM_MB=$(( $(awk '/^MemTotal:/ {print $2}' /proc/meminfo 2>/dev/null || echo 0) / 1024 )) mkdir -p "$(dirname "$MK_ROOT")" DISK_MB=$(df -Pm "$(dirname "$MK_ROOT")" 2>/dev/null | awk 'NR==2 {print $4}') DISK_MB="${DISK_MB:-0}" } os_field() { local value value="$(grep -E "^$1=" "$OS_RELEASE" 2>/dev/null | head -n1 | cut -d= -f2-)" || value="" value="${value%\"}"; value="${value#\"}"; value="${value%\'}"; value="${value#\'}" printf '%s' "$value" | tr -cd '[:alnum:] ._()/,+-' | cut -c1-80 } detect_package_manager() { local ids=" $DISTRO_ID $DISTRO_LIKE " if [[ -n "${MK_FORCE_PKG:-}" ]]; then printf '%s' "$MK_FORCE_PKG"; return; fi case "$ids" in *" arch "*|*" manjaro "*|*" endeavouros "*|*" cachyos "*|*" garuda "*|*" artix "*) printf pacman; return ;; *" debian "*|*" ubuntu "*|*" linuxmint "*|*" pop "*|*" elementary "*|*" zorin "*|*" kali "*) printf apt; return ;; *" fedora "*|*" rhel "*|*" centos "*|*" rocky "*|*" almalinux "*|*" nobara "*) printf dnf; return ;; *" opensuse "*|*" suse "*|*" opensuse-tumbleweed "*|*" opensuse-leap "*) printf zypper; return ;; *" void "*) printf xbps; return ;; *" solus "*) printf eopkg; return ;; *" alpine "*) printf apk; return ;; *" nixos "*) printf nix; return ;; esac local manager for manager in pacman apt-get dnf zypper xbps-install; do if command -v "$manager" >/dev/null 2>&1; then [[ "$manager" == apt-get ]] && manager=apt [[ "$manager" == xbps-install ]] && manager=xbps printf '%s' "$manager"; return fi done printf none } detect_glibc() { if [[ -n "${MK_FORCE_GLIBC:-}" ]]; then printf '%s' "$MK_FORCE_GLIBC"; return; fi local version version="$(getconf GNU_LIBC_VERSION 2>/dev/null | awk '{print $2}')" || true [[ -z "$version" ]] && version="$(ldd --version 2>/dev/null | head -n1 | grep -oE '[0-9]+\.[0-9]+$')" || true printf '%s' "${version:-0}" } detect_gpus() { GPU_INTEL=0 GPU_AMD=0 GPU_NVIDIA=0 GPU_VIRTUAL=0 GPU_LIST="" CHROMEOS=0; [[ -e "$CROS_MARKER" || -d /opt/google/cros-containers ]] && CHROMEOS=1 local vendor card for card in "$SYS_DRM"/card[0-9]*; do [[ -r "$card/device/vendor" ]] || continue vendor="$(cat "$card/device/vendor" 2>/dev/null)" case "$vendor" in 0x8086) GPU_INTEL=1 ;; 0x1002) GPU_AMD=1 ;; 0x10de) GPU_NVIDIA=1 ;; # virtio-gpu: the GPU that ChromeOS (or a VM) lends to Linux # through virgl/Venus. Mesa's virgl and virtio drivers run it. 0x1af4) GPU_VIRTUAL=1 ;; esac done # Every PCI display controller (class 0x03....) and the driver bound to # it: /sys/class/drm only lists GPUs a driver took, so an NVIDIA card left # without one was invisible. Lines "vendor device driver" ("none" = no # driver). virtio stays DRM-only: a ChromeOS VM without GPU support must # still read as "no acceleration". GPU_DEVICES="" local dev class device driver for dev in "$SYS_PCI"/*; do [[ -r "$dev/class" ]] || continue class="$(cat "$dev/class" 2>/dev/null)" [[ "$class" == 0x03* ]] || continue vendor="$(cat "$dev/vendor" 2>/dev/null)"; device="$(cat "$dev/device" 2>/dev/null)" driver="none" if [[ -L "$dev/driver" ]]; then driver="$(basename "$(readlink "$dev/driver")")"; fi case "$vendor" in 0x8086) GPU_INTEL=1 ;; 0x1002) GPU_AMD=1 ;; 0x10de) GPU_NVIDIA=1 ;; esac GPU_DEVICES+="$vendor $device $driver"$'\n' done [[ "$GPU_INTEL" == 1 ]] && GPU_LIST+="Intel " [[ "$GPU_AMD" == 1 ]] && GPU_LIST+="AMD " [[ "$GPU_NVIDIA" == 1 ]] && GPU_LIST+="NVIDIA " if [[ "$GPU_VIRTUAL" == 1 ]]; then if [[ "$CHROMEOS" == 1 ]]; then GPU_LIST+="ChromeOS GPU (virtio) "; else GPU_LIST+="virtual (virtio) "; fi fi if [[ -z "$GPU_LIST" ]]; then if [[ "$CHROMEOS" == 1 ]]; then GPU_LIST="none: Linux GPU acceleration is off"; else GPU_LIST="not identified"; fi fi NVIDIA_DRIVER="none" if [[ "$GPU_NVIDIA" == 1 ]]; then if [[ -r /proc/driver/nvidia/version ]] || grep -q '^0x10de [^ ]* nvidia$' <<<"$GPU_DEVICES"; then NVIDIA_DRIVER="proprietary" elif grep -q '^0x10de [^ ]* nouveau$' <<<"$GPU_DEVICES" || { lsmod 2>/dev/null || true; } | grep -q '^nouveau'; then NVIDIA_DRIVER="nouveau"; fi fi } # Informational: a GPU with no driver is unused (alone, Roblox draws on the # CPU), and nouveau is slow or fails. NVIDIA's 590 driver dropped Maxwell, # Pascal and Volta (GTX 750 to GTX 10xx, Titan V); 580 is their last branch. # Their PCI device ids run from 0x1340 (GM108, the first Maxwell) to 0x1dff # (GV100 is 0x1d81-0x1dba); Kepler ends below 0x1340 and Turing starts at 0x1e02. warn_gpu_drivers() { local vendor device driver name while read -r vendor device driver; do [[ -n "$vendor" ]] || continue case "$vendor" in 0x10de) name="NVIDIA" ;; 0x1002) name="AMD" ;; 0x8086) name="Intel" ;; *) continue ;; esac case "$driver" in none) warn_code MK-1040 "$name GPU (${vendor#0x}:${device#0x}) has no driver loaded: it is not used, and without another GPU Roblox draws on the CPU at a few FPS. Install your distro's $name driver." ;; nouveau) warn_code MK-1041 "NVIDIA GPU (${vendor#0x}:${device#0x}) runs on nouveau: Roblox is slow or fails to start on it. Install your distro's NVIDIA driver." ;; esac if [[ "$vendor" == 0x10de && "$driver" != nvidia && "$device" =~ ^0x[0-9a-f]{4}$ ]] && (( device >= 0x1340 && device <= 0x1dff )); then local where="your distro's 580 branch" [[ "$PKG" == pacman ]] && where="nvidia-580xx-dkms from the AUR on Arch; linux-nvidia-580xx on Manjaro" warn_code MK-1042 "This NVIDIA GPU (Maxwell/Pascal/Volta: GTX 750 to 10xx, Titan V) is not supported by the NVIDIA 590+ driver. It needs the 580xx legacy driver ($where)." fi done <<<"$GPU_DEVICES" } has_secret_service() { if [[ -n "${MK_FORCE_KEYRING:-}" ]]; then [[ "$MK_FORCE_KEYRING" == 1 ]]; return; fi local names="" if command -v busctl >/dev/null 2>&1; then names="$(busctl --user list --no-legend 2>/dev/null | awk '{print $1}')" elif command -v dbus-send >/dev/null 2>&1; then names="$(dbus-send --session --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus \ org.freedesktop.DBus.ListNames 2>/dev/null dbus-send --session --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus \ org.freedesktop.DBus.ListActivatableNames 2>/dev/null)" fi grep -qw "org.freedesktop.secrets" <<<"$names" } has_library() { if command -v ldconfig >/dev/null 2>&1 && ldconfig -p 2>/dev/null | grep -q "$1"; then return 0; fi local dir for dir in /usr/lib /usr/lib64 /usr/lib/x86_64-linux-gnu /lib/x86_64-linux-gnu /usr/lib32; do [[ -e "$dir/$1" ]] && return 0 done return 1 } report_system() { step "Your machine" say " System: $DISTRO_NAME ($DISTRO_ID${DISTRO_VERSION:+ $DISTRO_VERSION}) · kernel $KERNEL" say " Arch: $ARCH · glibc $GLIBC · packages: $PKG$([[ $IMMUTABLE == 1 ]] && echo ' (immutable system)')" say " Display: $SESSION · $DESKTOP" say " GPU: $GPU_LIST$([[ $GPU_NVIDIA == 1 ]] && echo "(NVIDIA driver: $NVIDIA_DRIVER)")" say " Graphics: EGL $([[ $EGL == 1 ]] && echo yes || echo no) · Vulkan $([[ $VULKAN == 1 ]] && echo yes || echo no)" say " Audio: $AUDIO · secret service: $([[ $KEYRING == 1 ]] && echo yes || echo no)" say " Memory: ${RAM_MB} MB · free disk: ${DISK_MB} MB" } check_blockers() { step "Checking requirements" [[ "$EUID" -ne 0 ]] || die MK-1006 "Do not run as root. Run as your user; the installer asks for sudo only for system packages." [[ "$ARCH" == "x86_64" ]] || die MK-1001 "MK-661 runs the x86_64 build of Roblox and does not support $ARCH yet." [[ "$CPU_OK" == 1 ]] || die MK-1002 "This CPU lacks SSE4.2/POPCNT/SSSE3, which Roblox requires." [[ "$PKG" != "apk" ]] || die MK-1003 "Alpine (musl) is not supported: Roblox for Android requires glibc." [[ "$LIBC" != musl ]] || die MK-1003 "musl is not supported: Roblox for Android requires glibc $MIN_GLIBC or newer$([[ "$PKG" == xbps ]] && echo ' (on Void, use the glibc edition)')." version_ge "$GLIBC" "$MIN_GLIBC" || die MK-1004 "glibc $GLIBC is too old; the minimum is $MIN_GLIBC." # A fresh install needs the fixed amount; an update is measured against # the package size once the manifest is known (install_release). if [[ -z "$(installed_version)" ]]; then [[ "$DISK_MB" -ge "$NEED_DISK_MB" ]] || die MK-8001 "Not enough free space: ${DISK_MB} MB (needs ${NEED_DISK_MB} MB)." fi ok "x86_64, glibc $GLIBC, compatible CPU, ${DISK_MB} MB free" [[ "$RAM_MB" -ge "$NEED_RAM_MB" ]] || warn_code MK-8002 "Low memory (${RAM_MB} MB). Roblox may stutter or crash with less than ${NEED_RAM_MB} MB." [[ "$SESSION" =~ ^(wayland|x11)$ ]] || warn "No graphical session found (Wayland/X11). Install now and open the apps from your desktop." if [[ -n "$GPU_DEVICES" ]]; then warn_gpu_drivers elif [[ "$GPU_NVIDIA" == 1 && "$NVIDIA_DRIVER" != "proprietary" && "$GPU_INTEL$GPU_AMD" == "00" ]]; then warn_code MK-1041 "NVIDIA GPU without the proprietary driver: Roblox is slow or fails to start on nouveau. Install your distro's NVIDIA driver." fi warn_chromeos_gpu } # ChromeOS 131+ starts Linux without GPU acceleration: Roblox then draws on # the CPU (llvmpipe) at a few FPS, and Chrome's own chrome://gpu still shows # the GPU as working, so nothing looks wrong. warn_chromeos_gpu() { [[ "$CHROMEOS" == 1 && "$GPU_VIRTUAL$GPU_INTEL$GPU_AMD$GPU_NVIDIA" == "0000" ]] || return 0 warn_code MK-1043 "ChromeOS: Linux has no GPU acceleration, so Roblox draws on the CPU and runs at a few FPS. In Chrome open chrome://flags/#crostini-gpu-support, choose Enabled and restart the Chromebook." } # ==================================================================== dependencies # Only what must come from the system: video drivers (EGL/GLES/Vulkan), audio # (GStreamer + pulse/pipewire output), secret service, fonts, certificates and # the installer's own tools, and WebKitGTK for the Roblox pages opened inside # MK-661 (mk661-web). Qt, the verifier's Java and the other libraries ship # inside the MK package. # # Each line lists alternatives in order of preference; the first name the # repository knows is chosen (names change between distro releases, e.g. # libasound2 -> libasound2t64 on Ubuntu 24.04). dependency_groups() { case "$PKG" in pacman) echo "curl"; echo "tar"; echo "zstd"; echo "openssl"; echo "ca-certificates" echo "xdg-utils"; echo "fontconfig"; echo "ttf-dejavu noto-fonts" echo "mesa"; echo "libglvnd"; echo "vulkan-icd-loader" [[ "$GPU_INTEL" == 1 ]] && echo "vulkan-intel" [[ "$GPU_AMD" == 1 ]] && echo "vulkan-radeon" echo "gstreamer"; echo "gst-plugins-base"; echo "gst-plugins-good"; echo "gst-plugins-bad" # pipewiresink, the game's sound output on a PipeWire desktop. [[ "$AUDIO" == pipewire ]] && echo "gst-plugin-pipewire" echo "alsa-lib"; echo "libpulse"; echo "libxkbcommon"; echo "wayland" echo "libxss"; echo "libxtst"; echo "libxkbcommon-x11"; echo "xcb-util-cursor"; echo "xcb-util-wm" echo "xcb-util-image"; echo "xcb-util-keysyms"; echo "xcb-util-renderutil" echo "libsecret"; [[ "$KEYRING" == 1 ]] || echo "gnome-keyring" echo "dbus"; echo "nss"; echo "webkit2gtk-4.1" ;; apt) echo "curl"; echo "tar"; echo "zstd"; echo "openssl"; echo "ca-certificates" echo "xdg-utils"; echo "fontconfig"; echo "fonts-dejavu-core fonts-noto-core" echo "libegl1"; echo "libgles2"; echo "libgl1"; echo "libgbm1" echo "libvulkan1"; echo "mesa-vulkan-drivers" echo "libgstreamer1.0-0"; echo "gstreamer1.0-plugins-base"; echo "gstreamer1.0-plugins-good"; echo "gstreamer1.0-plugins-bad" echo "gstreamer1.0-pulseaudio gstreamer1.0-pipewire" [[ "$AUDIO" == pipewire ]] && echo "gstreamer1.0-pipewire" echo "libasound2t64 libasound2"; echo "libpulse0"; echo "libxkbcommon0" echo "libwayland-client0"; echo "libwayland-egl1"; echo "libwayland-server0" echo "libsecret-1-0"; [[ "$KEYRING" == 1 ]] || echo "gnome-keyring" echo "libxss1"; echo "libxtst6"; echo "libxkbcommon-x11-0"; echo "libxcb-cursor0"; echo "libxcb-icccm4" echo "libxcb-image0"; echo "libxcb-keysyms1"; echo "libxcb-render-util0"; echo "libxcb-shape0"; echo "libxcb-xkb1" echo "dbus-user-session dbus"; echo "libnss3"; echo "libwebkit2gtk-4.1-0" ;; dnf) echo "curl"; echo "tar"; echo "zstd"; echo "openssl"; echo "ca-certificates" echo "xdg-utils"; echo "fontconfig"; echo "dejavu-sans-fonts google-noto-sans-fonts" echo "mesa-libEGL"; echo "libglvnd-gles mesa-libGLES"; echo "mesa-libgbm"; echo "libglvnd-egl" echo "vulkan-loader"; echo "mesa-vulkan-drivers" echo "gstreamer1"; echo "gstreamer1-plugins-base"; echo "gstreamer1-plugins-good"; echo "gstreamer1-plugins-bad-free" # AAC (faad) and H.264: RPM Fusion and the Cisco OpenH264 repository. # openh264 is the real library; Fedora's noopenh264 placeholder # conflicts with it and needs "dnf swap" (warn_noopenh264). rpm -q noopenh264 >/dev/null 2>&1 || echo "openh264" echo "gstreamer1-plugins-bad-freeworld"; echo "gstreamer1-plugin-openh264" [[ "$AUDIO" == pipewire ]] && echo "pipewire-gstreamer" echo "alsa-lib"; echo "pulseaudio-libs"; echo "libxkbcommon" echo "libwayland-client"; echo "libwayland-egl"; echo "libwayland-server" echo "libsecret"; [[ "$KEYRING" == 1 ]] || echo "gnome-keyring" echo "libXScrnSaver"; echo "libXtst"; echo "libxkbcommon-x11"; echo "xcb-util-cursor"; echo "xcb-util-wm" echo "xcb-util-image"; echo "xcb-util-keysyms"; echo "xcb-util-renderutil" echo "dbus"; echo "nss"; echo "webkit2gtk4.1" ;; zypper) echo "curl"; echo "tar"; echo "zstd"; echo "openssl"; echo "ca-certificates" echo "xdg-utils"; echo "fontconfig"; echo "dejavu-fonts google-noto-sans-fonts" echo "Mesa-libEGL1"; echo "Mesa-libGLESv2-2 libglvnd"; echo "libgbm1" echo "libvulkan1"; echo "Mesa-vulkan-device libvulkan_intel libvulkan_radeon" echo "gstreamer"; echo "gstreamer-plugins-base"; echo "gstreamer-plugins-good"; echo "gstreamer-plugins-bad" [[ "$AUDIO" == pipewire ]] && echo "gstreamer-plugin-pipewire" echo "alsa"; echo "libpulse0"; echo "libxkbcommon0" echo "libwayland-client0"; echo "libwayland-egl1" echo "libsecret-1-0"; [[ "$KEYRING" == 1 ]] || echo "gnome-keyring" echo "libXss1"; echo "libXtst6"; echo "libxkbcommon-x11-0"; echo "libxcb-cursor0"; echo "libxcb-icccm4" echo "libxcb-image0"; echo "libxcb-keysyms1"; echo "libxcb-render-util0"; echo "libxcb-shape0"; echo "libxcb-xkb1" echo "libgthread-2_0-0"; echo "libwayland-server0" echo "dbus-1"; echo "mozilla-nss"; echo "libwebkit2gtk-4_1-0" ;; xbps) echo "curl"; echo "tar"; echo "zstd"; echo "openssl"; echo "ca-certificates" echo "xdg-utils"; echo "fontconfig"; echo "dejavu-fonts-ttf noto-fonts-ttf" echo "mesa"; echo "libglvnd"; echo "vulkan-loader" [[ "$GPU_INTEL" == 1 ]] && echo "mesa-vulkan-intel" [[ "$GPU_AMD" == 1 ]] && echo "mesa-vulkan-radeon" echo "gstreamer1"; echo "gst-plugins-base1"; echo "gst-plugins-good1"; echo "gst-plugins-bad1" [[ "$AUDIO" == pipewire ]] && echo "gstreamer1-pipewire" echo "alsa-lib"; echo "libpulseaudio"; echo "libxkbcommon"; echo "wayland" echo "libsecret"; [[ "$KEYRING" == 1 ]] || echo "gnome-keyring" echo "libXScrnSaver"; echo "libXtst"; echo "libxkbcommon-x11"; echo "xcb-util-cursor"; echo "xcb-util-wm" echo "xcb-util-image"; echo "xcb-util-keysyms"; echo "xcb-util-renderutil" echo "dbus"; echo "nss"; echo "libwebkit2gtk41" ;; esac } package_known() { # does the repository know this name? case "$PKG" in pacman) pacman -Si "$1" >/dev/null 2>&1 || pacman -Qi "$1" >/dev/null 2>&1 ;; apt) [[ -n "$(apt-cache policy "$1" 2>/dev/null | awk '/Candidate:/ && $2 != "(none)"')" ]] ;; # Fedora Atomic before 41 has no dnf to ask: take the first name. dnf) command -v dnf >/dev/null 2>&1 || return 0 dnf -q list --available "$1" >/dev/null 2>&1 || rpm -q "$1" >/dev/null 2>&1 ;; zypper) zypper -q --non-interactive search -x "$1" >/dev/null 2>&1 ;; xbps) xbps-query -R "$1" >/dev/null 2>&1 || xbps-query "$1" >/dev/null 2>&1 ;; *) return 1 ;; esac } package_installed() { case "$PKG" in pacman) pacman -Qq "$1" >/dev/null 2>&1 ;; apt) dpkg-query -W -f='${Status}' "$1" 2>/dev/null | grep -q "install ok installed" ;; dnf|zypper) rpm -q --whatprovides "$1" >/dev/null 2>&1 ;; xbps) xbps-query "$1" >/dev/null 2>&1 ;; *) return 1 ;; esac } install_dependencies() { step "System dependencies" case "$PKG" in pacman|apt|dnf|zypper|xbps) ;; nix) warn_code MK-1038 "NixOS: add mesa, vulkan-loader, gstreamer (base+good+bad) and gnome-keyring to your configuration."; return 0 ;; *) warn_code MK-1038 "Unrecognized package manager ($PKG). Skipping; if anything is missing, 'mk doctor' will tell you what."; return 0 ;; esac if [[ "$IMMUTABLE_KIND" == steamos ]]; then immutable_install_hint; return 0; fi [[ "$PKG" == apt && "$DRY_RUN" == 0 && "$IMMUTABLE" == 0 ]] && refresh_apt_index missing_packages [[ "$PKG" == dnf ]] && warn_noopenh264 || true if [[ ${#MISSING[@]} -eq 0 ]]; then ok "Everything the apps need is already installed"; return 0; fi say " Missing: ${MISSING[*]}" # Immutable systems: the base image usually has the drivers; say how to # layer what is missing instead of trying (and failing) to install it. if [[ "$IMMUTABLE" == 1 ]]; then immutable_install_hint; return 0; fi if ! confirm "Install these packages now (asks for your administrator password)?"; then warn_code MK-1031 "Packages not installed. The apps may not start; run '$MK_CMD repair' later." return 0 fi local cmd=() sudo=() status=0 case "$PKG" in pacman) cmd=(pacman -S --needed --noconfirm) ;; # Waits for an unattended upgrade or Software Center holding the lock. apt) cmd=(env DEBIAN_FRONTEND=noninteractive apt-get -o DPkg::Lock::Timeout=180 install -y --no-install-recommends) ;; dnf) cmd=(dnf install -y) ;; zypper) cmd=(zypper --non-interactive install --no-recommends) ;; xbps) cmd=(xbps-install -Sy) ;; esac cmd+=("${MISSING[@]}") if command -v sudo >/dev/null 2>&1; then sudo=(sudo) elif command -v doas >/dev/null 2>&1; then sudo=(doas); fi if [[ ${#sudo[@]} -eq 0 ]]; then manual_install_hint MK-1032 "Neither sudo nor doas was found" "${cmd[@]}"; return 0 fi # A user outside sudoers (or three wrong passwords) gets the command to # run as an administrator instead of a dead install. if [[ "${sudo[0]}" == sudo && "$DRY_RUN" == 0 ]] && ! sudo -v; then manual_install_hint MK-1033 "sudo did not work for this user" "${cmd[@]}"; return 0 fi # A failed package install (conflict, broken mirror, held lock) is not the # end: the start-up test after the download decides whether the apps run. run "${sudo[@]}" "${cmd[@]}" 9>&- || status=$? if [[ "$status" -ne 0 ]]; then warn_code MK-1034 "Installing the system packages failed (exit $status). Continuing; the start-up test decides. To install them by hand:" say " ${sudo[0]} ${cmd[*]}" DEPS_HINT="${sudo[0]} ${cmd[*]}" return 0 fi ok "System packages installed" } # MISSING: for each dependency group not yet installed, the first name the # repository knows. missing_packages() { MISSING=() local group candidate chosen while IFS= read -r group; do [[ -z "$group" ]] && continue chosen="" for candidate in $group; do if package_installed "$candidate"; then chosen="installed"; break; fi done [[ -n "$chosen" ]] && continue for candidate in $group; do if package_known "$candidate"; then chosen="$candidate"; break; fi done if [[ -n "$chosen" ]]; then MISSING+=("$chosen") else warn_code MK-1035 "No package available for: $group (continuing without it)"; fi done < <(dependency_groups) } manual_install_hint() { # code reason command...: what to run by hand local code="$1" reason="$2"; shift 2 warn_code "$code" "$reason, so the system packages were not installed. The apps may not start until they are. As an administrator, run:" say " sudo $*" say " (or: su -c '$*')" DEPS_HINT="sudo $*" } # Immutable systems install packages their own way (and only after a restart). immutable_install_hint() { case "$IMMUTABLE_KIND" in ostree) warn_code MK-1037 "Immutable system (rpm-ostree): MK does not layer system packages. Add them with:" say " rpm-ostree install --apply-live ${MISSING[*]}" ;; transactional) warn_code MK-1037 "Immutable system (transactional-update): MK does not install system packages. Add them with this, then restart:" say " sudo transactional-update pkg install ${MISSING[*]}" ;; steamos) warn_code MK-1037 "SteamOS: every SteamOS update resets system packages, so MK does not install any. If something is missing ('$MK_CMD doctor'), run MK inside a distrobox (distrobox create --name mk --image archlinux:latest; distrobox enter mk) and install it there." ;; *) warn_code MK-1037 "Immutable system: install these with your system's tools: ${MISSING[*]}" ;; esac } # Fedora ships noopenh264, an empty stand-in for the Cisco library: # openh264dec loads and every H.264 frame fails. Returns 0 when it warned. warn_noopenh264() { rpm -q noopenh264 >/dev/null 2>&1 || return 1 if [[ "$IMMUTABLE_KIND" == ostree ]]; then warn_code MK-1054 "noopenh264 (Fedora's empty H.264 placeholder) is installed: video in games does not decode. Replace it: rpm-ostree override remove noopenh264 --install openh264" else warn_code MK-1054 "noopenh264 (Fedora's empty H.264 placeholder) is installed: video in games does not decode. Replace it: sudo dnf swap noopenh264 openh264" fi } # Whether "mk repair" can install system packages here. can_install_packages() { [[ "$IMMUTABLE" == 0 && "$PKG" =~ ^(pacman|apt|dnf|zypper|xbps)$ ]]; } fix_hint() { if can_install_packages; then printf "Run '%s repair'." "$MK_CMD" else printf 'Install it on the system (how: at the end).'; fi } refresh_apt_index() { # A stale index makes apt-cache miss packages; refresh at most once a day. local stamp=/var/lib/apt/periodic/update-success-stamp if [[ ! -e "$stamp" ]] || [[ $(( $(date +%s) - $(stat -c %Y "$stamp" 2>/dev/null || echo 0) )) -gt 86400 ]]; then if confirm "Refresh the package list (apt-get update)?"; then sudo apt-get update -qq || warn_code MK-1036 "apt-get update failed; continuing with the current list." fi fi } # ==================================================================== signed release # manifest.txt: key=value lines followed by one last line # signature= # Accepted keys: format version minimum_version arch glibc_min url sha256 size fetch_manifest() { local signed="$WORK/manifest.signed" MANIFEST="$WORK/manifest.txt" download "$MK_MANIFEST_URL" "$signed" 65536 # Exactly one signature line, and it must be the last line. [[ "$(grep -c '^signature=' "$signed")" == 1 && "$(tail -n1 "$signed")" == signature=* ]] || die MK-9005 "The release manifest is not signed. Nothing was installed (wrong file or server)." grep -v '^signature=' "$signed" >"$MANIFEST" tail -n1 "$signed" | cut -d= -f2- | tr -d '\r\n' | base64 -d >"$WORK/manifest.sig" 2>/dev/null || die MK-9005 "The release manifest signature is malformed." printf '%s\n' "$MK_RELEASE_PUBKEY" >"$WORK/release.pub" command -v openssl >/dev/null 2>&1 || die MK-1008 "openssl not found (required to verify the signature)." openssl pkeyutl -verify -pubin -inkey "$WORK/release.pub" -rawin \ -in "$MANIFEST" -sigfile "$WORK/manifest.sig" >/dev/null 2>&1 || die MK-9006 "The release signature does not match. Nothing was installed (tampered download or wrong server)." local key value M_FORMAT="" M_VERSION="" M_MINIMUM="" M_ARCH="" M_GLIBC="" M_URL="" M_SHA="" M_SIZE="" while IFS='=' read -r key value; do case "$key" in format) M_FORMAT="$value" ;; version) M_VERSION="$value" ;; minimum_version) M_MINIMUM="$value" ;; arch) M_ARCH="$value" ;; glibc_min) M_GLIBC="$value" ;; url) M_URL="$value" ;; sha256) M_SHA="$value" ;; size) M_SIZE="$value" ;; ''|'#'*) ;; *) die MK-1015 "Manifest has an unknown field: $key" ;; esac done <"$MANIFEST" [[ "$M_FORMAT" == 1 ]] || die MK-1015 "Unsupported manifest format ($M_FORMAT). Update the installer." [[ "$M_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ && "$M_MINIMUM" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || die MK-9007 "Invalid version in the manifest." [[ "$M_SHA" =~ ^[0-9a-f]{64}$ && "$M_SIZE" =~ ^[0-9]{1,11}$ ]] || die MK-9007 "Invalid hash/size in the manifest." # Any plain https URL (normally a GitHub release asset): the signed # size and SHA-256 are what make the package trusted, not the host. [[ "$M_URL" =~ ^https://[A-Za-z0-9./?=\&_%:-]+$ || ( -n "${MK_ALLOW_HTTP_FOR_TESTS:-}" && "$M_URL" =~ ^http://127\.0\.0\.1:[0-9]+/ ) ]] || die MK-9007 "Invalid package URL in the manifest." [[ "$M_ARCH" == "$ARCH" ]] || die MK-9007 "This release is for $M_ARCH; your machine is $ARCH." version_ge "$GLIBC" "$M_GLIBC" || die MK-1004 "This release requires glibc $M_GLIBC; yours is $GLIBC. Update your system." } # What curl's exit status means for the user; curl's own message (with the # HTTP status for 22) is printed just above. download_failed() { # url curl-status local url="$1" status="$2" case "$status" in 5|6) die MK-9001 "Could not download $url: the server name does not resolve (curl exit $status). Check your internet connection and DNS." ;; 7|16|18|28|52|55|56|92) die MK-9002 "Could not download $url: the connection failed or dropped (curl exit $status). Check your internet connection, VPN or firewall, then try again." ;; 22) die MK-9003 "Could not download $url: the server answered with an error (curl exit 22). Try again in a few minutes." ;; 23) die MK-8003 "Could not save the download in $CACHE_DIR (curl exit 23): the disk is full or the folder is not writable." ;; 35|51|53|54|58|59|60|77|80|83|90|91) die MK-9004 "Could not download $url: the secure connection failed (curl exit $status). Check the ca-certificates package, the system clock and any proxy." ;; 127) die MK-1010 "curl not found (required to download MK). Install the curl package and try again." ;; *) die MK-9099 "Could not download $url (curl exit $status). Check your internet connection." ;; esac } download() { # url destination max-size [resume] local url="$1" out="$2" max="$3" status=0 local args=(--fail --location --proto '=https' --tlsv1.2 ${MK_ALLOW_HTTP_FOR_TESTS:+--proto =http,https} --retry 3 --retry-delay 2 --connect-timeout 15 --max-filesize "$max") # curl 7.71+ also retries connection resets and other transfer errors, # not only timeouts and 5xx; older curl rejects the option. if curl_version_ge 7.71.0; then args+=(--retry-all-errors); fi if [[ "$max" -gt 1000000 && -t 2 ]]; then args+=(--progress-bar); else args+=(--silent --show-error); fi log "downloading $url" # "resume": continue a partial file left by an interrupted run. A server # that refuses the range (curl 33, or an HTTP error such as 416) gets a # fresh download. if [[ "${4:-}" == resume && -s "$out" ]]; then log "resuming at $(stat -c %s "$out") bytes" curl "${args[@]}" --continue-at - --output "$out" "$url" && return 0 || status=$? [[ "$status" == 33 || "$status" == 22 ]] || download_failed "$url" "$status" log "resume refused (curl exit $status); downloading from the start" rm -f "$out" status=0 fi curl "${args[@]}" --output "$out" "$url" || status=$? [[ "$status" == 0 ]] || download_failed "$url" "$status" } curl_version_ge() { local version version="$(curl --version 2>/dev/null | awk 'NR == 1 { print $2 }')" || version="" [[ -n "$version" ]] && version_ge "$version" "$1" } installed_version() { [[ -r "$MK_ROOT/current/VERSION" ]] && tr -cd '0-9.' <"$MK_ROOT/current/VERSION" || true } installed_version_line() { local v; v="$(installed_version)" if [[ -n "$v" ]]; then echo "MK installed: $v ($MK_ROOT/current)"; else echo "MK is not installed"; fi } # ==================================================================== installation # ==================================================================== which apps # Each app works on its own: only the chosen ones are kept on disk and get # commands, menu entries and the start-up test. (mk-0 runs scripts through a # running mk-661, but opens and works without it.) normalize_apps() { # "both", "mk0,mk-661", ... -> "mk-0 mk-661" (stable order) local raw="${1,,}" out=() word raw="${raw//,/ }" for word in $raw; do case "$word" in both|all) out=(mk-0 mk-661) ;; mk-0|mk0) out+=(mk-0) ;; mk-661|mk661) out+=(mk-661) ;; *) return 1 ;; esac done local apps="" [[ " ${out[*]} " == *" mk-0 "* ]] && apps="mk-0" [[ " ${out[*]} " == *" mk-661 "* ]] && apps="${apps:+$apps }mk-661" [[ -n "$apps" ]] || return 1 printf '%s\n' "$apps" } choose_apps() { local saved="" [[ -f "$MK_ROOT/apps" ]] && saved="$(normalize_apps "$(cat "$MK_ROOT/apps")" 2>/dev/null || true)" if [[ -n "$APPS_REQUEST" ]]; then APPS="$(normalize_apps "$APPS_REQUEST")" || die MK-1013 "Unknown --apps value: $APPS_REQUEST (use mk-0, mk-661 or both)." elif [[ -n "$saved" && "$COMMAND" != install ]]; then APPS="$saved" elif [[ "$ASSUME_YES" == 0 && -r /dev/tty ]] && { : /dev/null; then local default=1 [[ "$saved" == mk-661 ]] && default=2 [[ "$saved" == mk-0 ]] && default=3 step "Which apps?" say " 1) mk-661 + mk-0 both" say " 2) mk-661 Roblox client · free" say " 3) mk-0 executor (runs scripts in a running mk-661)" local answer="" printf ' Choice [%s]: ' "$default" read -r answer "$MK_ROOT/apps" install_integration "$MK_ROOT/current" 9>&- # helpers it starts must not inherit the lock return 0 fi if [[ -n "$current" && "$mode" == install ]] && ! version_ge "$M_VERSION" "$current"; then die MK-1016 "The installed version ($current) is newer than the published one ($M_VERSION). Use 'mk repair' to reinstall." fi [[ "$DRY_RUN" == 1 ]] && { ok "Dry run: would install $M_VERSION to $MK_ROOT/releases/$M_VERSION"; return 0; } # An update needs room for the package, its extraction and the release # kept for rollback: about 4x the package, not the fixed fresh-install figure. if [[ -n "$current" ]]; then local need_mb=$(( M_SIZE * 4 / 1048576 + 1 )) free_mb free_mb="$(df -Pm "$MK_ROOT" 2>/dev/null | awk 'NR==2 {print $4}')" [[ "${free_mb:-0}" =~ ^[0-9]+$ && "${free_mb:-0}" -ge "$need_mb" ]] || die MK-8001 "Not enough free space for the update: ${free_mb:-0} MB free (needs about $need_mb MB)." fi step "Downloading MK $M_VERSION" local archive="$CACHE_DIR/mk-$M_VERSION-$ARCH.tar.zst" fetch_package "$archive" ok "Package verified (signed SHA-256)" step "Installing" mkdir -p "$MK_ROOT/releases" # Each run extracts into its own folder (two runs used to share one). STAGING="$(mktemp -d "$MK_ROOT/releases/.staging-$M_VERSION.XXXXXX")" || die MK-8004 "Cannot create a folder in $MK_ROOT/releases." local staging="$STAGING" # Reject absolute paths, "..", links and special files before extracting. # The listing goes to a file: "tar | grep -q" under pipefail gives false negatives. decompress "$archive" | tar -tvf - >"$WORK/listing.long" decompress "$archive" | tar -tf - >"$WORK/listing" if awk '{print substr($1,1,1)}' "$WORK/listing.long" | grep -v '^[-d]' >/dev/null; then rm -rf "$staging"; die MK-1017 "The package contains links or special files; refused." fi if grep -E '(^/|(^|/)\.\.(/|$))' "$WORK/listing" >/dev/null; then rm -rf "$staging"; die MK-1017 "The package contains unsafe paths; refused." fi if ! decompress "$archive" | tar -xf - -C "$staging" --no-same-owner --strip-components=1; then rm -rf "$staging"; die MK-1018 "Could not extract the package (is the disk full?). The previous version was kept." fi [[ "$(tr -cd '0-9.' <"$staging/VERSION" 2>/dev/null)" == "$M_VERSION" ]] || { rm -rf "$staging"; die MK-1019 "The package does not match version $M_VERSION."; } local required for required in mk-0/bin/mk-0 mk-661/build/bin/mk-661 mk-manager.sh; do [[ -f "$staging/$required" ]] || { rm -rf "$staging"; die MK-1019 "Incomplete package (missing $required)."; } done # Keep only the chosen apps; the shared runtime (qt/, lib/) stays. for app in mk-0 mk-661; do [[ " $APPS " == *" $app "* ]] || rm -rf "${staging:?}/$app" done if ! smoke_test "$staging"; then rm -rf "$staging" [[ -z "$DEPS_HINT" ]] || warn_code MK-1039 "System packages are still missing. Install them first: $DEPS_HINT" die MK-1022 "The apps did not start on this machine; the previous version was kept. See $LOG_FILE" fi local target="$MK_ROOT/releases/$M_VERSION" old="" # Repair of an installed version: move the old tree aside instead of # deleting it first, so 'current' is never a half-deleted tree and a game # still running from it (1.4.1: games outlive the launcher) keeps its files. if [[ -e "$target" ]]; then old="$(mktemp -d "$MK_ROOT/releases/.old-$M_VERSION.XXXXXX")" && mv -T "$target" "$old" || die MK-8004 "Could not move the previous $target aside." fi mv -T "$staging" "$target" || die MK-8004 "Could not move the new version into $target." STAGING="" # Atomic switch: 'current' points to the new version in one step. ln -sfn "releases/$M_VERSION" "$MK_ROOT/current.new" mv -Tf "$MK_ROOT/current.new" "$MK_ROOT/current" printf '%s\n' "$APPS" >"$MK_ROOT/apps" ok "MK $M_VERSION installed in $target" install_integration "$MK_ROOT/current" 9>&- prune_releases clean_cache finish_message "$current" } # The package, checked against the signed size and SHA-256. Under the install # lock an interrupted download is resumed from .part by the next run; # without the lock each run downloads to its own .part.. fetch_package() { local archive="$1" part have=0 size=0 attempt if [[ -f "$archive" && "$(stat -c %s "$archive")" == "$M_SIZE" && "$(sha256sum "$archive" | cut -d' ' -f1)" == "$M_SHA" ]]; then return 0 fi rm -f "$archive" if [[ "$LOCK_HELD" == 1 ]]; then part="$archive.part"; else part="$archive.part.$$"; fi for attempt in 1 2; do have=0 if [[ -f "$part" ]]; then have="$(stat -c %s "$part")"; fi if [[ "$have" -gt "$M_SIZE" ]]; then rm -f "$part"; have=0; fi if [[ "$have" -lt "$M_SIZE" ]]; then download "$M_URL" "$part" "$((M_SIZE + 1))" resume; fi size="$(stat -c %s "$part" 2>/dev/null || echo 0)" if [[ "$size" == "$M_SIZE" && "$(sha256sum "$part" | cut -d' ' -f1)" == "$M_SHA" ]]; then mv -f "$part" "$archive" || die MK-8003 "Could not save the package in $CACHE_DIR." return 0 fi rm -f "$part" # A resumed piece of another file starts over once; a fresh download # that does not match is final. [[ "$have" -gt 0 ]] || break log "resumed package did not verify; downloading it again" done [[ "$size" == "$M_SIZE" ]] || die MK-9008 "Package size does not match ($size bytes downloaded, $M_SIZE expected). Nothing was installed." die MK-9009 "Package SHA-256 does not match. Nothing was installed." } # The cache keeps only the package just installed (repair reuses it): older # packages, their partial downloads and work folders of killed runs go. clean_cache() { local file for file in "$CACHE_DIR"/mk-*-"$ARCH".tar.zst "$CACHE_DIR"/mk-*-"$ARCH".tar.zst.part*; do [[ -e "$file" && "$file" != "$CACHE_DIR/mk-$M_VERSION-$ARCH.tar.zst" ]] || continue # Without the lock a parallel run may still be writing its .part.. [[ "$file" != *.part* || "$LOCK_HELD" == 1 ]] || continue rm -f "$file" done find "$CACHE_DIR" -mindepth 1 -maxdepth 1 -type d -name 'work.*' -mmin +60 ! -path "${WORK:-/nonexistent}" \ -exec rm -rf {} + 2>/dev/null || true } decompress() { case "$1" in *.zst) command -v zstd >/dev/null 2>&1 || die MK-1009 "zstd not found (run without --no-deps)."; zstd -dc --quiet "$1" ;; *.gz) gzip -dc "$1" ;; esac } smoke_test() { # binaries resolve their libraries and answer --version, headless local dir="$1" app name for name in ${APPS:-mk-0 mk-661}; do app="$(app_binary "$name")" if ldd "$dir/$app" 2>/dev/null | grep "not found" >/dev/null; then log "$(ldd "$dir/$app" | grep 'not found')" warn_code MK-1020 "$app: missing libraries: $(ldd "$dir/$app" | awk '/not found/ {print $1}' | tr '\n' ' ')" return 1 fi local status=0 QT_QPA_PLATFORM=offscreen timeout 20 "$dir/$app" --version >>"$LOG_FILE" 2>&1 9>&- || status=$? if [[ "$status" != 0 ]]; then warn_code MK-1021 "$app did not answer --version (exit $status$([[ "$status" == 124 ]] && echo ': timed out after 20 s'))" return 1 fi done ok "${APPS// / and } start$([[ "$APPS" == *" "* ]] || echo "s") on this machine" # Loaded later, so --version does not see them: the game runtime and Qt's # display plugins (xcb needs libxcb-cursor & co.). Warnings, not a # failure: the launcher runs, and 'mk doctor' says what to install. local file missing files=("$dir/qt/lib/libQt6XcbQpa.so.6" "$dir/qt/plugins/platforms"/*.so) [[ " ${APPS:-mk-0 mk-661} " == *" mk-661 "* ]] && files+=("$dir/mk-661/build/runtime"/*.so) for file in "${files[@]}"; do [[ -f "$file" ]] || continue missing="$(ldd "$file" 2>/dev/null | awk '/not found/ {print $1}' | sort -u | tr '\n' ' ')" [[ -n "$missing" ]] || continue if [[ "$file" == */runtime/* ]]; then warn_code MK-1048 "${file#"$dir/"} cannot load, missing: ${missing}($(fix_hint))" else warn_code MK-1047 "${file#"$dir/"} cannot load, missing: ${missing}($(fix_hint))"; fi done return 0 } install_integration() { # terminal commands, menu entries and icons local current="$1" mkdir -p "$BIN_DIR" "$APPS_DIR" "$ICONS_DIR" local apps="${APPS:-}" [[ -n "$apps" ]] || apps="$(cat "$MK_ROOT/apps" 2>/dev/null || echo "mk-0 mk-661")" local name for name in mk-0 mk-661; do if [[ " $apps " == *" $name "* && -f "$current/$(app_binary "$name")" ]]; then write_launcher "$BIN_DIR/$name" "$MK_ROOT/current/$(app_binary "$name")" else rm -f "$BIN_DIR/$name" "$APPS_DIR/$name.desktop" "$ICONS_DIR/$name.svg" [[ "$name" == mk-661 ]] && rm -f "$APPS_DIR/$LINK_HANDLER" fi done printf '#!/usr/bin/env bash\nexec bash "%s" "$@"\n' "$MK_ROOT/current/mk-manager.sh" >"$BIN_DIR/mk.new" chmod 755 "$BIN_DIR/mk.new"; mv -f "$BIN_DIR/mk.new" "$BIN_DIR/mk" for name in $apps; do [[ -f "$current/$(app_binary "$name")" ]] || continue if [[ -f "$current/share/icons/$name.svg" ]]; then cp -f "$current/share/icons/$name.svg" "$ICONS_DIR/$name.svg" # Icons are world-readable (0644): cp inherits the install umask, # which may be 0077, and a 0600 icon is invisible to some loaders. chmod 0644 "$ICONS_DIR/$name.svg" fi case "$name" in mk-0) write_desktop mk-0 "mk-0" "Explore. Execute. Experience MK." "Development;TextEditor;" ;; mk-661) write_desktop mk-661 "mk-661" "Free. Built for Linux." "Game;"; write_link_handler ;; esac done [[ " $apps " == *" mk-0 "* ]] && write_luau_mime command -v update-desktop-database >/dev/null 2>&1 && update-desktop-database -q "$APPS_DIR" 2>/dev/null || true [[ " $apps " == *" mk-661 "* && -f "$APPS_DIR/$LINK_HANDLER" ]] && claim_roblox_links command -v gtk-update-icon-cache >/dev/null 2>&1 && gtk-update-icon-cache -q "$DATA_HOME/icons/hicolor" 2>/dev/null || true refresh_icon_caches ok "Shortcuts created: app menu entries and the ${apps// /, } and mk commands" } # KDE/Plasma keeps a running icon cache that gtk-update-icon-cache does not # touch: a freshly installed app then shows up without its icon until the next # login. Rebuild the service cache (kbuildsycoca) and drop the stale pixmap # cache so a running Plasma reloads the icon now. No-ops off KDE. refresh_icon_caches() { local tool for tool in kbuildsycoca6 kbuildsycoca5; do command -v "$tool" >/dev/null 2>&1 && { "$tool" >/dev/null 2>&1 || true; break; } done rm -f "${XDG_CACHE_HOME:-$HOME/.cache}/icon-cache.kcache" 2>/dev/null || true command -v dbus-send >/dev/null 2>&1 && dbus-send --session --type=signal /KIconLoader org.kde.KIconLoader.iconChanged int32:0 2>/dev/null || true } write_launcher() { printf '#!/usr/bin/env bash\n# Generated by the MK installer.\nexec "%s" "$@"\n' "$2" >"$1.new" chmod 755 "$1.new"; mv -f "$1.new" "$1" } # A .luau saved from MK-0 had no file type anywhere: file managers guessed # from the content and some showed it as music and opened a media player # (report 21/11). The extension rule wins over that guess; the type is text, # so it opens in the user's text editor, as before, never in MK-0 by default. write_luau_mime() { umask 022 mkdir -p "$MIME_DIR/packages" || return 0 cat >"$MIME_DIR/packages/mk-luau.xml.new" <<'MIME' Luau script Script Luau Script Luau MIME mv -f "$MIME_DIR/packages/mk-luau.xml.new" "$MIME_DIR/packages/mk-luau.xml" command -v update-mime-database >/dev/null 2>&1 && update-mime-database "$MIME_DIR" >/dev/null 2>&1 || true } write_desktop() { umask 022 cat >"$APPS_DIR/$1.desktop.new" <