bundles/gitea: switch to new file type 'download'

This commit is contained in:
Franzi 2021-09-17 13:07:04 +02:00
parent fbb13e4c2f
commit b21f7c856a
Signed by: kunsi
GPG key ID: 12E3D2136B818350
3 changed files with 15 additions and 147 deletions

View file

@ -1,16 +1,3 @@
downloads = {
'/usr/local/bin/gitea': {
'url': 'https://dl.gitea.io/gitea/{version}/gitea-{version}-linux-amd64'.format(version=node.metadata['gitea']['version']),
'sha256': node.metadata['gitea']['sha256'],
'triggers': {
'svc_systemd:gitea:restart',
},
'preceded_by': {
'svc_systemd:gitea:stop',
},
},
}
users = { users = {
'git': {}, 'git': {},
} }
@ -35,16 +22,6 @@ directories = {
}, },
} }
actions = {
'chmod_gitea': {
'command': 'chmod a+x /usr/local/bin/gitea',
'unless': 'test -x /usr/local/bin/gitea',
'needs': {
'download:/usr/local/bin/gitea',
},
},
}
files = { files = {
'/etc/systemd/system/gitea.service': { '/etc/systemd/system/gitea.service': {
'content_type': 'mako', 'content_type': 'mako',
@ -61,6 +38,18 @@ files = {
'svc_systemd:gitea:restart', 'svc_systemd:gitea:restart',
}, },
}, },
'/usr/local/bin/gitea': {
'content_type': 'download',
'source': 'https://dl.gitea.io/gitea/{version}/gitea-{version}-linux-amd64'.format(version=node.metadata['gitea']['version']),
'content_hash': node.metadata['gitea']['sha1'],
'mode': '0755',
'triggers': {
'svc_systemd:gitea:restart',
},
'preceded_by': {
'svc_systemd:gitea:stop',
},
},
} }
if node.metadata['gitea'].get('install_ssh_key', False): if node.metadata['gitea'].get('install_ssh_key', False):
@ -74,10 +63,9 @@ if node.metadata['gitea'].get('install_ssh_key', False):
svc_systemd = { svc_systemd = {
'gitea': { 'gitea': {
'needs': { 'needs': {
'action:chmod_gitea',
'download:/usr/local/bin/gitea',
'file:/etc/systemd/system/gitea.service',
'file:/etc/gitea/app.ini', 'file:/etc/gitea/app.ini',
'file:/etc/systemd/system/gitea.service',
'file:/usr/local/bin/gitea',
}, },
}, },
} }

View file

@ -1,120 +0,0 @@
from bundlewrap.items import Item, ItemStatus
from bundlewrap.exceptions import BundleError
from bundlewrap.utils.text import force_text, mark_for_translation as _
from bundlewrap.utils.remote import PathInfo
import types
from pipes import quote
# Original file: https://github.com/bundlewrap/plugins/blob/master/item_download/items/download.py
# BW4 does not support plugins anymore, thus we download it manually.
class Download(Item):
"""
Download a file and verify its Hash.
"""
BUNDLE_ATTRIBUTE_NAME = "downloads"
NEEDS_STATIC = [
"pkg_apt:",
"pkg_pacman:",
"pkg_yum:",
"pkg_zypper:",
]
ITEM_ATTRIBUTES = {
'url': "",
'sha256': "",
'verifySSL': True,
}
ITEM_TYPE_NAME = "download"
REQUIRED_ATTRIBUTES = []
def __repr__(self):
return "<Download name:{}>".format(self.name)
def __hash_remote_file(self, filename):
path_info = PathInfo(self.node, filename)
if not path_info.is_file:
return None
if hasattr(path_info, 'sha256'):
return path_info.sha256
else:
""""pending pr so do it manualy"""
if self.node.os == 'macos':
result = self.node.run("shasum -a 256 -- {}".format(quote(filename)))
elif self.node.os in self.node.OS_FAMILY_BSD:
result = self.node.run("sha256 -q -- {}".format(quote(filename)))
else:
result = self.node.run("sha256sum -- {}".format(quote(filename)))
return force_text(result.stdout).strip().split()[0]
def fix(self, status):
if status.must_be_deleted:
# Not possible
pass
else:
# download file
try:
self.node.run("curl -L {verify}-s -o {file} -- {url}".format(
verify="" if self.attributes.get('verifySSL', True) else "-k ",
file=quote(self.name),
url=quote(self.attributes['url'])
))
except:
return False
# 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 = {
'type': 'download',
'sha256': self.attributes['sha256'],
}
return cdict
def sdict(self):
"""This is how the world is right now"""
path_info = PathInfo(self.node, self.name)
if not path_info.exists:
return None
else:
sdict = {
'type': 'download',
'sha256': self.__hash_remote_file(self.name)
}
return sdict
@classmethod
def validate_attributes(cls, bundle, item_id, attributes):
if 'sha256' not in attributes:
raise BundleError(_(
"at least one hash must be set on {item} in bundle '{bundle}'"
).format(
bundle=bundle.name,
item=item_id,
))
if 'url' not in attributes:
raise BundleError(_(
"you need to specify the url on {item} in bundle '{bundle}'"
).format(
bundle=bundle.name,
item=item_id,
))
def get_auto_deps(self, items):
deps = []
for item in items:
# debian TODO: add other package manager
if item.ITEM_TYPE_NAME == 'pkg_apt' and item.name == 'curl':
deps.append(item.id)
return deps

View file

@ -135,7 +135,7 @@ nodes['rx300'] = {
}, },
'gitea': { 'gitea': {
'version': '1.15.2', 'version': '1.15.2',
'sha256': '9a7fae605dc182e0c7b1d380647518aaa8736ad5a42f7e9299099317f1e614c9', 'sha1': '548018e2c9c1dfd9ac0919aec743759027ad9c72',
'domain': 'git.franzi.business', 'domain': 'git.franzi.business',
'email_domain_blocklist': { 'email_domain_blocklist': {
'gmail.com', 'gmail.com',