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 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