This commit is contained in:
Marc Beninca 2022-05-01 22:58:23 +02:00
parent a0b41d168a
commit e73fac2d0a
2 changed files with 111 additions and 0 deletions

47
pubnix.py Normal file
View file

@ -0,0 +1,47 @@
import os
import subprocess
PORT = 22
USER = 'mspe'
ROOT = 'public_html'
PROTOCOL = 'https'
DIR = False
class PubNix:
def __init__(self, dn,
ssh=None, port=PORT, user=USER,
root=ROOT, dir=DIR, web=None, sub=None):
self.dn = dn
self.ssh = f'{ssh}.{self.dn}' if ssh else self.dn
self.port = port
self.user = user
self.root = root
self.web = f'{web}.{self.dn}' if web else self.dn
if sub:
self.fqdn = f'{self.user}.{self.web}'
self.context = None
else:
self.fqdn = self.web
self.context = f'~{self.user}'
self.path = os.path.join(self.root, self.fqdn) if dir else self.root
self.target = f'{self.user}@{self.ssh}:{self.path}'
self.url = [f'{PROTOCOL}:', str(), self.fqdn]
if self.context:
self.url.append(self.context)
self.url = '/'.join(self.url)
def run(self, *args):
subprocess.call(['ssh',
'-o', 'LogLevel Error',
'-p', str(self.port),
f'{self.user}@{self.ssh}',
'--',
*args])
def disk_free(self):
self.run('df', '-h', os.curdir)
def __str__(self):
return os.linesep.join([self.target, self.url])

64
sync.py Executable file
View file

@ -0,0 +1,64 @@
#! /usr/bin/env python3
import os
import subprocess
import pubnix
ARGS = [
{'dn':'aussies.space', 'sub': False},
{'dn':'blinkenshell.org',
'ssh': 'ssh', 'port': 2222, 'web': 'u', 'sub': True},
{'dn':'ctrl-c.club', 'sub': False},
{'dn':'dimension.sh', 'sub': True},
{'dn':'envs.net', 'sub': True},
{'dn':'fr.tild3.org', 'sub': True},
{'dn':'heathens.club', 'root': 'www', 'sub': False},
{'dn':'insomnia247.nl', 'dir': True, 'sub': True},
{'dn':'remotes.club', 'port': 9022, 'root': 'web', 'sub': True},
{'dn':'rw.rs', 'sub': False},
{'dn':'squiggle.city', 'sub': False},
{'dn':'thunix.net', 'sub': False},
{'dn':'tilde.cafe', 'sub': True},
{'dn':'tilde.club', 'sub': False},
{'dn':'tilde.fun', 'root': 'html', 'sub': False},
{'dn':'tilde.guru', 'sub': False},
{'dn':'tilde.institute', 'sub': True},
{'dn':'tilde.pink', 'sub': False},
{'dn':'tilde.team', 'sub': True},
{'dn':'tilde.town', 'sub': False},
{'dn':'sdf.org', 'root': 'html', 'sub': True},
{'dn':'southlondon.cc', 'sub': False},
]
PUBNIXES = [pubnix.PubNix(**args) for args in ARGS]
def sync(root, pubnix, exclude=None):
args = [
'rsync',
'--archive',
'--checksum',
'--delete-before',
'--rsh', f"ssh -o 'LogLevel Error' -p {pubnix.port}",
'--partial',
'--progress',
'--verbose',
os.path.join(root, str()),
]
for item in exclude:
args.extend(['--exclude', os.path.join(str(), item)])
args.append(os.path.join(pubnix.target, str()))
subprocess.call(args, stdout=subprocess.DEVNULL)
def main():
root = os.path.dirname(os.path.realpath(__file__))
for pubnix in PUBNIXES:
print()
print(pubnix)
sync(root, pubnix, exclude=['__pycache__', 'cnam', 'pgp.asc'])
# pubnix.disk_free()
if __name__ == '__main__':
main()