Skip to content

Instantly share code, notes, and snippets.

@Drac346
Last active November 24, 2018 14:53
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Drac346/0f054a35d77ea639c78697734d1496e8 to your computer and use it in GitHub Desktop.
Factorio Linux Server Admin Script
#!/bin/bash
#Written on Ubuntu 16.04 LTS
#Written against Factorio 0.15.3 (tested again 0.15.35)
#walkthough: tbd
#props: https://gist.github.com/othyn/e1287fd937c1e267cdbcef07227ed48c
#disclaimer: stole the idea from someone (can't remember who, sorry), but modified it for my wants
#Requires Sudo for systemctl commands (start, stop, restart, ect)
clear
# Config
working_dir="/home/steam/factorio"
factorio="bin/x64/factorio"
whitelist="$working_dir/data/server-whitelist.json"
# End config
# Variables
url="https://www.factorio.com/get-download/latest/headless/linux64"
update_dir="/home/steam"
# End variables
cd $working_dir || exit
FactorioStart()
{
systemctl start factorio
}
FactorioStop()
{
systemctl stop factorio
}
FactorioRestart()
{
systemctl restart factorio
}
FactorioStatus()
{
systemctl status factorio.service
}
FactorioCheck ()
{
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 | sed s/.tar.xz//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
}
FactorioUpdate ()
{
FactorioCheck #Creates all the variables
echo "Installing $version_latest_filename"
echo "Downloading $version_latest_url..."
wget -qO "$update_file" "$url"
$factorio --apply-update "$update_file"
rm -f "$update_file"
printf "\n"
echo "Installed."
}
FactorioTail()
{
journalctl -u factorio.service -f
}
FactorioConsole()
{
tail -n 45 -f /home/steam/console.log
}
FactorioFailedAttempts()
{
echo "Searching:"
journalctl -u factorio.service | grep UserVerificationMissing
echo "search complete"
}
Usage ()
{
echo "Usage:"
echo "$0 [update|check|start|stop|restart|tail|console|fail|add]"
exit
}
for i in "$1"
do
case $i in
update) FactorioUpdate;;
check) FactorioCheck;;
start) FactorioStart;;
status) FactorioStatus;;
stop) FactorioStop;;
restart) FactorioRestart;;
tail) FactorioTail;;
console) FactorioConsole;;
fail) FactorioFailedAttempts;;
*) Usage;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment