diff --git a/start_server.sh b/start_server.sh index 4efda6d..dba0ed5 100644 --- a/start_server.sh +++ b/start_server.sh @@ -1,7 +1,22 @@ #!/usr/bin/env bash -# Fetch variables from config.sh -source config.sh +# If config.sh exists, fetch variables from it +if [ -f "config.sh" ]; then + source config.sh + echo "Loaded configuration from config.sh" +else + # If config.sh doesn't exist, check if config.sh.example exists + if [ -f "config.sh.example" ]; then + # Fetch variables from config.sh.example + echo "WARNING: config.sh file does not exist, falling back on default configuration." + source config.sh.example + echo "Loaded configuration from config.example.sh" + else + # Handle the scenario when both files are missing + echo "FATAL: Configuration files are missing! Cannot start the Factorio server." + exit 1 + fi +fi # Retrieves the script's directory and cd's into it. script_dir="$(cd "$(dirname "$0")" && pwd)" @@ -10,15 +25,19 @@ cd ${script_dir} # Check if the current directory is inside a Git repository. if [ -d .git ] || git rev-parse --is-inside-work-tree > /dev/null 2>&1 ; then # Pull updated scripts from CoastalCommits. + echo "Updating scripts..." git pull + echo "Scripts updated!" else - # The current directory is not part of a Git repository. echo "WARNING: This directory is not a Git repository. Script updates will not be automatically fetched." fi # This handles automatically updating the Factorio binary. +echo "Fetching Factorio binary..." wget https://factorio.com/get-download/stable/headless/linux64 -O factorio_headless.tar.xz +echo "Extracting Factorio binary..." tar -xf factorio_headless.tar.xz --strip-components=1 --overwrite +echo "Factorio binary updated!" rm -f factorio_headless.tar.xz # This checks if the ./saves/$save_name.zip save file exists or not...