113 lines
3.4 KiB
Bash
Executable File
113 lines
3.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# ABOUT ME
|
|
# Installs the Auto Radiator mod into Cosmoteer's user Mods folder.
|
|
#
|
|
# Why it exists: Cosmoteer loads mods from the user profile directory, which on
|
|
# a Proton install lives deep inside the Steam compatdata prefix of whichever
|
|
# library the game was installed to. That library can sit on any disk, so this
|
|
# script reads Steam's own libraryfolders.vdf to find it, validates the mod
|
|
# against the installed game data, and copies only the files the game needs.
|
|
#
|
|
# Usage: ./install.sh install (validates first)
|
|
# ./install.sh --uninstall remove the installed copy
|
|
#
|
|
# Sourcing this file defines the discovery functions without installing, and
|
|
# leaves the sourcing shell's options untouched.
|
|
|
|
MOD_ID="auto_radiator"
|
|
COSMOTEER_APPID=799600
|
|
SOURCE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
steam_roots() {
|
|
# The Steam client directories, one per install flavour: the modern default,
|
|
# the two legacy symlinks, and Flatpak's sandboxed home.
|
|
printf '%s\n' \
|
|
"$HOME/.local/share/Steam" \
|
|
"$HOME/.steam/steam" \
|
|
"$HOME/.steam/root" \
|
|
"$HOME/.var/app/com.valvesoftware.Steam/data/Steam"
|
|
}
|
|
|
|
steam_libraries() {
|
|
# Every library folder Steam knows about. libraryfolders.vdf lists one
|
|
# "path" per library; the app data sits in <path>/steamapps. Steam's own
|
|
# root is listed there too, but emit it regardless so a missing or
|
|
# unreadable manifest still leaves the default library searchable.
|
|
local root vdf
|
|
steam_roots
|
|
while read -r root; do
|
|
vdf="$root/steamapps/libraryfolders.vdf"
|
|
[ -f "$vdf" ] || continue
|
|
sed -n 's/^[[:space:]]*"path"[[:space:]]*"\(.*\)"[[:space:]]*$/\1/p' "$vdf"
|
|
done < <(steam_roots)
|
|
}
|
|
|
|
find_mods_dir() {
|
|
local lib path
|
|
local -a libraries
|
|
readarray -t libraries < <(steam_libraries)
|
|
|
|
# Proton keeps the profile inside the game's compat prefix. The profile
|
|
# folder is named after the Steam ID, so glob for it.
|
|
for lib in "${libraries[@]}"; do
|
|
for path in "$lib/steamapps/compatdata/$COSMOTEER_APPID/pfx/drive_c/users/steamuser/Saved Games/Cosmoteer"/*/Mods; do
|
|
[ -d "$path" ] && printf '%s\n' "$path" && return 0
|
|
done
|
|
done
|
|
|
|
# A native or Windows install keeps the profile in the user's home.
|
|
for path in "$HOME/Saved Games/Cosmoteer"/*/Mods "$HOME/Documents/My Games/Cosmoteer"/*/Mods; do
|
|
[ -d "$path" ] && printf '%s\n' "$path" && return 0
|
|
done
|
|
|
|
return 1
|
|
}
|
|
|
|
resolve_mods_dir() {
|
|
# An explicit COSMOTEER_MODS_DIR wins, so an unusual install can be pointed
|
|
# at by hand when discovery comes up empty.
|
|
if [ -n "${COSMOTEER_MODS_DIR:-}" ]; then
|
|
printf '%s\n' "$COSMOTEER_MODS_DIR"
|
|
return 0
|
|
fi
|
|
find_mods_dir
|
|
}
|
|
|
|
main() {
|
|
set -euo pipefail
|
|
local mods_dir target
|
|
mods_dir="$(resolve_mods_dir || true)"
|
|
|
|
if [ -z "$mods_dir" ]; then
|
|
echo "Could not find the Cosmoteer Mods folder." >&2
|
|
echo "Searched these Steam libraries:" >&2
|
|
steam_libraries | sort -u | sed 's/^/ /' >&2
|
|
echo "Set COSMOTEER_MODS_DIR to it and run again." >&2
|
|
return 1
|
|
fi
|
|
|
|
target="$mods_dir/$MOD_ID"
|
|
|
|
if [ "${1:-}" = "--uninstall" ]; then
|
|
rm -rf "$target"
|
|
echo "Removed $target"
|
|
return 0
|
|
fi
|
|
|
|
echo "Validating against installed game data..."
|
|
python3 "$SOURCE_DIR/tests/test_mod.py"
|
|
|
|
echo
|
|
echo "Installing to $target"
|
|
rm -rf "$target"
|
|
mkdir -p "$target"
|
|
cp "$SOURCE_DIR/mod.rules" "$target/"
|
|
cp -r "$SOURCE_DIR/components" "$target/"
|
|
|
|
echo "Done. Enable \"Auto Radiator\" in the game's Mods menu."
|
|
}
|
|
|
|
if [ "${BASH_SOURCE[0]}" = "$0" ]; then
|
|
main "$@"
|
|
fi
|