FactorioScripts/start_server.sh

33 lines
1.3 KiB
Bash
Raw Normal View History

2023-08-13 15:45:11 -04:00
#!/usr/bin/env bash
save_name="default" # Set this to the name of your save file.
# Don't change this unless you know what you're doing.
# Set this to the custom parameters you want the --create command to use.
extra_params_create=""
2023-08-13 15:45:11 -04:00
# Don't change this unless you know what you're doing.
# Set this to the custom parameters you want the --start_server command to use.
extra_params_start_server=""
# Retrieves the script's directory and cd's into it.
script_dir="$(cd "$(dirname "$0")" && pwd)"
cd ${script_dir}
2023-08-13 15:45:11 -04:00
# This handles automatically updating the Factorio binary.
wget https://factorio.com/get-download/stable/headless/linux64 -O factorio_headless.tar.xz
tar -xf factorio_headless.tar.xz --strip-components=1 --overwrite
rm -f factorio_headless.tar.xz
# This checks if the ./saves/$save_name.zip save file exists or not...
if [ ! -f "./saves/${save_name}.zip" ]; then
# ...if not, create the save file
./bin/x64/factorio ${extra_params_create} --create "./saves/${save_name}.zip"
fi
# This creates a byobu session that starts the server.
byobu new-session -d -s factorio "./bin/x64/factorio ${extra_params_start_server} --start-server ./saves/${save_name}.zip"
# This attaches the current terminal to the byobu session.
# Comment this out if you don't want this functionality.
byobu attach -t factorio