Last active
May 11, 2017 17:45
-
-
Save NotoriousPyro/2005be0a434f52ef439abdead5089ed8 to your computer and use it in GitHub Desktop.
Place anywhere, then edit the file to configure it. Then run it like so: ./factorio-server.sh [update|start|stop|restart]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Config | |
| working_dir="/opt/factorio-server" | |
| factorio="bin/x64/factorio" | |
| start_cmd="systemctl start factorio-server" | |
| stop_cmd="systemctl stop factorio-server" | |
| # End config | |
| # Variables | |
| url="https://www.factorio.com/get-download/latest/headless/linux64" | |
| update_dir="update" | |
| # End variables | |
| cd $working_dir || exit | |
| if [ ! -e $update_dir ]; then mkdir $update_dir; fi | |
| if [ "$2" == "--force" ]; then update="force"; fi | |
| ver="1.0" | |
| printf "Factorio Updater %s by NotoriousPyro\n\n" "$ver" | |
| FactorioStart () | |
| { | |
| echo "Starting the Factorio server..." | |
| $start_cmd | |
| } | |
| FactorioStop () | |
| { | |
| echo "Stopping the Factorio server..." | |
| $stop_cmd | |
| } | |
| FactorioRestart () | |
| { | |
| echo "Restarting the Factorio server..." | |
| FactorioStop && FactorioStart | |
| } | |
| FactorioUpdate () | |
| { | |
| version_current=$($factorio --version | grep "Version: " | awk '{print $2}') | |
| version_latest_url=$(curl -sI "$url" | grep "Location: " | awk '{print $2}') | |
| version_latest_filename=$(echo "$version_latest_url" | cut -d '/' -f 5 | cut -d '?' -f 1) | |
| version_latest=$(echo "$version_latest_filename" | sed s/factorio_headless_x64_//g | sed s/.tar.gz//g) | |
| update_file="$update_dir/$version_latest_filename" | |
| echo "Current version: $version_current" | |
| echo "Latest version: $version_latest [$version_latest_filename]" | |
| printf "\n" | |
| if [ "$update" == "force" ]; then version_current=""; fi | |
| if [ "$version_current" == "$version_latest" ]; then echo "No new version detected" & exit; fi | |
| echo "Installing $version_latest_filename" | |
| FactorioStop | |
| echo "Downloading $version_latest_url..." | |
| wget -qO "$update_file" "$url" | |
| $factorio --apply-update "$update_file" | |
| rm -f "$update_file" | |
| printf "\n" | |
| echo "Installed." | |
| FactorioStart | |
| } | |
| Usage () | |
| { | |
| echo "Usage:" | |
| echo "$0 [update|start|stop|restart]" | |
| exit | |
| } | |
| for i in "$1" | |
| do | |
| case $i in | |
| update) FactorioUpdate;; | |
| start) FactorioStart;; | |
| stop) FactorioStop;; | |
| restart) FactorioRestart;; | |
| *) Usage;; | |
| esac | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment