<commit_before>#!/bin/bash
# -----------------------------------------------------------------------------
# Script for Updating the dedicated Server of Rust within a docker-Container
#
# Authors: <NAME>, <NAME>
# Updated: Jun 25th, 2015
# -----------------------------------------------------------------------------

# Configuration of the Variables---------------------------------------------------

# Path from rust server
LOGPATH="/var/rust/rustserver"
OLDLOG="/var/rust/rustserver/old_logs"
# Path from the Dockerfile of rust
DOCKFILEPATH="/var/docker/image_src/rust"
# systemctl name
SYSCTL=docker-rust
# Name of docker-Image
NIMG="bechof/rust"
NCON="rust"
# Hostname of the rust Server
HOST=FQDN
# Port from rcon
PORT=28016
# Password for rcon
PASSWORD=Password
# Message for the Players that are currently logged in
MESSAGE1="wird in 5 Minuten neugestartet, da es ein Update gibt. Nach einer kurzen Verzoegerung kann es hier weitergehen!"
MESSAGE2="wird jetzt neugestartet, da es ein Update gibt. Nach einer kurzen Verzoegerung kann es hier weitergehen!"
# Maximum age of the Log-Files in days
MAXAGE=60
DAT=`date +%Y%m%d_%H%M`
# Protocol for sending chat message to Rust by RCON
RCON_PROT='\x11\x00\x00\x00\x01\x00\x00\x00\x03\x00\x00\x00%s\x00\x00\n\x13\x00\x00\x00\x8b\x30\x00\x00\x02\x00\x00\x00\x73\x61\x79\x20%s \x00\x00'
# -----------------------------------------------------------------------------

NV=`egrep "New version" $LOGPATH/Log.Log.txt | wc -l`

if [ $NV -ge 1 ]
    then echo "Update available"
else 
    exit
fi

systemctl status $SYSCTL > /dev/null
P1=$?

if [ $P1 != 0 ]
    then echo "Rust is not running"
else 
     CP=`echo -e "\0\0\0\0TSource Engine Query\0" | nc -u -q 1 $HOST $PORT | tr '[\000-\011\013-\037\177-\377]' '.' | sed 's/\(.*\)\(@.mp\)\([0-9]*\)\(,cp\)\([0-9]*\)\(,\)\(.*\)/\5/'`
    if [ $CP -ge 1 ]
        then
            printf "$RCON_PROT" "$PASSWORD" "$MESSAGE1" | nc -i 1 -q 1 $HOST $PORT
            sleep 10
            printf "$RCON_PROT" "$PASSWORD" "$MESSAGE2" | nc -i 1 -q 1 $HOST $PORT
            sleep 10
    else
        echo "No Player connected"
    fi             
    systemctl stop $SYSCTL
fi

docker rm $NCON
docker rmi $NIMG
cd $DOCKFILEPATH
docker build -t $NIMG .

# tidy up

if [ ! -d $OLDLOG ]
   then mkdir $OLDLOG
        chmod 755 $OLDLOG
fi

cd $LOGPATH
LOGS=`find . -maxdepth 1 -type f -iname "*.txt" | cut -d "/" -f 2 | sed -r 's/([^\.]*)\.txt.*/\1/'`

for i in $LOGS
    do mv $i".txt" $i"_"$DAT".txt"
       mv $i"_"$DAT".txt" $OLDLOG/
done
<commit_msg>now with better check of new version<commit_after>#!/bin/bash
# -----------------------------------------------------------------------------
# Script for Updating the dedicated Server of Rust within a docker-Container
#
# Authors: <NAME>, <NAME>
# Updated: Jun 25th, 2015
# -----------------------------------------------------------------------------

# Configuration of the Variables---------------------------------------------------

# Path from rust server
LOGPATH="/var/rust/rustserver"
OLDLOG="/var/rust/rustserver/old_logs"
# Path from the Dockerfile of rust
DOCKFILEPATH="/var/docker/image_src/rust"
# systemctl name
SYSCTL=docker-rust
# Name of docker-Image
NIMG="bechof/rust"
NCON="rust"
# Hostname of the rust Server
HOST=FQDNorIP
# Port from rcon
PORT=28016
# Password for rcon
PASSWORD=Password
# Message for the Players that are currently logged in
MESSAGE1="wird in 5 Minuten neugestartet, da es ein Update gibt. Nach einer kurzen Verzoegerung kann es hier weitergehen!"
MESSAGE2="wird jetzt neugestartet, da es ein Update gibt. Nach einer kurzen Verzoegerung kann es hier weitergehen!"
# Maximum age of the Log-Files in days
MAXAGE=60
DAT=`date +%Y%m%d_%H%M`
# Protocol for sending chat message to Rust by RCON
RCON_PROT='\x11\x00\x00\x00\x01\x00\x00\x00\x03\x00\x00\x00%s\x00\x00\n\x13\x00\x00\x00\x8b\x30\x00\x00\x02\x00\x00\x00\x73\x61\x79\x20%s \x00\x00'
# -----------------------------------------------------------------------------

NV=`echo -e "\0\0\0\0TSource Engine Query\0" | nc -u -q 1 192.168.127.12 28016 | tr '[\000-\011\013-\037\177-\377]' '.' | sed 's/\(.*\)\(,cp\)\([0-9]*\)\(,v\)\([0-9]*\)\(.*\)/\5/'`
CV=`echo -e "\0\0\0\0TSource Engine Query\0" | nc -u -q 1 bechof.de 28016 | tr '[\000-\011\013-\037\177-\377]' '.' | sed 's/\(.*\)\(,cp\)\([0-9]*\)\(,v\)\([0-9]*\)\(.*\)/\5/'`

if [ $NV -gt $CV ]
    then echo "Update available"
    else exit
fi

systemctl status $SYSCTL > /dev/null
P1=$?

if [ $P1 != 0 ]
    then echo "Rust is not running"
else 
     CP=`echo -e "\0\0\0\0TSource Engine Query\0" | nc -u -q 1 $HOST $PORT | tr '[\000-\011\013-\037\177-\377]' '.' | sed 's/\(.*\)\(@.mp\)\([0-9]*\)\(,cp\)\([0-9]*\)\(,\)\(.*\)/\5/'`
    if [ $CP -ge 1 ]
        then
            printf "$RCON_PROT" "$PASSWORD" "$MESSAGE1" | nc -i 1 -q 1 $HOST $PORT
            sleep 5m
            printf "$RCON_PROT" "$PASSWORD" "$MESSAGE2" | nc -i 1 -q 1 $HOST $PORT
            sleep 20
    else
        echo "No Player connected"
    fi             
    systemctl stop $SYSCTL
fi

docker rm $NCON
docker rmi $NIMG
cd $DOCKFILEPATH
docker build -t $NIMG .

# tidy up

if [ ! -d $OLDLOG ]
   then mkdir $OLDLOG
        chmod 755 $OLDLOG
fi

cd $LOGPATH
LOGS=`find . -maxdepth 1 -type f -iname "*.txt" | cut -d "/" -f 2 | sed -r 's/([^\.]*)\.txt.*/\1/'`

for i in $LOGS
    do mv $i".txt" $i"_"$DAT".txt"
       mv $i"_"$DAT".txt" $OLDLOG/
done

{'fraction_non_alphanumeric': 0.2610464041412461, 'fraction_numerical': 0.0619338140136809, 'mean_word_length': 1.9354313619099295, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6502355', 'n_tokens_mistral': 2214, 'n_tokens_neox': 1982, 'n_words': 554}