#!/usr/bin/env bash # SlaktarnVI from nothing to PLAY, in one command, and the same command to update: # # curl -fsSL https://raw.githubusercontent.com/Slaktarn700/SlaktarnVI/main/install.sh | bash # # or ./install.sh in a clone. It checks the PC first (an AMD Radeon with resizable BAR, Steam's # Proton Experimental), offers to install what the system lacks (it asks first; sudo asks for your # password), then: the source in ~/SlaktarnVI (cloned, or brought up to date), the program, the # Windows DLLs, this project's driver and Proton copy, your game's folder and its shaders, and an # entry in your applications menu. Steps already done are skipped or quick. # # Options: # --game your copy of the game (else it asks, or you choose it in the launcher) # --dir where the source goes (default ~/SlaktarnVI) # --yes yes to every question (installs packages, prepares shaders) # --check says what is there and what is missing, changes nothing # --no-fsr --no-proton --no-prepare --no-menu --no-launch set -euo pipefail # (All of it in one function, called on the last line: piped from curl, bash has read the whole # script before any of it runs, and nothing it starts can read the rest of it.) main() { REPO="${VALHALLA_REPO:-https://github.com/Slaktarn700/SlaktarnVI}" say() { printf '\n%s\n' "== $*"; } note() { printf ' %s\n' "$*"; } fail() { printf '\nVALHALLA: %s\n' "$*" >&2; exit 1; } (( EUID != 0 )) || fail "start this as yourself, not as root or with sudo: it asks for sudo itself where needed" [[ "$(uname -sm)" == "Linux x86_64" ]] || fail "this is for Linux on a 64-bit PC only" DIR="" GAME="" FSR=1 PROTON=1 PREPARE=1 MENU=1 LAUNCH=1 CHECK=0 YES=0 while (( $# )); do case "$1" in --dir) DIR="${2:?--dir needs a folder}"; shift ;; --game) GAME="${2:?--game needs a folder}"; shift ;; --yes|-y) YES=1 ;; --check) CHECK=1 ;; --no-fsr) FSR=0 ;; --no-proton) PROTON=0 ;; --no-prepare) PREPARE=0 ;; --no-menu) MENU=0 ;; --no-launch) LAUNCH=0 ;; -h|--help) sed -n '2,17p' "${BASH_SOURCE[0]:-/dev/null}" 2>/dev/null | sed -E 's/^# ?//' || echo "see $REPO"; exit 0 ;; *) fail "unknown option $1 (see --help)" ;; esac shift done here="$(cd "$(dirname "${BASH_SOURCE[0]:-.}")" 2>/dev/null && pwd || true)" if [[ -z "$DIR" ]]; then if [[ -n "$here" && -f "$here/.victory-root" && -f "$here/linux/run-xmem.sh" ]]; then DIR="$here"; else DIR="$HOME/SlaktarnVI"; fi fi # Questions go to the terminal, not to the pipe from curl; without one, every answer is no. tty=/dev/null if [[ -t 0 ]]; then tty=/dev/stdin; elif [[ -r /dev/tty ]] && { : /dev/null; then tty=/dev/tty; fi ask() { # ask "question" -> yes? (( YES )) && { note "$1 yes (--yes)"; return 0; } [[ "$tty" != /dev/null ]] || { note "$1 no (no terminal to ask in)"; return 1; } local answer read -r -p " $1 [y/N] " answer <"$tty" || return 1 [[ "$answer" == [yY]* ]] } printf '%s\n' "SlaktarnVI installer: from nothing to PLAY. Steps already done are skipped." \ "The first time takes 20 to 40 minutes and roughly 1 to 2 GB of downloads (the driver and Proton are built from source)." # 1. What no download can mend: the card, and Steam's Proton. say "Step 1 of 9: this PC" card="" most=0 seen=0 for dev in /sys/class/drm/card*/device; do [[ "$(cat "$dev/vendor" 2>/dev/null || true)" == 0x1002 ]] || continue total="$(cat "$dev/mem_info_vram_total" 2>/dev/null || echo 0)" if (( total > most )); then card="$dev"; most=$total; seen="$(cat "$dev/mem_info_vis_vram_total" 2>/dev/null || echo 0)"; fi done [[ -n "$card" ]] || fail "no AMD Radeon card was found. SlaktarnVI runs on AMD Radeon only (RDNA 3 or 4 recommended)." (( seen >= most )) || fail "resizable BAR is off: the processor reaches $((seen >> 20)) of the card's $((most >> 20)) MB. Turn on 'Above 4G Decoding' and 'Re-Size BAR' (or 'Smart Access Memory') in the BIOS, then run this again." note "AMD Radeon with $((most >> 20)) MB, resizable BAR on" proton="" for steam in "$HOME/.steam/steam" "$HOME/.steam/root" "$HOME/.local/share/Steam" \ "$HOME/.var/app/com.valvesoftware.Steam/.local/share/Steam" "$HOME/.var/app/com.valvesoftware.Steam/data/Steam" \ "$HOME/snap/steam/common/.local/share/Steam"; do [[ -d "$steam/steamapps" ]] || continue while IFS= read -r lib; do [[ -x "$lib/steamapps/common/Proton - Experimental/files/bin/wineserver" ]] && { proton="$lib/steamapps/common/Proton - Experimental"; break 2; } done < <(printf '%s\n' "$steam"; sed -n 's/^[[:space:]]*"path"[[:space:]]*"\(.*\)"$/\1/p' "$steam/steamapps/libraryfolders.vdf" 2>/dev/null) done [[ -n "$proton" || -n "${PROTON_DIR:-}" ]] || fail "Steam's Proton Experimental was not found. Install Steam, then in Steam: Library, search \"Proton Experimental\", Install. Then run this again." note "Proton Experimental: ${proton:-$PROTON_DIR}" # 2. What the system lacks, all of it at once; installed if you say so. say "Step 2 of 9: tools and libraries" distro="$(. /etc/os-release 2>/dev/null; printf '%s %s' "${ID:-}" "${ID_LIKE:-}")" find_missing() { missing=() local tool lib for tool in git curl unzip make flex bison autoconf ninja glslangValidator pkg-config python3 sha256sum; do command -v "$tool" >/dev/null || missing+=("$tool") done command -v gcc >/dev/null || command -v clang >/dev/null || missing+=(gcc) command -v g++ >/dev/null || command -v clang++ >/dev/null || missing+=(g++) if command -v python3 >/dev/null && ! python3 -c 'import venv, ensurepip' 2>/dev/null; then missing+=(python3-venv); fi if command -v pkg-config >/dev/null; then for lib in libdrm_amdgpu zlib libzstd libelf expat libudev wayland-client wayland-scanner x11 xcb xcb-randr xcb-keysyms \ x11-xcb xcb-dri3 xcb-present xcb-shm xcb-sync xcb-xfixes xshmfence xrandr SPIRV-Tools; do pkg-config --exists "$lib" || missing+=("$lib") done fi return 0 } install_cmd="" case " $distro " in *" arch "*|*" cachyos "*|*" manjaro "*|*" endeavouros "*) install_cmd="sudo pacman -S --needed base-devel git curl unzip python ninja glslang flex bison autoconf libdrm zlib zstd libelf expat systemd-libs wayland libx11 libxcb xcb-util-keysyms libxshmfence libxrandr spirv-tools" ;; *" fedora "*|*" rhel "*) install_cmd="sudo dnf install git curl unzip python3 gcc gcc-c++ make ninja-build glslang flex bison autoconf pkgconf libdrm-devel zlib-devel libzstd-devel elfutils-libelf-devel expat-devel systemd-devel wayland-devel libX11-devel libxcb-devel xcb-util-keysyms-devel libxshmfence-devel libXrandr-devel spirv-tools-devel" ;; *" debian "*|*" ubuntu "*) install_cmd="sudo apt install git curl unzip build-essential ninja-build glslang-tools flex bison autoconf pkg-config python3-venv libdrm-dev zlib1g-dev libzstd-dev libelf-dev libexpat1-dev libudev-dev libwayland-dev libx11-dev libx11-xcb-dev libxcb1-dev libxcb-randr0-dev libxcb-keysyms1-dev libxcb-dri3-dev libxcb-present-dev libxcb-shm0-dev libxcb-sync-dev libxcb-xfixes0-dev libxshmfence-dev libxrandr-dev spirv-tools" ;; esac find_missing if (( ${#missing[@]} )); then note "missing: ${missing[*]}" if [[ -z "$install_cmd" ]]; then fail "install those with your distribution's package manager, then run this again" fi note "this installs them: $install_cmd" (( CHECK )) && exit 0 if ask "Install them now (sudo asks for your password)?"; then bash -c "$install_cmd" <"$tty" || fail "the packages were not installed" find_missing (( ${#missing[@]} == 0 )) || fail "still missing: ${missing[*]}" else fail "install them, then run this again: $install_cmd" fi fi note "all there" # rustup: Rust's own installer (a distribution's Rust has no Windows target). export PATH="${CARGO_HOME:-$HOME/.cargo}/bin:$PATH" if ! command -v rustup >/dev/null; then note "rustup (Rust's installer) is missing" (( CHECK )) && exit 0 if ask "Install rustup into your home folder, from https://sh.rustup.rs?"; then curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain none --no-modify-path || fail "rustup was not installed" else fail "install rustup (https://rustup.rs, or your distribution's rustup package), then run this again" fi fi note "rustup: $(rustup --version 2>/dev/null | head -1)" # 3. The source. say "Step 3 of 9: the source" if [[ -d "$DIR/.git" ]]; then if (( CHECK )); then note "$DIR ($(git -C "$DIR" log -1 --format='%h, %cs'))" elif [[ -n "$(git -C "$DIR" status --porcelain --untracked-files=no)" ]]; then note "$DIR has changes of your own: not updated (commit or stash them to update)" else before="$(git -C "$DIR" rev-parse HEAD)" git -C "$DIR" pull --ff-only -q || fail "git pull failed in $DIR" note "$DIR, up to date ($(git -C "$DIR" log -1 --format='%h, %cs'))" # This script changed in the update: the new one goes on from here. if [[ "$before" != "$(git -C "$DIR" rev-parse HEAD)" && "${VALHALLA_INSTALL_AGAIN:-0}" != 1 ]] && ! git -C "$DIR" diff --quiet "$before" HEAD -- install.sh; then args=(--dir "$DIR") [[ -n "$GAME" ]] && args+=(--game "$GAME") (( YES )) && args+=(--yes) (( FSR )) || args+=(--no-fsr) (( PROTON )) || args+=(--no-proton) (( PREPARE )) || args+=(--no-prepare) (( MENU )) || args+=(--no-menu) (( LAUNCH )) || args+=(--no-launch) VALHALLA_INSTALL_AGAIN=1 exec bash "$DIR/install.sh" "${args[@]}" fi fi elif (( CHECK )); then note "not there yet: $DIR" exit 0 elif [[ -e "$DIR" && -n "$(ls -A "$DIR" 2>/dev/null)" ]]; then fail "$DIR is there and is not SlaktarnVI: choose another folder with --dir" else git clone -q "$REPO" "$DIR" || fail "git clone failed" note "cloned into $DIR" fi cd "$DIR" L=linux # (Tests of the steps above alone.) [[ "${VALHALLA_ONLY_SOURCE:-0}" == 1 ]] && { say "the source is ready: $(git log -1 --format='%h %s')"; return 0; } if (( CHECK )); then say "the rest" bash $L/setup-dlls.sh --check $( (( FSR )) || echo --no-fsr ) || true bash $L/setup-driver.sh --check || true (( PROTON )) && { bash $L/setup-proton.sh --check || true; } [[ -f target/x86_64-pc-windows-msvc/release/victory.exe ]] && note "the program: built" || note "the program: not built yet" exit 0 fi # 4. The launcher's Python library, in a folder of its own unless the system has it. say "Step 4 of 9: the launcher" py=python3 if python3 -c 'import PySide6' 2>/dev/null; then note "PySide6: the system's" else [[ -x $L/.venv/bin/python3 ]] || python3 -m venv $L/.venv || fail "python3 could not make linux/.venv" $L/.venv/bin/python3 -c 'import PySide6' 2>/dev/null || $L/.venv/bin/pip install -q --disable-pip-version-check PySide6 || fail "PySide6 could not be installed into linux/.venv" py=$L/.venv/bin/python3 note "PySide6: in linux/.venv" fi say "Step 5 of 9: the program (Rust and the build)" bash $L/setup-build.sh <"$tty" say "Step 6 of 9: Microsoft's shader compiler$( (( FSR )) && echo ' and AMD FSR')" bash $L/setup-dlls.sh $( (( FSR )) || echo --no-fsr ) say "Step 7 of 9: this project's driver" bash $L/setup-driver.sh say "Step 8 of 9: Proton" if (( PROTON )); then bash $L/setup-proton.sh; else note "Steam's, as it is (--no-proton)"; fi # 9. Your game, its shaders, the menu entry. say "Step 9 of 9: your game" saved="$("$py" -I -c 'import sys; sys.path.insert(0, "linux/launcher"); import valhalla as v; print(v.Settings.load().game_dir)' 2>/dev/null || true)" if [[ -z "$GAME" && -z "$saved" && "$tty" != /dev/null ]]; then read -r -p " Where is your copy of the game? (its folder; Enter: choose it in the launcher later) " GAME <"$tty" || GAME="" GAME="${GAME/#\~/$HOME}"; GAME="${GAME%/}"; GAME="${GAME#\'}"; GAME="${GAME%\'}"; GAME="${GAME#\"}"; GAME="${GAME%\"}" fi if [[ -n "$GAME" ]]; then [[ -d "$GAME" ]] || fail "not a folder: $GAME" GAME="$(cd "$GAME" && pwd)" "$py" -I - "$GAME" <<'PY' || fail "no game executable in that folder: $GAME" import sys from pathlib import Path sys.path.insert(0, "linux/launcher") import valhalla as v folder = Path(sys.argv[1]) if v.game_exe(folder) is None: sys.exit(1) s = v.Settings.load() s.game_dir = str(folder) s.save() PY saved="$GAME" note "the game: $GAME (kept for the launcher)" elif [[ -n "$saved" ]]; then note "the game: $saved (chosen before)" else note "the game: choose it in the launcher (SYSTEM, Game folder, Change)" fi cache="${VALHALLA_HOME:-${XDG_DATA_HOME:-$HOME/.local/share}/valhalla-xmem}/victory-data/cache/pipelines" if [[ -n "$saved" ]] && (( PREPARE )) && [[ -z "$(ls -A "$cache" 2>/dev/null)" ]]; then if ask "Prepare the game's shaders and pipelines now (several minutes, about 6 GB of cache)?"; then GAME_DIR="$saved" bash $L/run-xmem.sh shaders && GAME_DIR="$saved" bash $L/run-xmem.sh warm || note "preparing stopped; do it later in the launcher (TOOLS, Shaders and pipelines, Prepare)" else note "later: in the launcher, TOOLS, Shaders and pipelines, Prepare" fi fi if (( MENU )); then apps="${XDG_DATA_HOME:-$HOME/.local/share}/applications" mkdir -p "$apps" printf '%s\n' "[Desktop Entry]" "Type=Application" "Name=SlaktarnVI" "GenericName=Valhalla launcher" \ "Comment=Xbox Series compatibility layer for Linux and AMD Radeon" "Exec=\"$DIR/linux/valhalla.sh\"" \ "Icon=applications-games" "Terminal=false" "Categories=Game;" > "$apps/slaktarnvi.desktop" note "in your applications menu: SlaktarnVI" fi say "Ready" note "Start it: your applications menu, SlaktarnVI (or $DIR/linux/valhalla.sh)" note "Play: choose a preset (S70), then PLAY" note "Update: the same command you used now (or $DIR/install.sh)" note "Problems: TOOLS, Copy a report, in the launcher; and $REPO/issues" if (( LAUNCH )) && [[ -n "${DISPLAY:-}${WAYLAND_DISPLAY:-}" ]]; then exec bash $L/valhalla.sh <"$tty" fi } main "$@"