diff --git a/bundles/l4d2/README.md b/bundles/l4d2/README.md new file mode 100644 index 0000000..21f02fe --- /dev/null +++ b/bundles/l4d2/README.md @@ -0,0 +1 @@ +https://developer.valvesoftware.com/wiki/List_of_L4D2_Cvars diff --git a/bundles/l4d2/items.py b/bundles/l4d2/items.py new file mode 100644 index 0000000..46b11d8 --- /dev/null +++ b/bundles/l4d2/items.py @@ -0,0 +1,21 @@ +directories = { + '/etc/left4dead2': { + 'owner': 'steam', + 'purge': True, + } +} + +for name, config in node.metadata.get('left4dead2').items(): + config.pop('port') + config['hostname'] = name + + files[f'/etc/left4dead2/{name}.cfg'] = { + 'content': '\n'.join( + f'{key} "{value}"' for key, value in config.items() + ), + 'owner': 'steam', + 'triggers': [ + f'svc_systemd:left4dead2-server-{name}:restart', + ], + } + svc_systemd[f'left4dead2-server-{name}'] = {} diff --git a/bundles/l4d2/metadata.py b/bundles/l4d2/metadata.py index c3b4514..b9d74fa 100644 --- a/bundles/l4d2/metadata.py +++ b/bundles/l4d2/metadata.py @@ -1,7 +1,41 @@ -@metadata_reactor.provides() +defaults = { + 'steam': { + 'games': { + 'left4dead2': '222860', + }, + }, + 'servers': {}, +} + + +@metadata_reactor.provides( + 'systemd/units', +) def steam(metadata): + units = {} + services = {} + + for name, config in metadata.get('left4dead2').items(): + units[f'left4dead2-server-{name}.service'] = { + 'Unit': { + 'Description': 'steam: install and update games', + 'After': 'network.target', + 'Requires': 'steam-update.service', + }, + 'Service': { + 'User': 'steam', + 'Group': 'steam', + 'WorkingDirectory': '/opt/left4dead2', + 'ExecStart': f'/opt/left4dead2/srcds_run -port {config["port"]} -secure +exec /etc/left4dead2/{name}.cfg', + 'Restart': 'on-failure', + }, + 'Install': { + 'WantedBy': ['multi-user.target'], + }, + } + return { - 'steam': { - '222860': 'l4d2', + 'systemd': { + 'units': units, }, } diff --git a/bundles/steam/files/steam-update.service b/bundles/steam/files/steam-update.service index a91acd8..b2d975d 100644 --- a/bundles/steam/files/steam-update.service +++ b/bundles/steam/files/steam-update.service @@ -1,4 +1,3 @@ -GNU nano 4.8 /etc/systemd/system/l4d2-update.service [Unit] Description=l4d2 update After=network.target diff --git a/bundles/steam/items.py b/bundles/steam/items.py index 83a52e7..cb5bdd2 100644 --- a/bundles/steam/items.py +++ b/bundles/steam/items.py @@ -1,4 +1,41 @@ -for id, name in node.metadata.get('steam'): - pass +users = { + 'steam': { + 'home': '/opt/steam', + }, +} + +directories = { + '/opt/steam': { + 'owner': 'steam', + 'group': 'steam', + }, +} + +files = { + '/opt/steam/steamcmd_linux.tar.gz': { + 'content_type': 'download', + 'source': 'https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz', + 'owner': 'steam', + 'group': 'steam', + }, +} + +actions = { + 'extract_steamcmd': { + 'command': 'tar xfvz /opt/steam/steamcmd_linux.tar.gz --directory /opt/steam', + 'unless': 'test -f /opt/steam/steamcmd.sh', + 'needs': [ + 'file:/opt/steam/steamcmd_linux.tar.gz', + ], + }, + 'chown_steamcmd': { + 'command': 'chown -R steam:steam /opt/steam', + 'triggered': True, + 'triggered_by': [ + 'action:extract_steamcmd', + ], + }, +} # sudo -Hiu steam bash -c '~/steam/steamcmd.sh +login anonymous +force_install_dir ./l4d2/ +app_update 222860 validate +quit' +# https://github.com/SegoCode/swd/releases/download/1.1/swd-linux-amd64 diff --git a/bundles/steam/metadata.py b/bundles/steam/metadata.py new file mode 100644 index 0000000..6241ed3 --- /dev/null +++ b/bundles/steam/metadata.py @@ -0,0 +1,42 @@ +defaults = { + 'apt': { + 'packages': { + 'lib32gcc-s1': {}, + }, + }, + 'steam': { + 'games': {}, + } +} + +@metadata_reactor.provides( + 'systemd/units', +) +def initial_unit(metadata): + install_games = ' '.join( + f'+force_install_dir /opt/{name} +app_update {id}' + for name, id in metadata.get('steam/games').items() + ) + + return { + 'systemd': { + 'units': { + 'steam-update.service': { + 'Unit': { + 'Description': 'steam: install and update games', + 'After': 'network.target', + }, + 'Service': { + 'Type': 'oneshot', + 'User': 'steam', + 'Group': 'steam', + 'WorkingDirectory': '/opt/steam', + 'ExecStart': f'/opt/steam/steamcmd.sh +login anonymous {install_games} validate +quit', + }, + 'Install': { + 'WantedBy': 'multi-user.target', + }, + }, + }, + }, + } diff --git a/bundles/systemd/metadata.py b/bundles/systemd/metadata.py index d358342..c9f7225 100644 --- a/bundles/systemd/metadata.py +++ b/bundles/systemd/metadata.py @@ -48,7 +48,7 @@ def services(metadata): extension = name.split('.')[-1] if extension not in ['timer', 'service']: - raise Exception(f'unknown extension {extension}') + raise Exception(f'unknown extension: {extension}') return { 'systemd': { diff --git a/groups/os/debian.py b/groups/os/debian.py index cb44d5d..4144520 100644 --- a/groups/os/debian.py +++ b/groups/os/debian.py @@ -8,7 +8,7 @@ 'metadata': { 'apt': { 'sources': { - 'deb http://deb.debian.org/debian {release} main non-free contrib', + 'deb http://deb.debian.org/debian {release} main contrib non-free', 'deb http://deb.debian.org/debian {release}-updates main contrib non-free', 'deb http://deb.debian.org/debian {release}-backports main contrib non-free', }, diff --git a/nodes/htz.games-2.py b/nodes/htz.games-2.py new file mode 100644 index 0000000..fe0e2d7 --- /dev/null +++ b/nodes/htz.games-2.py @@ -0,0 +1,35 @@ +{ + 'hostname': '23.88.121.141', + 'groups': [ + 'backup', + 'debian-11', + 'hetzner-cloud', + ], + 'bundles': [ + 'steam', + 'l4d2', +# 'java', +# 'minecraft', + ], + 'metadata': { + 'id': '3915f236-dd0a-4c6c-8fb3-1584c81038c6', + 'left4dead2': { + 'realism-expert': { + 'port': 27001, + } + }, + 'network': { + 'internal': { + 'interface': 'ens10', + 'ipv4': '10.0.10.4/32', + }, + 'external': { + 'interface': 'eth0', + 'ipv4': '23.88.121.141/32', + 'ipv6': '2a01:4f8:c17:e0b4::2/64', + 'gateway4': '172.31.1.1', + 'gateway6': 'fe80::1', + } + }, + }, +} diff --git a/nodes/htz.games.py b/nodes/htz.games.py index 66eb3e0..827edc9 100644 --- a/nodes/htz.games.py +++ b/nodes/htz.games.py @@ -9,7 +9,7 @@ # 'steam', # 'l4d2', 'java', - 'minecraft', +# 'minecraft', ], 'metadata': { # TEMP