-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseds
executable file
·278 lines (250 loc) · 8.32 KB
/
seds
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
#!/bin/bash
# Put this script where you want Space Engineers installed
# Run 'chmod +x seds' if it is not already executable
# Run './seds install' to get started
# Stop on errors
set -e
STEAMCMD_DL='https://steamcdn-a.akamaihd.net/client/installer/steamcmd.zip'
SEDIR=$PWD
SEDS=./`basename "$0"`
NORMAL='\e[0m'
BLACK='\e[30;2m'
RED='\e[31;2m'
GREEN='\e[32;2m'
YELLOW='\e[33;2m'
BLUE='\e[34;2m'
MAGENTA='\e[35;2m'
CYAN='\e[36;2m'
WHITE='\e[37;2m'
GREY='\e[30;1m'
BRED='\e[31;1m'
BGREEN='\e[32;1m'
BYELLOW='\e[33;1m'
BBLUE='\e[34;1m'
BMAGENTA='\e[35;1m'
BCYAN='\e[36;1m'
BWHITE='\e[37;1m'
function vercomp {
if [[ $1 == $2 ]]; then
echo '0'
return 0
fi
local IFS=.
local i ver1=($1) ver2=($2)
# fill empty fields in ver1 with zeros
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do
ver1[i]=0
done
for ((i=0; i<${#ver1[@]}; i++)); do
if [[ -z ${ver2[i]} ]]; then
# fill empty fields in ver2 with zeros
ver2[i]=0
fi
if ((10#${ver1[i]} < 10#${ver2[i]})); then
echo '-1'
return 0
fi
if ((10#${ver1[i]} > 10#${ver2[i]})); then
echo '1'
return 0
fi
done
echo '0'
return -1
}
case "$1" in
startx)
printf "Starting virtual X-server ... "
Xvfb -screen 0 1024x768x16 -ac &>xvfb.log &
echo $1 > xvfb.pid
sleep 1
DISPLAY=:0 ratpoison &>ratpoison.log &
echo $1 > ratpoison.pid
x11vnc --localhost --display :0 & &>x11vnc.out
printf "${BGREEN}started!${NORMAL}\n"
echo "Create an SSH tunnel to forward port 5900 and launch x11vnc then connect to 'localhost' with a vncclient."
echo "If you are running Windows localy you can use Cygwin or PuTTY to create the tunnel."
#echo "ssh -L 5900:localhost:5900 <user>@<server> 'x11vnc -localhost -display :0'"
echo "ssh -L 5900:localhost:5900 <user>@<server>"
;;
stopx)
printf "Stopping virtual X-server and VNC ... "
if [ -e ratpoison.pid ]; then
kill `cat ratpoison.pid`
rm -f ratpoison.pid
fi
if [ -e xvfb.pid ]; then
kill `cat xvfb.pid`
rm -f xvfb.pid
fi
printf "${BRED}stopped.${NORMAL}\n"
;;
start)
if [ -e se.pid ]; then
echo "Space Engineers already running, pid `cat se.pid`" && false
else
printf "Starting Space Engineers Dedicated server ... "
cd SpaceEngineers/DedicatedServer
screen -S se -d -m wine SpaceEngineersDedicated.exe -console 2>/dev/null &
sepid=$!
cd - &>/dev/null
echo ${sepid} > se.pid
printf "${BGREEN}started!${NORMAL}\n"
printf "Run 'screen -x' to connect to screen running SEDS\n"
printf "<ctrl>-A,D will detach from the screen\n"
fi
;;
gui)
if [ -e se.pid ]; then
echo "Space Engineers already running, pid `cat se.pid`" && false
else
printf "Starting Space Engineers Dedicated server ... "
cd SpaceEngineers/DedicatedServer
DISPLAY=:0 wine SpaceEngineersDedicated.exe 1>se.out 2>se.err &
sepid=$!
cd - &>/dev/null
echo ${sepid} > se.pid
printf "${BGREEN}started!${NORMAL}\n"
fi
;;
toolbox)
DISPLAY=:0 wine ~/.wine/drive_c/SEToolbox/SEToolbox.exe& 2>/dev/null
;;
stop)
if [ -e se.pid ]; then
printf "Stopping server ... "
# Send a <ctrl>-C to attempt a clean shutdown
sepid=`cat se.pid`
echo ${sepid}
rm -f se.pid
kill -SIGINT ${sepid} &>/dev/null ||true
sleep 5
# ... but the SE server waits for a key-press to exit for some God-forsaken reason so we have to kill it hard
kill ${sepid} &>/dev/null || true
while kill -0 ${sepid} &>/dev/null; do
sleep 0.5
done
killall SpaceEngineersDedicated.exe &>/dev/null
printf "${BRED}stopped.${NORMAL}\n"
else
echo "No Space Engineers server running" && false
fi
;;
update)
STEAMUSER=`cat .steamuser 2>/dev/null || true`
if [ -z "${STEAMUSER}" ]; then
printf "Enter Steam username:\n"
read STEAMUSER
echo "${STEAMUSER}" > .steamuser
./Steamcmd/steamcmd.exe +login ${STEAMUSER} +quit
fi
mkdir -p SpaceEngineers
ln -sf ${PWD}/SpaceEngineers ~/.wine/drive_c/SpaceEngineers
mkdir -p ~/.wine/drive_c/users/`whoami`/Application\ Data/SpaceEngineersDedicated/Saves
ln -sf ~/.wine/drive_c/users/`whoami`/Application\ Data/SpaceEngineersDedicated Worlds
./Steamcmd/steamcmd.exe +force_install_dir C:\\SpaceEngineers +login ${STEAMUSER} +app_update 244850 +quit 2>/dev/null
#Steamcmd doesn't seem to always shutdown NCURSES correctly; a reset fixes it but also clears the screen
#reset
;;
login)
./Steamcmd/steamcmd.exe +login 2>/dev/null
;;
install_steam)
printf "${BWHITE}Downloading Steamcmd ... ${NORMAL}"
mkdir -p Steamcmd
cd Steamcmd
wget -O steamcmd.zip ${STEAMCMD_DL} &>/dev/null
printf "${BGREEN}done!${NORMAL}\n"
printf "${BWHITE}Unpacking ... ${NORMAL}"
unzip -u -o steamcmd.zip &>/dev/null
chmod +x steamcmd.exe
printf "${BGREEN}done!${NORMAL}\n"
printf "Updating Steam\n"
./steamcmd.exe +login anonymous +exit 2>/dev/null
cd - &>/dev/null
printf "${NORMAL}"
;;
install_wine)
sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get -y install wine winetricks zenity wine-gecko
export DISPLAY=0:0
WINEARCH=win32 wine wineboot &> /dev/null
winetricks msxml3 &> /dev/null
winetricks dotnet40 &> /dev/null
winetricks gdiplus &> /dev/null
;;
local_wine)
rm -rf ~/.wine
export DISPLAY=0:0
WINEARCH=win32 wine wineboot &> /dev/null
winetricks msxml3 &> /dev/null
winetricks dotnet40 &> /dev/null
winetricks gdiplus &> /dev/null
;;
install_mono)
# Could try using Mono with Wine64
#sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
;;
install_hg)
sudo apt-get -y install mercurial
;;
install_xvfb)
sudo apt-get -y install Xvfb
sudo apt-get -y install ratpoison
sudo apt-get -y install x11vnc
sudo apt-get -y install x11-apps
;;
install)
${SEDS} install_xvfb
${SEDS} startx
${SEDS} install_wine
${SEDS} install_hg
${SEDS} install_steam
${SEDS} update
sudo apt-get -y install screen
;;
#put an entry in your crontab pointing to this script with the first argument being 'backup <worldname>'.
backup)
# Using Mercurial for back-up because I think that will be easier for most people - especially if they want to clone the backups to their Windows PC
SAVE="./Worlds/Saves/$2"
if [ -z $2 ]; then
printf "Usage: ./seds backup <world>\n"
printf "Run './seds worlds' to see list of Space Engineers worlds\n" && false
else
if [ -d "${SAVE}" ]; then
if [ ! -d "${SAVE}/.hg" ]; then
hg init ${SAVE}
fi
hg status -R ${SAVE}
hg add -R ${SAVE}
hg commit -m"Backup" -R ${SAVE}
hg status -R ${SAVE}
else
printf "World ${BYELLOW}%s${NORMAL} not found at ${BYELLOW}%s${NORMAL}.\n" "$2" "${SAVE}" && false
fi
fi
;;
worlds)
ls -1d ./Worlds/Saves/*/ | sed -e "s:./Worlds/Saves/::" | awk -F/ '{ printf $1 "\n" }'
;;
revert)
SAVE="./Worlds/Saves/$2"
if [ -d "${SAVE}" ]; then
if [ -d "${SAVE}/.hg" ]; then
hgdate=`hg log -l 1 -R ${SAVE}|awk '/date/ { print $0 }'|sed 's/date:\ \+//'`
printf "This will undo all changes back to ${BYELLOW}%s${NORMAL} and ${BMAGENTA}CANNOT be undone${NORMAL} !\n" "${hgdate}"
printf "Are you ${BYELLOW}SURE${NORMAL}?\n${BRED}<ctrl>-C${NORMAL} to abort, ${BGREEN}<enter>${NORMAL} to continue\n"
read
hg revert --all -R ${SAVE}
else
printf "No backup found at ${BYELLOW}%s${NORMAL} !\n" "${SAVE}" && false
fi
else
printf "World ${BYELLOW}%s${NORMAL} not found at ${BYELLOW}%s${NORMAL}.\n" "$2" "${SAVE}" && false
fi
;;
*)
printf "${BWHITE}./seds ${NORMAL}[${BCYAN}install${NORMAL}|${BYELLOW}update${NORMAL}|${BGREEN}startx${NORMAL}|${BRED}stopx${NORMAL}|${BGREEN}gui${NORMAL}|${BGREEN}start${NORMAL}|${BRED}stop${NORMAL}|${BMAGENTA}toolbox${NORMAL}|${BMAGENTA}worlds${NORMAL}|${BMAGENTA}backup <world-name>${NORMAL}]${NORMAL}\n" && false
;;
esac