-
Notifications
You must be signed in to change notification settings - Fork 3
/
dwarf-fortress.sh
executable file
·124 lines (102 loc) · 3.27 KB
/
dwarf-fortress.sh
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/bin/bash
# XXX Build a runtime directory in /tmp?
cd ~/df_linux || exit 1
DFHACK=""
usage() {
cat <<EOF
Usage: $0 [OPTION...]
Application data can be found in ~/.var/app/com.bay12games.DwarfFortress/df_linux/
By default, this will launch plain Dwarf Fortress.
If a dfhack init file exists then it will launch DFHack by default.
If a file named .dfrc exists in df_linux, then it will be sourced before launching Dwarf Fortress.
If a file named .dfhackrc exists in df_linux, then it will be sourced before setting up dfhack.
Options:
-d Runs plain Dwarf Fortress
-h Runs dfhack, creating an init file if one doesn't already exist
-t Run dfhack with TWBT
EOF
}
while getopts ":hsdtR" opt; do
case $opt in
t)
DFHACK="true"
TWBT="true"
;;
h)
DFHACK="true"
;;
d)
DFHACK="false"
TWBT="false"
;;
\?)
echo "Unknown option -$OPTARG"
usage
exit 1
;;
esac
shift
done
if [ ! -d /app/dfhack/hack ]; then
[ "$DFHACK" = "true" ] && ( echo "This version of com.bay12games.DwarfFortress does not come with dfhack support. Sorry."; exit 1; )
DFHACK="false"
fi
if [ ! -d /app/twbt/hack ]; then
[ "$TWBT" = "true" ] && ( echo "This version of com.bay12games.DwarfFortress does not come with TWBT support. Sorry."; exit 1; )
TWBT="false"
fi
DIRS=( data raw )
HACKDIRS=( )
FILES=( '*.txt' README.linux )
[ -f dfhack.init ] && [ "$DFHACK" != "false" ] && DFHACK="true"
if [ "$DFHACK" = "true" ] && [ ! -t 0 ] && [ ! -t 1 ]; then
# FIXME Can this be done, or maybe a separate terminal could be opened for handling dfhack?
# TODO Show this message to the user
echo "Trying to run dfhack outside of terminal, this won't work at the moment."
DFHACK="false"
fi
[ "$DFHACK" = "true" ] && HACKDIRS+=( dfhack/hack dfhack/dfhack-config dfhack/stonesense )
[ "$TWBT" = "true" ] && HACKDIRS+=( twbt/hack twbt/data )
for DIR in "${DIRS[@]}"; do
if [ ! -e "$DIR/.skip" ]; then
cp -nr "/app/extra/$DIR" .
fi
done
for DIR in "${HACKDIRS[@]}"; do
if [ ! -e "$DIR/.skip" ]; then
cp -nr "/app/$DIR" .
fi
done
for PATTERN in "${FILES[@]}"; do
for FILE in /app/extra/$PATTERN; do
if [ ! -e ".$FILE.skip" ]; then
[ -f "$FILE" ] && cp -n "$FILE" .
fi
done
done
# Don't overwrite user configuration by default
AUTOSKIP=( data/init/init.txt data/init/g_init.txt dfhack.init )
for FILE in "${AUTOSKIP[@]}"; do
SKIPNAME="$(pwd)/$(dirname "$FILE")/.$(basename "$FILE").skip"
[ -e "$SKIPNAME" ] || touch "$SKIPNAME"
done
if [ "$DFHACK" = "true" ] && [ ! -f dfhack.init ]; then
echo "Creating dfhack.init"
cp /app/dfhack/dfhack.init-example dfhack.init
fi
if [ "$DFHACK" = "true" ] || [ -f dfhack.init ] && [ "$DFHACK" != "false" ]; then
RC='.dfhackrc'
if [ -r "$RC" ]; then
. "$RC"
fi
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/app/dfhack/hack/libs:/app/dfhack/hack"
export LD_PRELOAD="${PRELOAD_LIB:+/app/$PRELOAD_LIB:}/app/dfhack/hack/libdfhack.so"
fi
if [ "$TWBT" = "true" ]; then
sed -i 's;PRINT_MODE:2D;PRINT_MODE:TWBT;g' data/init/init.txt
fi
RC='.dfrc'
if [ -r "$RC" ]; then
. "$RC"
fi
/app/extra/libs/Dwarf_Fortress "$@"