first re-impl of python, still linux dependent because of rsync

This commit is contained in:
Mathew Guest 2020-03-01 21:36:06 -07:00
parent a81e2d4c46
commit 01c87f40af
3 changed files with 101 additions and 19 deletions

@ -1,9 +1,10 @@
import hashlib import hashlib
import functools
def md5sum_file(filename): def md5sum_file(filename):
with open(filename, mode='rb') as f: with open(filename, mode='rb') as f:
d = hashlib.md5() d = hashlib.md5()
for buf in iter(partial(f.read, 128), b''): for buf in iter(functools.partial(f.read, 128), b''):
d.update(buf) d.update(buf)
h = d.hexdigest() h = d.hexdigest()
return h return h

@ -17,7 +17,7 @@
remote_game_host = string(max=255, default='') remote_game_host = string(max=255, default='')
remote_game_directory = string(max=255, default='') remote_game_dir = string(max=255, default='')
remote_redirect_host = string(max=255, default='') remote_redirect_host = string(max=255, default='')

@ -1,14 +1,11 @@
from .config_editor import UnrealIniFile, GameIniSpecial from .config_editor import UnrealIniFile, GameIniSpecial
from . import config_editor from ._util import md5sum_file
from . import _util
from app_skellington import _util from app_skellington import _util
from functools import partial
import collections import collections
import configobj import configobj
import configparser import configparser
import glob import glob
import hashlib
import os import os
import pathlib import pathlib
import subprocess import subprocess
@ -168,7 +165,71 @@ ssh {remote_game_host} {remote_game_dir}/stop-server.sh
Upload paks to redirect server. Upload paks to redirect server.
""" """
self.ctx.log['ut4'].info('Uploading redirects (maps, mutators, etc.) to target hub.') self.ctx.log['ut4'].info('Uploading redirects (maps, mutators, etc.) to target hub.')
pass
project_dir = self.ctx.config['app']['project_dir']
# paks_dir = os.path.join(project_dir, 'instance/LinuxServer/UnrealTournament/Content/Paks/')
paks_dir = os.path.join(project_dir, 'files/') # trailing slash required
remote_redirect_host = self.ctx.config['app']['remote_redirect_host']
cwd = project_dir
cmd = '''
rsync -rvz \
--delete \
--exclude "*.md5" \
--exclude 'unused' \
--exclude ".KEEP" \
--exclude Mods.db \
{paks_dir} {remote_redirect_host}
'''\
.format(**{
'paks_dir': paks_dir,
'remote_redirect_host': remote_redirect_host,
})
# subprocess.run(cmd, cwd=cwd) # should be invoke_command? no because gui will need subprocess.run
self._invoke_command(cmd)
self._redirect_hide_passwords()
self._redirect_upload_script()
self._redirect_chown()
def _redirect_hide_passwords(self):
project_dir = self.ctx.config['app']['project_dir']
remote_redirect_host = self.ctx.config['app']['remote_redirect_host']
# (on the server):
gameini="/srv/ut4-redirect.zavage.net/config/Game.ini"
engineini="/srv/ut4-redirect.zavage.net/config/Engine.ini"
cmd = '''
ssh mathewguest.com sed -i /ServerInstanceID=/c\ServerInstanceID=Hidden {gameini}
'''.format(gameini=gameini)
self._invoke_command(cmd)
cmd = '''
ssh mathewguest.com sed -i /RconPassword=/c\RconPassword=Hidden {engineini}
'''.format(engineini=engineini)
self._invoke_command(cmd)
def _redirect_upload_script(self):
project_dir = self.ctx.config['app']['project_dir']
remote_redirect_host = self.ctx.config['app']['remote_redirect_host']
cmd = '''
rsync -vz {project_dir}/ut4-server-ctl.sh {remote_redirect_host}
'''\
.format(**{
'project_dir': project_dir,
'remote_redirect_host': remote_redirect_host,
})
# subprocess.run(cmd, cwd=cwd) # should be invoke_command? no because gui will need subprocess.run
self._invoke_command(cmd)
def _redirect_chown(self):
project_dir = self.ctx.config['app']['project_dir']
remote_redirect_host = self.ctx.config['app']['remote_redirect_host']
cmd = '''
ssh mathewguest.com 'chown http.http /srv/ut4-redirect.zavage.net -R'
'''
self._invoke_command(cmd)
def upload_server(self): def upload_server(self):
""" """
@ -193,32 +254,52 @@ rsync -ravzp \
--exclude "Saved/Crashes/*" \ --exclude "Saved/Crashes/*" \
--exclude "Saved/Logs/*" \ --exclude "Saved/Logs/*" \
{project_dir}/instance/ \ {project_dir}/instance/ \
{remote_game_host}:{remote_game_dir}" {remote_game_host}:{remote_game_dir}
'''\ '''\
.format(**{ .format(**{
'project_dir': project_dir, 'project_dir': project_dir,
'remote_game_host': remote_game_host, 'remote_game_host': remote_game_host,
'remote_game_dir': remote_game_dir 'remote_game_dir': remote_game_dir
}) })
subprocess.run(cmd, cwd=cwd) # should be invoke_command? cmd = cmd.replace(' ', '')
# subprocess.run(cmd, cwd=cwd) # should be invoke_command? no because gui will need subprocess.run
self._invoke_command(cmd)
# transfer #2 # transfer #2
cmd = ''' cmd = '''
rsync -avzp {project_dir}/ut4-server-ctl.sh {remote_game_host}:{remote_game_dir} rsync -avzp {project_dir}/ut4-server-ctl.sh {remote_game_host}:{remote_game_dir}
''' '''\
subprocess.run(cmd, cwd=cwd) .format(**{
'project_dir': project_dir,
'remote_game_host': remote_game_host,
'remote_game_dir': remote_game_dir
})
# subprocess.run(cmd, cwd=cwd)
self._invoke_command(cmd)
# transfer #3 # transfer #3
cmd = ''' cmd = '''
scp {project_dir}/instance/ut4-server.service {remote_game_host}:/etc/systemd/system/ scp {project_dir}/instance/ut4-server.service {remote_game_host}:/etc/systemd/system/
''' '''\
subprocess.run(cmd, cwd=cwd) .format(**{
'project_dir': project_dir,
'remote_game_host': remote_game_host,
'remote_game_dir': remote_game_dir
})
# subprocess.run(cmd, cwd=cwd)
self._invoke_command(cmd)
# transfer #4 # transfer #4
cmd = ''' cmd = '''
ssh {remote_game_host} chown ut4.ut4 {remote_game_dir} -R ssh {remote_game_host} chown ut4.ut4 {remote_game_dir} -R
''' '''.format(**{
subprocess.run(cmd, cwd=cwd) 'remote_game_host': remote_game_host,
'remote_game_dir': remote_game_dir
})
# subprocess.run(cmd, cwd=cwd)
self._invoke_command(cmd)
def _first_run(self): def _first_run(self):
self.ctx.log['ut4'].info('Starting instance once to get UID.') self.ctx.log['ut4'].info('Starting instance once to get UID.')
@ -280,14 +361,14 @@ ssh {remote_game_host} chown ut4.ut4 {remote_game_dir} -R
self.ctx.log['ut4'].info('Installing maps...') self.ctx.log['ut4'].info('Installing maps...')
cmd = 'rsync -ravzp {src} {dst}'.format(**{ cmd = 'rsync -ravzp {src} {dst}'.format(**{
'src': '/'.join([project_dir, 'files/maps']), 'src': '/'.join([project_dir, 'files/maps/']),
'dst': '/'.join([project_dir, 'instance/LinuxServer/UnrealTournament/Content/Paks/']) 'dst': '/'.join([project_dir, 'instance/LinuxServer/UnrealTournament/Content/Paks/'])
}) })
self._invoke_command(cmd) self._invoke_command(cmd)
self.ctx.log['ut4'].info('Installing mutators...') self.ctx.log['ut4'].info('Installing mutators...')
cmd = 'rsync -ravzp {src} {dst}'.format(**{ cmd = 'rsync -ravzp {src} {dst}'.format(**{
'src': '/'.join([project_dir, 'files/mutators']), 'src': '/'.join([project_dir, 'files/mutators/']),
'dst': '/'.join([project_dir, 'instance/LinuxServer/UnrealTournament/Content/Paks/']) 'dst': '/'.join([project_dir, 'instance/LinuxServer/UnrealTournament/Content/Paks/'])
}) })
self._invoke_command(cmd) self._invoke_command(cmd)
@ -309,7 +390,7 @@ ssh {remote_game_host} chown ut4.ut4 {remote_game_dir} -R
for idx, filename in enumerate(files): for idx, filename in enumerate(files):
# if idx > 5: # if idx > 5:
# break # break
md5sum = _util.md5sum_file(filename) md5sum = md5sum_file(filename)
p = pathlib.Path(filename) p = pathlib.Path(filename)
relative_path = p.relative_to(mod_dir) relative_path = p.relative_to(mod_dir)
pkg_basename = p.name pkg_basename = p.name
@ -380,7 +461,7 @@ ssh {remote_game_host} chown ut4.ut4 {remote_game_dir} -R
'redirect_protocol', 'redirect_protocol',
'redirect_url', 'redirect_url',
'remote_game_host', 'remote_game_host',
'remote_game_directory', 'remote_game_dir',
'remote_redirect_host' 'remote_redirect_host'
) )
for name in variable_names: for name in variable_names: