home · contact · privacy
Explicitely call python3 in wrapper script, don't trust script hashbang.
[plomrogue] / start_server_client_union.sh
1 #!/bin/sh
2
3 # Abort the script on error.
4 set -e
5
6 # Don't let any log leftovers from before interfere.
7 if [ -e ./log ]
8 then
9     rm log
10 fi
11
12 # Abort if no proper Python version installed.
13 test=`command -v python3 | wc -l`
14 if [ 1 != $test ]
15 then
16     echo "FAILURE:"
17     echo "No python3 installed, but it's needed!"
18     exit 1
19 fi
20
21 # Give helpful message to players that want to start without compiling first.
22 if [ ! -e ./roguelike-client ]
23 then
24     echo 'No ./roguelike-client executable found. Try "./redo" first?'
25     false
26 fi
27 if [ ! -e ./libplomrogue.so ]
28 then
29     echo 'No ./libplomrogue.so library found. Try "./redo" first?'
30     false
31 fi
32
33 # Use shell script's arguments for server and pipe server output to log file.
34 # This script's wrapper script will read it out on exit.
35 python3 ./roguelike-server "$@" > log 2>&1 &
36
37 # Give server some time to start up and exit on error.
38 sleep 0.01
39
40 # The client should not start if the server is not running. (If the server was
41 # running in the foreground, any error exit of it so far would be caught by "set
42 # -e" above. But "set -e" is blind to error codes generated in the background.)
43 kill -0 $! 2> /dev/null
44
45 # Give server some time (max. 10 seconds) to generate its worldstate file.
46 i=0
47 while [ ! -e server/worldstate ] && [ $i -le 1000 ]
48 do
49     sleep 0.01
50     i=`expr $i + 1`
51 done
52 if [ ! -e server/worldstate ]
53 then
54     echo "Server failed generating worldstate file within given time limit."
55     false
56 fi
57
58 # Only start the interface when everything else went well.
59 kill -0 $! 2> /dev/null
60 ./roguelike-client