Launch scripts for Linux, to update to latest experimental and handle save game backup/restore

Here are a couple of scripts I’ve written to make things a little easier in Linux, since there is no GUI launcher like for Windows.

The first one installs the latest experimental from github, if there is a new one available. The second one handles backing up and restoring save games before launch.

To use, place them in your PATH somewhere and edit the configuration sections. I hope someone finds these useful.

‘cdda-update’ script:

#!/bin/bash

# OVERVIEW:
# ---------
#
# This script fetches the most recent experimental version from github and
#   installs it.  Save games from the previous version are copied over.
#   Archives of the six most recent versions are kept, in case there are killer
#   bugs and you have to roll back manually.


# REQUIREMENTS:
# -------------
#
# The textmode Lynx web browser must be installed in order for this
#   script to work.


# INSTALLATION:
# -------------
#
# Place this script somewhere in your path (I like to use ~/bin/, but suit
#   yourself).  Change CDDA_WORKING_DIR below to something that suits your
#   particular system.


# CONFIGURATION:
# --------------
#
# Set this to your CDDA working directory.  This directory will contain
#   archives of the last six experimental versions you've had installed (so
#   that you can manually roll back if there are killer bugs).  The previously
#   installed version will be in a directory called "old", and the most
#   recently installed version will be in a directory called "new".
# If you change this, you will also need to change it in the "cdda" launch
#   script.
CDDA_WORKING_DIR=~/bin/cdda-dir


###############################################################################

# Use Lynx to dump the experimental version download URLs that match the
#   architecture we want.  Sort them, then prune off all but the last (newest)
#   entry.
# Then extract the filename we'll be working with from the URL.
# Then extract the version we'll be working with from the filename.
URL=`lynx --dump https://cataclysmdda.org/experimental/ | grep "https://github.com/CleverRaven/Cataclysm-DDA/releases/download/cdda-experimental-" | grep cdda-linux-tiles-x64 | cut -d. -f2- | sort -u | tail -n1`
FILE=`basename $URL`
VERSION=`echo $FILE | cut -d- -f5- | cut -d. -f1`

# Create the working directory if it doesn't exist, and enter it.
if ! [ -e $CDDA_WORKING_DIR ]; then
	mkdir $CDDA_WORKING_DIR
fi
cd $CDDA_WORKING_DIR

# Exit if there is no new version available.
if [ -e $FILE ]; then
	echo No new version available.
	exit 0
fi

echo Installing new version $VERSION.  One moment...

# Fetch new version.
wget -q $URL

# Back up old version.
rm -rf old 2>/dev/null
mv -f current old 2>/dev/null

# Extract new version into current/.
mkdir current
cd current
tar --strip-components=1 -xzf ../$FILE
cd ..

# Copy old saves over.
cp -af old/save* current/ 2>/dev/null
cp -af old/prerestore-save.tar.gz current/ 2>/dev/null

# Copy old config over.
cp -af old/config/ current/config/ 2>/dev/null


# Prune old archives until there are only six left.
while [ `ls cdda-linux-tiles-x64-*.tar.gz | sort -u | wc -l` -gt 6 ]; do
	rm -f `ls cdda-linux-tiles-x64-*.tar.gz | sort -u | head -n1`
done

‘cdda’ launch script:

#!/bin/bash

# OVERVIEW:
# ---------
#
# This script handles save game backups before launching CDDA.  The user is
#   prompted as to whether or not they would like to restore the save backup
#   from the last launch.  If 'N', then the save game backups are rotated and
#   the current save/ directory is backed up, before the game is launched.  If
#   'Y', then the current save/ directory is backed up to
#   'prerestore-save.tar.gz', deleted, and the previously backed up save
#   archive is extracted, before the game is launched.
# The default is to not restore.
# Ten rolling archives of the save/ directory are kept, so that you can
#   manually roll back farther if needed.


# REQUIREMENTS:
# -------------
#
# You must install CDDA with the 'cdda-update' script before this one will
#   work.


# INSTALLATION:
# -------------
#
# Place this script somewhere in your path (I like to use ~/bin/, but suit
#   yourself).  Change CDDA_WORKING_DIR below to something that suits your
#   particular system.


# CONFIGURATION:
# --------------
#
# Set this to your CDDA working directory from the "cdda-update" script.  If
#   you change this, you will also need to change it there.
CDDA_WORKING_DIR=~/bin/cdda-dir
#
# Set this to 'Y' if you want this script to automatically install the newest
#   experimental version before launching.  The 'cdda-update' script must be
#   in your path for this to work.
AUTO_UPDATE=y


###############################################################################

# Auto update.
if [ "x$AUTO_UPDATE" == "xy" ] || [ "x$AUTO_UPDATE" == "xY" ]; then
	cdda-update
fi

# Change to working dir and prompt for restore.
cd $CDDA_WORKING_DIR/current
read -p "Restore (y/N)? " restore

if [ "x$restore" == "xy" ] || [ "x$restore" == "xY" ]; then
	# Back up the current save/ and restore the most recent one.
	rm -f prerestore-save.tar.gz
	tar -czf prerestore-save.tar.gz save
	rm -rf save
	tar -xzf save-1.tar.gz
elif [ -e save ]; then
	# Rotate saves and back up the current save/.
	mv -f save-8.tar.gz save-9.tar.gz 2>/dev/null
	mv -f save-7.tar.gz save-8.tar.gz 2>/dev/null
	mv -f save-6.tar.gz save-7.tar.gz 2>/dev/null
	mv -f save-5.tar.gz save-6.tar.gz 2>/dev/null
	mv -f save-4.tar.gz save-5.tar.gz 2>/dev/null
	mv -f save-3.tar.gz save-4.tar.gz 2>/dev/null
	mv -f save-2.tar.gz save-3.tar.gz 2>/dev/null
	mv -f save-1.tar.gz save-2.tar.gz 2>/dev/null
	tar -czf save-1.tar.gz save
fi

# Start CDDA.
./cataclysm-launcher
1 Like

Updated the cdda-update script so that it correctly moves the old config to the newly installed version.

Interesting I would not use these myself since I update using git and compiling is easy, I must say though, very tidy, very nice.

I was doing that via script at first, but it was somewhat slow to do a git pull and then a compile. This method is about as fast as one’s internet connection, plus about 2 seconds to extract and move things around. I guess I am an impatient man, lol. Although I 'spect I’ll end up going back to compiling if I ever start making mods.

Fixed stupid bug in update script relating to pruning old archived versions.