bundlewrap/bundles/apt/items.py

69 lines
1.9 KiB
Python
Raw Normal View History

2020-02-29 14:42:29 +00:00
actions = {
'apt_update': {
'command': 'apt-get update',
'needed_by': [
'pkg_apt:',
],
'triggered': True,
'cascade_skip': False,
},
}
files = {
'/etc/apt/apt.conf.d/50unattended-upgrades': {
'content_type': 'mako',
'source': 'apt.conf-unattended-upgrades',
'context': {'data': node.metadata.get('apt', {}).get('unattended-upgrades', {})}
},
}
directories = {
'/etc/apt/sources.list.d': {},
}
pkg_apt = {
'apt-transport-https': {},
'unattended-upgrades': {},
}
gpg_keys = set()
for name, data in node.metadata.get('apt', {}).get('repos', {}).items():
files['/etc/apt/sources.list.d/{}.list'.format(name)] = {
'content_type': 'mako',
'content': "\n".join(data['items']),
'triggers': [
'action:apt_update',
],
}
if 'key' in data:
gpg_keys.add(data['key'])
files['/etc/apt/sources.list.d/{}.list'.format(name)]['needs'] = [
'action:add_gpg_key_{}'.format(data['key']),
]
previous_action = None
for key in gpg_keys:
files['/etc/apt/gpg-keys/{}'.format(key)] = {
'source': 'gpg-keys/{}'.format(key),
}
action_name = 'add_gpg_key_{}'.format(key)
action_item_name = 'action:' + action_name
actions[action_name] = {
'command': 'apt-key add /etc/apt/gpg-keys/{}'.format(key),
'unless': 'apt-key export {} 2>/dev/null | grep -q "END PGP PUBLIC KEY BLOCK"'.format(key),
'cascade_skip': False,
'needed_by': ["action:apt_update"],
'needs': list(filter(None, [
'file:/etc/apt/gpg-keys/{}'.format(key),
previous_action,
])),
}
previous_action = action_item_name
if node.metadata.get('apt', {}).get('packages', {}):
for package, options in node.metadata['apt']['packages'].items():
pkg_apt[package] = options