Skip to content

Instantly share code, notes, and snippets.

@leycec
Last active March 22, 2020 02:02
Show Gist options
  • Save leycec/24931c7c7d2a7da4a97de6558736841a to your computer and use it in GitHub Desktop.
Save leycec/24931c7c7d2a7da4a97de6558736841a to your computer and use it in GitHub Desktop.
Linux-based installer for the "Long War Rebalance" XCOM mod.
#!/usr/bin/env bash
#
# ====================[ install_linux.sh ]====================
#
# --------------------( SYNOPSIS )--------------------
# Linux-based installer for the "Long War Rebalance" XCOM mod.
#
# --------------------( INSTALLATION )--------------------
# Copy this script into the top-level directory to which you unzipped the
# contents of the "Long War Rebalance" zip archive and run that script to
# install "Long War Rebalance": e.g.,
#
# 1. Download both this installer and the "Long War Rebalance" zip archive into
# the current directory.
# 2. Unzip this archive:
# unzip 'LW Rebalance '*.zip
# 3. Copy this installer into the unzipped directory:
# cp install_linux.bash 'LW Rebalance '*/
# 4. Run this script to install "Long War Rebalance":
# bash 'LW Rebalance '*/install_linux.bash
#
# --------------------( USAGE )--------------------
# $ bash install_linux.bash [XCOM_INSTALL_DIRECTORY]
#
# This script optionally accepts the absolute or relative dirname of the
# top-level installation directory for "XCOM: Enemy Unknown." When unpassed,
# this argument defaults to the typical Steam installation directory (i.e.,
# "~/.steam/steam/steamapps/common/Xcom-Enemy-Unknown").
#
# --------------------( EXAMPLES )--------------------
# * Install "Long War Rebalance" to the typical Steam installation directory:
# bash install_linux.bash
# * Install "Long War Rebalance" to a custom installation directory:
# bash install_linux.bash ~/Games/XCom_Enemy_Within
#
# --------------------( AUTHORS )--------------------
# * Original author:
# https://github.com/leycec
#
# --------------------( SEE ALSO )--------------------
# * Nexus forum post inspiring this script:
# https://forums.nexusmods.com/index.php?showtopic=6697482/#entry64622831
# ....................{ PREAMBLE }....................
# Enforce strictness.
set -e
# If the user passed more than one argument, print an error and fail.
if (( $# > 1 )); then
echo 'Expected no arguments or one target dirname.' >&2
exit 1
fi
# Absolute canonical dirname of the directory containing this script. Note the
# "readlink -f" option requires the macOS-incompatible GNU coreutils.
SRC_DIRNAME="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
# Absolute or relative dirname of the top-level XCOM installation directory,
# defaulting to the typical Steam installation directory if unpassed.
TRG_DIRNAME="${1:-${HOME}/.steam/steam/steamapps/common/Xcom-Enemy-Unknown}"
# Print a welcome message.
echo "Installing Long War Rebalance: ${SRC_DIRNAME} -> ${TRG_DIRNAME}"
# If this installation directory does *NOT* exist, print an error and fail.
if [[ ! -d "${TRG_DIRNAME}" ]]; then
echo "Target directory \"${TRG_DIRNAME}\" not found." >&2
exit 1
fi
# ....................{ RENAME }....................
# Coerce all filenames in the "CookedPCConsole" and "Localization"
# subdirectories to lowercase. Note that this does *NOT* apply to the "Config"
# subdirectory, whose filenames are intentionally preserved as is.
find "${SRC_DIRNAME}/CookedPCConsole/" "${SRC_DIRNAME}/Localization/" \
-depth -type f | while read -r SRC_FILENAME; do
# Absolute filename of this file coerced to lowercase.
TRG_FILENAME="$(dirname "${SRC_FILENAME}")/$(basename "${SRC_FILENAME}" |
tr '[:upper:]' '[:lower:]')"
# If the two filenames differ (i.e., the original filename contains at
# least one uppercase character), coerce this filename to lowercase.
if [[ "${SRC_FILENAME}" != "${TRG_FILENAME}" ]]; then
mv -v -T "${SRC_FILENAME}" "${TRG_FILENAME}"
fi
done
# Rename the "Default" prefix of every filename in the "Config" subdirectory to
# "XCom" instead (e.g., "Config/DefaultMaps.ini" to "Config/XComMaps.ini").
for SRC_CONFIG_FILENAME in "${SRC_DIRNAME}"/Config/*; do
# Basename of this file with this prefix replaced.
TRG_CONFIG_BASENAME="$(basename "${SRC_CONFIG_FILENAME}")"
TRG_CONFIG_BASENAME="XCom${TRG_CONFIG_BASENAME#Default}"
# Absolute filename of this file with this prefix replaced.
TRG_CONFIG_FILENAME="$(dirname "${SRC_CONFIG_FILENAME}")/${TRG_CONFIG_BASENAME}"
# Rename this prefix in this filename.
mv -v -T "${SRC_CONFIG_FILENAME}" "${TRG_CONFIG_FILENAME}"
done
# ....................{ INSTALL }....................
# Install all files in the "Config" subdirectory.
cp -v "${SRC_DIRNAME}"/Config/* \
~/.local/share/feral-interactive/XCOM/XEW/WritableFiles/
# Install all files in the "CookedPCConsole" subdirectory.
cp -v "${SRC_DIRNAME}"/CookedPCConsole/* \
"${TRG_DIRNAME}"/xew/xcomgame/cookedpcconsole/
# Install all files in the "Localization/INT" subdirectory.
cp -v "${SRC_DIRNAME}"/Localization/INT/* \
"${TRG_DIRNAME}"/xew/binaries/share/feraloverrides/
cp -v "${SRC_DIRNAME}"/Localization/INT/* \
"${TRG_DIRNAME}"/xew/xcomgame/localization/int/
# ....................{ POSTAMBLE }....................
# Print a shutdown message.
echo 'Installed!'
@Pauloel7
Copy link

Pauloel7 commented Jan 1, 2020

Hello Cecil Curry.
I'm unsuccessfully trying to install UCROSS LW Rebalance v1.23.08 on Mac, and thus writing you for help.
First, do I even need to run the Linux installation, because of Mac?
Second, as I assumed so, I did try and failed.
Here's the terminal output:
"readlink: illegal option -- f
usage: readlink [-n] [file ...]
Installing Long War Rebalance: . -> /Users/PauloEduardoLeme/.steam/steam/steamapps/common/Xcom-Enemy-Unknown
Target directory "/Users/PauloEduardoLeme/.steam/steam/steamapps/common/Xcom-Enemy-Unknown" not found."

@Pauloel7
Copy link

Pauloel7 commented Jan 1, 2020

https://www.nexusmods.com/xcom/mods/686?tab=images
Are these the correct instructions now?
Are you gonna update the script?

@leycec
Copy link
Author

leycec commented Jan 3, 2020

Thanks for the show of interest, @Pauloel7! Sadly, the current Linux-specific instructions are... Linux-specific. I know, right? "Way to ruin 2020," you may now be thinking.

My only hope for the New Year is that someone who is not me – like, you, possibly? – will fork this gist and make a working install_macos.bash script based on this install_linux.bash script. All that's needed is low-level knowledge of Steam directories, macOS internals, and command-line usage. But you're a GitHub user, so... I'll safely assume that you're already awesome. At a minimum, here's what you or anyone else who is not me will need to do to make this happen:

  • Replace all Linux-specific paths in this script with their macOS-specific equivalents. This includes:
    • ${HOME}/.steam/steam/steamapps/common/Xcom-Enemy-Unknown, the default Linux-specific Steam installation directory for XCOM.
    • ~/.local/share/feral-interactive/XCOM/XEW/WritableFiles/, the default Linux-specific configuration directory for XCOM.
  • Replace the readlink command with a macOS alternative. readlink is a GNU command installed by default on Linux but not macOS. Why? Because Apple hates the GPL and hence Richard Stallman and hence GNU. So much geek rage! 😠

I'd happily do that for you, but... I don't currently have a macOS laptop capable of running XCOM – let alone XCOM: Long War Rebalance, which appears to be even more CPU- and GPU-intensive. My macOS hardware is about a decade old at this point. Damn you, planned obsolescence.

If the above sounds like hell in an open-source handbasket, you might instead try manually following the macOS installation instructions found here under the heading "For installing on a MAC, the instructions below might help:". Whichever way you choose to go, I wish you and the macOS community the best of volunteer luck. May the Long War be rebalanced for you always.

@Pauloel7
Copy link

Pauloel7 commented Jan 5, 2020

Love your answer.
Would love to follow through and update the bash file, but am afraid don't know how to.
Considering your guideline, it does sounds feasible, but without assistance, I don't feel I can do it. If you feel like providing that, I can get started and come back with questions. Believe I could get the directory part but have zero clue on the GNU deal.
Since this post, I saw the Ucross "HOW TO INSTALL LW:REBALANCE 1.18.19 ON MACOS 10.11.5 (AUGUST 08 2018)" instructions from that link and with a few adjustments I think I got it right. It feels like jumping on hoops in unknown territory dealing with this game installation and modding.
Just to illustrate, imagine the LW1.0 config files no longer control game behaviour as in the past, only partially, which is not even mapped out in the files. The logs show some error messages - which I don't even know if pre-existed nor how to interpret - BUT the game runs.
After that I even, somehow, got PatcherGUI to work on Mac with Wineskin... kindda scary experience for a nubbie. I'm not a programmer, only - hopefully - a savvy user.
Save geek power and stick it to the man!
HAPPY NEW YEAR, Cecil!

@pescepalla
Copy link

Please consider including an uninstaller.

@daniele-bondi
Copy link

I ran into a problem when running this installer multiple times. The loop on line 90 kept appending "XCom" prefixes each time it ran (so I ended up having e.g. XComXComXComCheckpoint.ini).
I made a modified (untested) version https://gist.github.com/Maeriden/2e9d437cac2e3aecd53885b3b1a22689
It also tries to use $HOME/.local/share/Steam/... if it exists (because it is xdg compliant and I hate having my home dir full of dotfiles).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment