You are not logged in.

Dear visitor, welcome to sourceserver.info. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

  • DeaD_EyE

    Administrator

    You have to register first, to connect to this user.

13

ESL-Config Downloader

Rating:

by DeaD_EyE, Tuesday, March 8th 2011, 8:10pm

Ich hab mal ein kleines Python-Script geschrieben, welches die ESL-Configs nur herunterlädt, wenn diese auf dem ESL-Server neuer sind, als die gespeicherten. Das Script lädt die cssconfig.zip in dem Verzeichnis herunter, in dem sich auch das Script befindet. Nach dem Download wird das Zip-Archiv entpackt und ein Shell-Script ausgeführt, dass sich im gleichen Verzeichnis befindet.


Hier der Code:

configdownloader.py

PHP Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/python
import urllibzipfileossysshlexsubprocess

cssconfigurl 'http://gfx.esl.eu/gfx/media/de/css/cfg/cssconfig.zip'
timestampfile 'cssconfig.zip.txt'
programm_after_download './config_update.sh'

os.chdir(os.path.split(os.path.abspath(sys.argv[0]))[0])

def getfile_extract(url):
    file url.split('/')[-1]
    urllib.urlretrieve(urlfile)
    file_zip zipfile.ZipFile(file)
    file_zip.extractall()
    file_zip.close()

def gettimestamp_server(file):
    timestamp_fp open(file,'r')
    configdate_server timestamp_fp.read()
    timestamp_fp.close()
    return configdate_server

def settimestamp_server(file,timestamp):
    timestamp_fp open(file,'w')
    timestamp_fp.write(timestamp)
    timestamp_fp.close()
    return

def programm_start(programm):
    start subprocess.Popen(shlex.split(programm), shell=False)
    return

configdate_esl str(urllib.urlopen(cssconfigurl).headers.getdate('Last-Modified'))
configdate_server None

if os.path.isfile(timestampfile):
    configdate_server gettimestamp_server(timestampfile)
    if not configdate_server == configdate_esl:
        getfile_extract(cssconfigurl)
        settimestamp_server(timestampfile,configdate_esl)
        programm_start(programm_after_download)
else:
    getfile_extract(cssconfigurl)
    settimestamp_server(timestampfile,configdate_esl)
    programm_start(programm_after_download)


Nach erfolgtem Update wird ein Shellscript ausgeführt. Als Beispiel habe ich mal eins erstellt, dass './config_update.sh' heißt.

config_update.sh

PHP Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/bin/bash
serverbasepath="/home/server/"
#Basisverzeichnis der Server
servers="testserver"
#Serververzeichnisse Mit einem Leerzeichen trennen
addpath="orangebox/cstrike/cfg"
#so belassen, wenn es Configs für CS:S sind
configdir="server"
#so belassen, wenn es cssconfigs.zip ist

if [ ! -"$configdir]; then exit; fi

for server in $servers; do
        if [ ! -"$serverbasepath/$server/$addpath/" ]; then continue; fi
        cp -u $configdir/* $serverbasepath/$server/$addpath/
done

Das Script aktualisiert alle eingetragenen Server. Ihr könnt dies auch nach belieben anpassen. Manche stehen eher auf die konventionelle Weise und tragen alle Server einzeln ein:

PHP Source code

1
2
3
4
#!/bin/bash
cp -u server/* /home/server/warserver1/orangebox/cstrike/cfg/
cp -u server/* /home/server/warserver2/orangebox/cstrike/cfg/
cp -u server/* /home/server/warserver2/orangebox/cstrike/cfg/


Was noch eingebaut wird:
  • Programmabbruch, wenn der Server nicht erreichbar ist.

This article has been read 64,650 times.

Tags: Configs, Downloader, ESL

Categories: SRCDS


Comments (11)

Blog navigation

Next article

Backupscript für Webserver und MySQL

by DeaD_EyE (Monday, March 21st 2011, 11:05pm)

Previous article

Waffen der Spieler entfernen...

by DeaD_EyE (Friday, February 25th 2011, 1:38pm)