Have fun
Code: Select all
#!/bin/bash
NC="\033[0m"
RED="\033[0;31m"
GREEN="\033[0;32m"
WHITE="\033[1;37m"
function die
{
echo -e "${RED}$@${NC}"
exit 1
}
function update
{
wget -O "factorio_${release}.tar.xz" https://factorio.com/get-download/${release}/headless/linux64 || die "Error downloading new version"
mv "factorio" "factorio_${current}"
tar xvJf "factorio_${release}.tar.xz"
cp "factorio_${current}/data/server-settings.json" "factorio/data/"
echo "Update successful!"
}
function get_versions
{
release=$(curl https://factorio.com 2>&1 | grep -A1 Experimental | grep \<dd\> | cut -d'>' -f2 | cut -d'<' -f1)
current=$(cat ./factorio/data/base/info.json | grep version | cut -d'"' -f4)
}
function trigger_check
{
check=1
}
function do_update
{
echo "Released version: $release"
echo "Current version: $current"
if [ "${current}" != "${release}" ]; then
echo "Needing update"
update
else
echo "Factorio is up-to-date!"
fi
}
trap trigger_check SIGUSR1
get_versions
do_update
while true; do
# this is my script to launch factorio!
./start_mp17.sh &
update=0
while [ $update -eq 0 ]; do
check=0
while [ $check -eq 0 ]; do
sleep 5
done
get_versions
if [ "${current}" != "${release}" ]; then
update=1
else
echo "Factorio is up-to-date"
fi
done
pid=$(ps aux | sed 's/ */ /g' | grep "\./factorio/bin" | grep -v grep | cut -d' ' -f2)
if [ ! -z "${pid}" ]; then
echo "Sending SIGINT to $pid"
kill -SIGINT $pid
echo "Waiting for $pid"
tail --pid $pid -f /dev/null
echo "Updating"
do_update
fi
done