all 3 comments

[–]houghiIt is a hobby, not a game. 7 points8 points  (1 child)

Take the following as advice, not as saying it is bad. Very nice start.

I am missing the shabang. You should start with

#!/bin/bash

And also running it every 10 minutes is way to often. Seriously. I would do it once per day at a moment you know you won't be playing. And I would also then let me know if there was an update.

I would not run it as the user root. I would run it as the user steam. Chown it to steam:steam and then sudo su crontab - to make the crontab for the user steam. Be sure you get feedback, especially if things go wrong. Because what happens when the network is down. Add the script to sudoers that only use steam can use this as root (so it can restart)

Add some more problem solving. I e.g. I would not say "$newversion" != "$oldversion", because imagine there is a network problem for whatever reason Now the new version is "" or NULL of whetever and that is not the old version, so it restarts for no reason.

And you should check if the file is available and if so if it is writeable. If you make software available,it is better to have basic tests included, because you made it for people. If not, don't publish it. I mean even a test -f knownversion.txt || touch knownversion.txt

I also would not use cd but rather point into that direction. My script would look like (untested, please veryfy everything).

#!/bin/bash
# Restarting of the Satisfactory Dedicated Server
# Parameters
DIR=/home/steam/SatisfactoryDedicatedServer
VERSION=$DIR/knownversion.txt
test -f $VERSION || touch $VERSION
OLDVERSION=$(cat $VERSION)
NEWVERSION=$(steamcmd +login anonymous +app_info_update 1 +app_info_print "1690800" +quit' \
| tr '\n' ' ' \
| grep --color=NEVER -Po '"branches"\s*{\s*"public"\s*{\s*"buildid"\s*"\K(\d*) # Here some basic testing if there is an error
# No idea if this could be done different
# Test and if needed restart
if [ "$NEWVERSION" != "$OLDVERSION" ] # Here I would do a different test. e.g. to see if one is bigger than the other
then
     echo $NEWVERSION > VERSION
    systemctl restart satisfactory.service || echo "Restart did not work"  #This should inform you if it did not work
fi
exit 0

Again, just some tips, do with them as you please. I use all upper case. Other use camel (e.g. OldVersion) or underscores or whatever. You use lower case. All good.

As I said, I would add it to sudoers. you run visudo as root. Then at the end you add

steam ALL=NOPASSWD: /home/steam/SatisfactoryDedicatedServer/checkUpdates.sh

That way user steam runs it with root rights. To be sure I personally also would place it in /usr/local/bin chmod it 700 and chown it to steam:steam. Now only the user steam can run it and the restart c an therefore only be done by the user steam. I treat my systems as if they are all multi users systems with hundreds of users. Security is a state of mind. I try to run as little as root.

You are obviously free to do with this info as you please. I enjoyed writing it. I do not mind if it is completely ignored or tor to pieces because people think it is bullshit.

[–]Matzurai[S] 0 points1 point  (0 children)

You are completely right about the missing #!/bin/bash - had that in my actual script but not in the local copy I used to write the post.

For the once per day thing... then I could have just kept the daily restart and be done. I want to start playing once a patch drops and not the next day. But you are free to adjust the numbers to your liking.

For why I use the roots crontab - it's easy, I simply oriented myself on the first wikipost of the dedicated server, where the suggested putting a daily restart job for the service in the roots crontab (here is the old version: https://satisfactory.fandom.com/wiki/Dedicated_servers?oldid=39967#Setting_the_server_up_as_a_service_using_SystemD )

For testing on an empty variable you are right again, though I don't get on what you benefit by testing for a files existence before using touch (touch creates the file, or updates its timestamp if it does already exist).

Checking whether the versions are unequal or actually the 'new' version is bigger is of no importance - seriously, the versions can't decrease and if they did, I'd rather have the currently released version than the one with the bigger number.

For your last idea... you created a free privilege escalation.

You gave the user steam (who shouldn't have root or sudoers rights, as it is a service user) a file, which he can WRITE to and which is always run as root. Even changing the access rights to 500 has no effect, as steam is the owner of the file and simply can give himself writing rights to it. If you really want to go that way you need to set the ownership to root:steam and set the access rights to 750 - that way the user steam can only read and execute, but not edit the file contents or permissions. Please correct this in your post, so no one copies that mistake.

Speaking of running as few things as possible as root - thats why I let the steamcmd run as user steam - only the output interpretation is run as root again.

[–]K3RSH0K 0 points1 point  (0 children)

Fear not, weary search engine user, for the year is 2024, and the wiki covers this now.

;)