factorio/start.sh

40 lines
1.4 KiB
Bash
Raw Normal View History

2016-12-15 00:37:56 +00:00
#!/bin/bash -e
set -o pipefail
ACTION=$1
BINARY="/opt/factorio/bin/x64/factorio"
MAP_FILE="mapfile.zip"
case ${ACTION} in
"init")
echo "Initializing files in case they do not exist: map-gen-settings.json / server-settings.json"
[ -e map-gen-settings.json ] || cp /opt/defaults/map-gen-settings.json map-gen-settings.json
[ -e server-settings.json ] || cp /opt/defaults/server-settings.json server-settings.json
;;
"create")
echo "Creating map at ${MAP_FILE} with settings from map-gen-settings.json"
[ -e map-gen-settings.json ] || cp /opt/defaults/map-gen-settings.json map-gen-settings.json
exec ${BINARY} --map-gen-settings map-gen-settings.json --create ${MAP_FILE}
;;
"start")
echo "Starting game from map file ${MAP_FILE} with settings from server-settings.json"
if ! [ -e ${MAP_FILE} ]; then
echo "Error: There is no map file at ${MAP_FILE}. Use 'create' or put a map file at that location."
exit 1
fi
[ -e server-settings.json ] || cp /opt/defaults/server-settings.json server-settings.json
exec ${BINARY} --server-settings server-settings.json --start-server ${MAP_FILE}
2016-12-15 00:37:56 +00:00
;;
2016-12-15 00:42:19 +00:00
"help")
echo "Usage: docker run quay.io/luzifer/factorio [init | create | start]"
echo
echo "Alternative: docker run quay.io/luzifer/factorio <factorio server options>"
2016-12-15 00:53:43 +00:00
;;
2016-12-15 00:37:56 +00:00
*)
exec ${BINARY} "$@"
;;
esac