steam-dontstarve/entrypoint.sh
2018-12-15 21:12:00 +01:00

128 lines
2.9 KiB
Bash

#!/bin/bash
function fail {
# Write to stderr
echo "ERROR: $@" >&2
exit 1
}
# what are we trying to install?
game_nm="DST"
game_id=343050
DST_SERVER_DIR=${DST_SERVER_DIR:-'server'}
dontstarve_dir="$HOME/.klei/DoNotStarveTogether"
# install game to this directory
installdir=/home/steam/games/$game_nm
# if path does not exist, create it
mkdir -p $installdir
if [[ -w $installdir ]] # can we write into the directory?
then
# Install or update the game in /home/steam/games/[game name]
/opt/steamcmd/steamcmd.sh \
+login anonymous \
+force_install_dir $installdir \
+app_update $game_id validate \
+quit
else
# install dir maybe mounted read-only, simply
# skip installing/updating and inform the user.
echo "Skipped game installation."
fi
# if game dir does not exist, create it
mkdir -p ${dontstarve_dir}/${DST_SERVER_DIR}
if [[ ! -w ${dontstarve_dir}/${DST_SERVER_DIR} ]]
then
fail "Not allowed to write to game dir as user $(id -u)"
fi
if [[ ! -f ${dontstarve_dir}/${DST_SERVER_DIR}/cluster_token.txt ]]
then
mkdir -p ${dontstarve_dir}/${DST_SERVER_DIR}
echo "${DST_CLUSTER_TOKEN}" > ${dontstarve_dir}/${DST_SERVER_DIR}/cluster_token.txt
fi
if [[ ! -f ${dontstarve_dir}/${DST_SERVER_DIR}/cluster.ini ]]
then
mkdir -p ${dontstarve_dir}/${DST_SERVER_DIR}
cat <<- EOF > ${dontstarve_dir}/${DST_SERVER_DIR}/cluster.ini
[GAMEPLAY]
game_mode = ${DST_GAME_MODE}
max_players = ${DST_MAX_PLAYERS}
pvp = ${DST_PVP}
pause_when_empty = ${DST_}
[NETWORK]
cluster_description = ${DST_CLUSTER_DESCRIPTION}
cluster_name = ${DST_CLUSTER_NAME}
cluster_intention = ${DST_CLUSTER_INTENTION}
cluster_password = ${DST_CLUSTER_PASSWORD}
[MISC]
console_enabled = true
[SHARD]
shard_enabled = true
bind_ip = 127.0.0.1
master_ip = 127.0.0.1
master_port = 10889
cluster_key = paul
EOF
fi
if [[ ! -f ${dontstarve_dir}/${DST_SERVER_DIR}/Master/server.ini ]]
then
mkdir -p ${dontstarve_dir}/${DST_SERVER_DIR}/Master
cat <<- EOF > ${dontstarve_dir}/${DST_SERVER_DIR}/Master/server.ini
[NETWORK]
server_port = 11000
[SHARD]
is_master = true
[STEAM]
master_server_port = 27018
authentication_port = 8768
[ACCOUNT]
encode_user_path = true
EOF
fi
if [[ ! -f ${dontstarve_dir}/${DST_SERVER_DIR}/Caves/server.ini ]]
then
mkdir -p ${dontstarve_dir}/${DST_SERVER_DIR}/Caves
cat <<- EOF > ${dontstarve_dir}/${DST_SERVER_DIR}/Caves/server.ini
[NETWORK]
server_port = 11001
[SHARD]
is_master = false
name = Caves
id = 2521590582
[STEAM]
master_server_port = 27019
authentication_port = 8769
[ACCOUNT]
encode_user_path = true
EOF
fi
# run the next commands from the installdir
cd $installdir/bin
run_shared=(./dontstarve_dedicated_server_nullrenderer)
run_shared+=(-console)
run_shared+=(-cluster "$DST_SERVER_DIR")
run_shared+=(-monitor_parent_process $$)
"${run_shared[@]}" -shard Caves | sed 's/^/Caves: /' &
"${run_shared[@]}" -shard Master | sed 's/^/Master: /'