From fb1c7a2bccf181bb4c460765ee8fc15ec562fb07 Mon Sep 17 00:00:00 2001 From: mwiegand Date: Thu, 1 Jul 2021 00:11:40 +0200 Subject: [PATCH] wip --- bundles/nextcloud/items.py | 46 +++++++++++++++++++++----------------- items/download.py | 19 +++++++--------- nodes/htz.mails.py | 3 ++- 3 files changed, 35 insertions(+), 33 deletions(-) diff --git a/bundles/nextcloud/items.py b/bundles/nextcloud/items.py index 3b8f4a2..bed230a 100644 --- a/bundles/nextcloud/items.py +++ b/bundles/nextcloud/items.py @@ -4,6 +4,7 @@ from shlex import quote from os.path import join from mako.template import Template +version = node.metadata.get('nextcloud/version') directories = { '/opt/nextcloud': {}, @@ -26,21 +27,25 @@ directories = { }, } -git_deploy = { - '/opt/nextcloud': { - 'repo': 'git://github.com/nextcloud/server.git', - 'rev': f"v{node.metadata.get('nextcloud/version')}", - 'needs': { - 'directory:/opt/nextcloud', - }, - }, - '/opt/nextcloud/3rdparty': { - 'repo': 'git://github.com/nextcloud/3rdparty.git', - 'rev': f"v{node.metadata.get('nextcloud/version')}", - 'needs': { - 'git_deploy:/opt/nextcloud', - }, - }, +downloads[f'/tmp/nextcloud-{version}.tar.bz2'] = { + 'url': f'https://download.nextcloud.com/server/releases/nextcloud-{version}.tar.bz2', + 'sha256_url': f'https://download.nextcloud.com/server/releases/nextcloud-{version}.tar.bz2.sha256', + 'triggered': True, +} +actions['delete_nextcloud'] = { + 'command': 'rm -rf /opt/nextcloud/{.*,*}', + 'triggered': True, +} +actions['extract_nextcloud'] = { + 'command': f'tar xfvj /tmp/nextcloud-{version}.tar.bz2 --skip-old-files --strip 1 -C /opt/nextcloud nextcloud', + 'unless': f"""php -r 'include "/opt/nextcloud/version.php"; echo "$OC_VersionString";' | grep -q '^{version}$'""", + 'preceded_by': [ + 'action:delete_nextcloud', + f'download:/tmp/nextcloud-{version}.tar.bz2', + ], + 'needs': [ + 'directory:/opt/nextcloud', + ], } symlinks = { @@ -49,7 +54,7 @@ symlinks = { 'owner': 'www-data', 'group': 'www-data', 'needs': [ - 'git_deploy:/opt/nextcloud', + 'action:extract_nextcloud', ], }, '/opt/nextcloud/userapps': { @@ -57,7 +62,7 @@ symlinks = { 'owner': 'www-data', 'group': 'www-data', 'needs': [ - 'git_deploy:/opt/nextcloud', + 'action:extract_nextcloud', ], }, } @@ -65,7 +70,7 @@ symlinks = { files = { # '/opt/nextcloud/core/shipped.json': { # 'needs': [ - # 'git_deploy:/opt/nextcloud', + # 'action:extract_nextcloud', # ], # }, '/etc/nextcloud/CAN_INSTALL': { @@ -115,8 +120,7 @@ actions['install_nextcloud'] = { 'directory:/var/lib/nextcloud/.cache', 'symlink:/opt/nextcloud/config', 'symlink:/opt/nextcloud/userapps', - 'git_deploy:/opt/nextcloud', - 'git_deploy:/opt/nextcloud/3rdparty', + 'action:extract_nextcloud', 'file:/etc/nextcloud/CAN_INSTALL', 'file:/etc/nextcloud/managed.config.php', 'postgres_db:nextcloud', @@ -140,6 +144,6 @@ actions['nextcloud_add_missing_inidces'] = { ], 'triggered': True, 'triggered_by': [ - f'git_deploy:/opt/nextcloud', + f'action:extract_nextcloud', ], } diff --git a/items/download.py b/items/download.py index c5eb3d5..80066eb 100644 --- a/items/download.py +++ b/items/download.py @@ -22,6 +22,7 @@ class Download(Item): ITEM_ATTRIBUTES = { 'url': "", 'sha256': "", + 'sha256_url': "", 'verifySSL': True, 'decompress': None, } @@ -62,15 +63,6 @@ class Download(Item): url=quote(self.attributes['url']) )) - # check hash - sha256 = self.__hash_remote_file(self.name) - - if sha256 != self.attributes['sha256']: - # unlink file - self.node.run("rm -rf -- {}".format(quote(self.name))) - - return False - def cdict(self): """This is how the world should be""" cdict = { @@ -88,14 +80,19 @@ class Download(Item): else: sdict = { 'type': 'download', - 'sha256': self.__hash_remote_file(self.name) } + if 'sha256' in self.attributes: + sdict['sha256'] = self.attributes['sha256'] + elif 'sha256_url' in self.attributes: + sdict['sha256'] = force_text( + self.node.run(f"curl -L -s -- {quote(self.attributes['sha256_url'])}").stdout + ).strip().split()[0] return sdict @classmethod def validate_attributes(cls, bundle, item_id, attributes): - if 'sha256' not in attributes: + if 'sha256' not in attributes and 'sha256_url' not in attributes: raise BundleError(_( "at least one hash must be set on {item} in bundle '{bundle}'" ).format( diff --git a/nodes/htz.mails.py b/nodes/htz.mails.py index d650105..4240627 100644 --- a/nodes/htz.mails.py +++ b/nodes/htz.mails.py @@ -18,7 +18,8 @@ 'metadata': { 'nextcloud': { 'domain': 'cloud.sublimity.de', - 'version': '20.0.10', + 'version': '20.0.5', + 'sha256': '5e5b38109a3485db5fd2d248f24478eabe6c0790ec10b030acbbee207d5511fe', }, 'id': 'ea29bdf0-0b47-4bf4-8346-67d60c9dc4ae', 'bind': {