bundlewrap/bundles/apt/items.py

227 lines
5.3 KiB
Python
Raw Normal View History

from bundlewrap.exceptions import BundleError
supported_os = {
'debian': {
10: 'buster',
2020-11-12 17:40:19 +00:00
11: 'bullseye',
2023-07-13 18:02:38 +00:00
12: 'bookworm',
2020-10-09 16:12:49 +00:00
99: 'unstable',
},
'raspbian': {
10: 'buster',
},
}
try:
supported_os[node.os][node.os_version[0]]
except (KeyError, IndexError):
raise BundleError(f'{node.name}: OS {node.os} {node.os_version} is not supported by bundle:apt')
2020-02-29 14:42:29 +00:00
actions = {
'apt_update': {
'command': 'apt-get update',
2020-08-20 08:59:45 +00:00
'needed_by': {
2020-02-29 14:42:29 +00:00
'pkg_apt:',
2020-08-20 08:59:45 +00:00
},
2020-02-29 14:42:29 +00:00
'triggered': True,
'cascade_skip': False,
},
'apt_execute_update_commands': {
'command': ' && '.join(sorted(node.metadata.get('apt/additional_update_commands'))),
'triggered': True,
},
2020-02-29 14:42:29 +00:00
}
files = {
'/etc/apt/sources.list': {
'source': 'sources.list-{}-{}'.format(node.os, supported_os[node.os][node.os_version[0]]),
'triggers': {
'action:apt_update',
},
},
'/etc/cloud': {
'delete': True,
},
'/etc/kernel/postinst.d/unattended-upgrades': {
'source': 'kernel-postinst.d',
'mode': '0755',
},
'/etc/netplan': {
'delete': True,
},
'/etc/upgrade-and-reboot.conf': {
'content_type': 'mako',
},
'/usr/local/sbin/upgrade-and-reboot': {
'mode': '0700',
},
'/usr/local/sbin/do-unattended-upgrades': {
2020-02-29 14:42:29 +00:00
'content_type': 'mako',
'mode': '0700',
'context': {
'additional_update_commands': node.metadata.get('apt/additional_update_commands', set()),
'clean_old_kernels': node.metadata.get('apt/clean_old_kernels', True),
'restart_triggers': node.metadata.get('apt/restart_triggers', {}),
}
2020-02-29 14:42:29 +00:00
},
'/usr/local/share/icinga/plugins/check_unattended_upgrades': {
'mode': '0755',
2020-08-20 09:07:18 +00:00
},
'/var/lib/cloud': {
'delete': True,
},
2020-02-29 14:42:29 +00:00
}
directories = {
'/etc/apt/sources.list.d': {
'purge': True,
'triggers': {
'action:apt_update',
},
},
2020-02-29 14:42:29 +00:00
}
svc_systemd = {
'apt-daily.timer': {
'running': False,
'enabled': False,
},
'apt-daily-upgrade.timer': {
'running': False,
'enabled': False,
},
}
2020-02-29 14:42:29 +00:00
pkg_apt = {
'apt-transport-https': {},
2020-08-18 13:46:42 +00:00
'arping': {},
'at': {},
'build-essential': {},
2020-08-18 13:46:42 +00:00
'bzip2': {},
'curl': {},
'diffutils': {},
'dnsutils': {},
'git': {},
2020-08-18 13:46:42 +00:00
'grep': {},
'gzip': {},
'htop': {},
'jq': {},
'less': {},
'logrotate': {},
'lsof': {},
'mailutils': {},
'manpages': {},
'moreutils': {},
'mount': {},
'mtr': {},
'ncdu': {},
'ncurses-term': {},
2023-07-13 18:02:38 +00:00
'netcat-openbsd': {},
2020-08-18 13:46:42 +00:00
'nmap': {},
'python3': {},
'python3-dev': {},
'python3-setuptools': {
'needed_by': {
'pkg_pip:',
},
},
'python3-pip': {
'needed_by': {
'pkg_pip:',
},
},
'python3-virtualenv': {},
2020-11-13 11:37:26 +00:00
'rsync': {},
2020-08-18 13:46:42 +00:00
'tar': {},
'tcpdump': {},
'telnet': {},
'tmux': {},
'tree': {},
'unzip': {},
'vim': {},
2020-08-18 13:46:42 +00:00
'wget': {},
'whois': {},
'zip': {},
2020-08-20 09:07:18 +00:00
'cloud-init': {
'installed': False,
},
2023-01-28 17:07:31 +00:00
'molly-guard': {
'installed': False,
},
2020-08-20 09:07:18 +00:00
'netplan.io': {
'installed': False,
},
'popularity-contest': {
'installed': False,
},
'python3-packaging': {
'installed': False,
},
'unattended-upgrades': {
'installed': False,
},
2020-02-29 14:42:29 +00:00
}
if node.os_version[0] >= 11:
symlinks = {
'/usr/bin/python': {
'target': '/usr/bin/python3',
'needs': {
'pkg_apt:python3',
},
},
}
2020-08-20 09:07:18 +00:00
for name, data in node.metadata.get('apt/repos', {}).items():
if 'items' in data:
files['/etc/apt/sources.list.d/{}.list'.format(name)] = {
'content_type': 'mako',
'content': ("\n".join(sorted(data['items']))).format(
os=node.os,
os_release=supported_os[node.os][node.os_version[0]],
),
'triggers': {
'action:apt_update',
},
}
elif 'uris' in data:
uris = {
x.format(
os=node.os,
os_release=supported_os[node.os][node.os_version[0]],
) for x in data['uris']
}
2020-02-29 14:42:29 +00:00
files['/etc/apt/sources.list.d/{}.sources'.format(name)] = {
'source': 'deb822-sources',
'content_type': 'mako',
'context': {
'data': data,
'name': name,
'os_release': supported_os[node.os][node.os_version[0]],
'uris': uris,
},
'triggers': {
'action:apt_update',
},
2020-08-20 08:59:45 +00:00
}
2020-02-29 14:42:29 +00:00
if data.get('install_gpg_key', True):
if 'items' in data:
files['/etc/apt/sources.list.d/{}.list'.format(name)]['needs'] = {
'file:/etc/apt/trusted.gpg.d/{}.list.asc'.format(name),
}
2020-08-20 08:59:45 +00:00
files['/etc/apt/trusted.gpg.d/{}.list.asc'.format(name)] = {
'source': 'gpg-keys/{}.asc'.format(name),
'triggers': {
'action:apt_update',
},
}
2020-02-29 14:42:29 +00:00
2021-04-30 11:30:10 +00:00
for package, options in node.metadata.get('apt/packages', {}).items():
pkg_apt[package] = options