Skip to content

Instantly share code, notes, and snippets.

@42atomys
Created January 10, 2021 23:18
Show Gist options
  • Save 42atomys/b631a7183556255ce8a7d3464715d76c to your computer and use it in GitHub Desktop.
Save 42atomys/b631a7183556255ce8a7d3464715d76c to your computer and use it in GitHub Desktop.
#!/bin/bash
# Used to update Factorio servers located on INSTALL_PATH
# to latest version of servers.
# Your server installations needs to follow the headless architecture "INSTALL_PATH/$name/factorio/{bin,config,...}"
# To work correctly this script want to found a systemctl service attached to your install location
# to restart the server.
# WARNING: No backup is done during this update.
export INSTALL_PATH="/home/factorio"
export LATEST_URL="https://factorio.com/get-download/latest/headless/linux64"
export LOCAL_NAME="server-latest"
export LOCAL_TAR_GZ="$LOCAL_NAME.tar.gz"
echo "> Update Factorio server located on $INSTALL_PATH..."
export FIND_PATH="$INSTALL_PATH/*/factorio"
echo "> Look at $FIND_PATH"
echo "> Found $(find $INSTALL_PATH/* -type d -name "factorio" | wc -l) installation(s) on $INSTALL_PATH"
echo "\n> Downloading Factorio latest version"
wget -qO /tmp/$LOCAL_TAR_GZ $LATEST_URL
echo "> Untar the archive in /tmp/$LOCAL_NAME"
mkdir -p /tmp/$LOCAL_NAME
tar -xf /tmp/$LOCAL_TAR_GZ -C /tmp/$LOCAL_NAME
echo ""
for pth in $(find $INSTALL_PATH/* -type d -name "factorio"); do
echo "> Update server at $pth"
serviceName=$(ps -e -o pid,unit,cmd | grep $pth | awk '{print $2}' | grep -v "session" | head -n 1)
if [ ! -z "$serviceName" ]; then
echo "> Stop the service $serviceName..."
systemctl stop $serviceName
fi
echo "> Update files..."
cp -rf /tmp/$LOCAL_NAME/factorio/* $pth/
if [ ! -z "$serviceName" ]; then
echo "> Restart the service $serviceName..."
systemctl restart $serviceName
fi
echo "> Update of $serviceName completed successfully !\n"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment