summaryrefslogtreecommitdiff
path: root/debian/bin/dwarf-fortress
blob: 2afbcfa2484b4efc6825104266f9434ff3582ce9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash -eu
#
# Debian Dwarf Fortress launcher
# © 2012 Beren Minor <beren.minor+debian@gmail.com>
# © 2015 Benjamin Barenblat <bbaren@mit.edu>
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>
#
# On Debian systems, the complete text of the GNU General Public License version
# 3 can be found in "/usr/share/common-licenses/GPL-3".
#
#
# This script adapts Dwarf Fortress to run out of tree by staging its files into
# a temporary directory, symlinking in the user’s save files, and launching.

# User configuration: This environment variable controls where user saves and
# movies will be stored.  It defaults to ~/.local/share/dwarf-fortress.
declare -r DWARF_FORTRESS_DATA_HOME="${DWARF_FORTRESS_DATA_HOME:-${XDG_DATA_HOME:-$HOME/.local/share}/dwarf-fortress}"


declare -r DF="/usr/lib/games/dwarf-fortress"

# Create a directory to stage Dwarf Fortress in.
declare -r TMP="$(mktemp --directory --tmpdir dwarf-fortress.XXXXXXXXXX)"
trap "rm -rf \"$TMP\"" EXIT

# Stage the game files.
cp -r --dereference --symbolic-link "$DF"/* "$TMP"

# Actually copy the data/index file, because Dwarf Fortress gets unhappy if it’s
# a symlink.
rm "$TMP"/data/index
cp -r --dereference --reflink=auto "$DF"/data/index "$TMP"/data

# Link in the user’s save and movies files.
mkdir -p "$DWARF_FORTRESS_DATA_HOME"/movies
mkdir -p "$DWARF_FORTRESS_DATA_HOME"/save
ln -s "$DWARF_FORTRESS_DATA_HOME"/movies "$TMP"/data
ln -s "$DWARF_FORTRESS_DATA_HOME"/save "$TMP"/data

# Start Dwarf Fortress!
echo "User data is $DWARF_FORTRESS_DATA_HOME"
echo "wd is $TMP"
"$TMP"/df "$@"