-
Notifications
You must be signed in to change notification settings - Fork 35
/
openttd.sh
executable file
·110 lines (96 loc) · 3.53 KB
/
openttd.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
#!/bin/sh
old_openttd_dir="/home/openttd/.openttd"
new_openttd_dir="/home/openttd/.local/share/openttd"
#check if new openttd profile dir exists
if [ -d ${new_openttd_dir} ]; then
# if exists, set the new path
savepath="/home/openttd/.local/share/openttd/save"
else
# if not, leave the old path
savepath="/home/openttd/.openttd/save"
fi
savegame="${savepath}/${savename}"
LOADGAME_CHECK="${loadgame}x"
loadgame=${loadgame:-'false'}
PUID=${PUID:-911}
PGID=${PGID:-911}
PHOME=${PHOME:-"/home/openttd"}
USER=${USER:-"openttd"}
if [ ! "$(id -u ${USER})" -eq "$PUID" ]; then usermod -o -u "$PUID" ${USER} ; fi
if [ ! "$(id -g ${USER})" -eq "$PGID" ]; then groupmod -o -g "$PGID" ${USER} ; fi
if [ "$(grep ${USER} /etc/passwd | cut -d':' -f6)" != "${PHOME}" ]; then
if [ ! -d ${PHOME} ]; then
mkdir -p ${PHOME}
chown ${USER}:${USER} -R ${PHOME}
fi
usermod -m -d ${PHOME} ${USER}
fi
#create save folder and set permissions
mkdir -p ${savepath}
chown ${USER}:${USER} -R ${savepath}
#fix home folder permissions
chown ${USER}:${USER} -R ${PHOME}
echo "
-----------------------------------
GID/UID
-----------------------------------
User uid: $(id -u ${USER})
User gid: $(id -g ${USER})
User Home: $(grep ${USER} /etc/passwd | cut -d':' -f6)
-----------------------------------
"
# Loads the desired game, or prepare to load it next time server starts up!
if [ ${LOADGAME_CHECK} != "x" ]; then
case ${loadgame} in
'true')
if [ -f ${savegame} ]; then
echo "We are loading a save game!"
echo "Lets load ${savegame}"
su -l openttd -c "/usr/share/games/openttd/openttd -D -g ${savegame} -x -d ${DEBUG}"
exit 0
else
echo "${savegame} not found..."
exit 0
fi
;;
'false')
echo "Creating a new game."
su -l openttd -c "/usr/share/games/openttd/openttd -D -x -d ${DEBUG}"
exit 0
;;
'last-autosave')
savegame=${savepath}/autosave/`ls -rt ${savepath}/autosave/ | tail -n1`
if [ -r ${savegame} ]; then
echo "Loading ${savegame}"
su -l openttd -c "/usr/share/games/openttd/openttd -D -g ${savegame} -x -d ${DEBUG}"
exit 0
else
echo "${savegame} not found..."
echo "Creating a new game."
su -l openttd -c "/usr/share/games/openttd/openttd -D -x -d ${DEBUG}"
exit 0
fi
;;
'exit')
savegame="${savepath}/autosave/exit.sav"
if [ -r ${savegame} ]; then
echo "Loading ${savegame}"
su -l openttd -c "/usr/share/games/openttd/openttd -D -g ${savegame} -x -d ${DEBUG}"
exit 0
else
echo "${savegame} not found..."
echo "Creating a new game."
su -l openttd -c "/usr/share/games/openttd/openttd -D -x -d ${DEBUG}"
exit 0
fi
;;
*)
echo "ambigous loadgame (\"${loadgame}\") statement inserted."
exit 1
;;
esac
else
echo "\$loadgame (\"${loadgame}\") not set, starting new game"
su -l openttd -c "/usr/share/games/openttd/openttd -D -x"
exit 0
fi