Last active
May 12, 2022 22:16
-
-
Save dbannik/de5fa36e6cd73c7c28efeea480dc32df to your computer and use it in GitHub Desktop.
autoupdate game servers (steam)
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
| <?php | |
| if(!array_key_exists(1, $argv)) exit(); | |
| $appid = (int) $argv[1]; | |
| $version = (int) preg_replace("/[^0-9]+/","",$argv[2]); | |
| $url = "http://api.steampowered.com/isteamapps/uptodatecheck/v0001?appid=$appid&version=$version"; | |
| $data = file_get_contents($url); | |
| $res = json_decode($data, true); | |
| if(@$res['response']['version_is_listable']) | |
| echo "OK"; | |
| else | |
| echo "UPDATE"; |
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/sh | |
| if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then | |
| echo "$0 APPID SERVERAPPID STEAMINF" | |
| echo "$0 240 232330 cstrike/steam.inf" | |
| exit; | |
| fi | |
| APPID="$1" | |
| SERVERAPPID="$2" | |
| STEAMINF="$3" | |
| STEAMCMD="$HOME/steamcmd" | |
| DIRFILES="$STEAMCMD/$APPID" | |
| APPDIR="$HOME/$APPID" | |
| DATE="$(date '+%Y-%m-%d_%H:%M:%S')" | |
| # Checked state program | |
| if pgrep -f $0 > /dev/null 2>&1 ; then | |
| if [ -f $0.pid ] && pgrep -f $0 | tr ' ' '\n' | grep -w $(cat $0.pid) > /dev/null 2>&1 ; then | |
| echo "$0 in progress.." | |
| exit | |
| fi | |
| fi | |
| echo "$0 Started." | |
| echo $$ > $0.pid | |
| # Get steamcmd | |
| steamcmd() { | |
| mkdir -p $STEAMCMD | |
| if [ -d $STEAMCMD ]; then | |
| cd $STEAMCMD | |
| curl http://media.steampowered.com/client/installer/steamcmd_linux.tar.gz | tar xvz | |
| fi | |
| if [ $? -ne 0 ]; then | |
| echo "failed to install steamcmd" | |
| else | |
| echo "steamcmd install." | |
| fi | |
| } | |
| # | |
| csnapshot() { | |
| if [ -f $DIRFILES/$STEAMINF ]; then | |
| HOCK="$(awk -F'=' '/PatchVersion/ {print $2}' $DIRFILES/$STEAMINF | tr -d '\n\r')" | |
| if [ $? -eq 0 ]; then | |
| DATE=$HOCK | |
| fi | |
| fi | |
| touch $APPDIR/.rsyncignore | |
| if [ -L $APPDIR/current ]; then | |
| rsync -a --link-dest=$APPDIR/current $DIRFILES/ $APPDIR/$DATE --exclude-from $APPDIR/.rsyncignore | |
| else | |
| rsync -a $DIRFILES/ $APPDIR/$DATE --exclude-from $APPDIR/.rsyncignore | |
| fi | |
| if [ $? -eq 0 ]; then | |
| rm $APPDIR/current | |
| cd $APPDIR && ln -sf $DATE $APPDIR/current | |
| fi | |
| } | |
| # Check steamcmd installed | |
| if [ ! -f $STEAMCMD/steamcmd.sh ]; then | |
| steamcmd | |
| fi | |
| # Check directory app | |
| if [ ! -d $APPDIR ]; then | |
| mkdir -p $APPDIR | |
| fi | |
| # getVersion game server | |
| if [ -f $APPDIR/current/$STEAMINF ]; then | |
| VERSION="$(awk -F'=' '/PatchVersion/ {print $2}' $APPDIR/current/$STEAMINF)" | |
| CHECK="$(php steam-check.php $APPID $VERSION)" | |
| else | |
| echo "is not file $APPDIR/current/$STEAMINF" | |
| fi | |
| # Check update or install game server | |
| if [ "$CHECK" != "OK" ]; then | |
| cd $STEAMCMD; ./steamcmd.sh +login anonymous +force_install_dir $DIRFILES +app_update $SERVERAPPID +quit | |
| fi | |
| if [ -z "$CHECK" ] && [ -L $APPDIR/current ]; then | |
| if [ -n "$(diff -qr $DIRFILES/ $APPDIR/current/)" ]; then | |
| # Create snapshot versions | |
| csnapshot | |
| fi | |
| else | |
| # Create snapshot versions | |
| csnapshot | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment