Skip to content

Commit 6aba62a

Browse files
authored
feat(bsd): add OpenBSD support to Meson build (#6789)
1 parent 59b7393 commit 6aba62a

5 files changed

Lines changed: 60 additions & 39 deletions

File tree

meson.build

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,27 @@ elif init_system == 'sysvinit_freebsd'
221221
endforeach
222222
# Enable cloud-init on reboot
223223
meson.add_install_script('sh', '-c', '/usr/sbin/sysrc cloudinit_enable=YES')
224+
elif init_system == 'sysvinit_openbsd'
225+
rcd_templates = run_command(find, 'sysvinit/openbsd', '-type', 'f', check: true)
226+
foreach template : rcd_templates.stdout().strip().split('\n')
227+
custom_target(
228+
input: template,
229+
output: '@BASENAME@',
230+
command: [
231+
render_tmpl,
232+
'@INPUT@',
233+
meson.current_build_dir() / '@OUTPUT@',
234+
],
235+
install: true,
236+
install_dir: sysconfdir / 'rc.d',
237+
install_mode: 'r-xr-xr-x',
238+
install_tag: 'sysvinit',
239+
)
240+
endforeach
241+
meson.add_install_script('/usr/sbin/rcctl', 'enable', 'cloudinitlocal')
242+
meson.add_install_script('/usr/sbin/rcctl', 'enable', 'cloudinit')
243+
meson.add_install_script('/usr/sbin/rcctl', 'enable', 'cloudconfig')
244+
meson.add_install_script('/usr/sbin/rcctl', 'enable', 'cloudfinal')
224245
endif
225246

226247
custom_target(

meson_options.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
option('init_system', type: 'combo', value: 'systemd', choices: ['systemd', 'sysvinit_openrc', 'sysvinit_freebsd'], description: 'Set target init system.')
1+
option('init_system', type: 'combo', value: 'systemd', choices: ['systemd', 'sysvinit_openrc', 'sysvinit_freebsd', 'sysvinit_openbsd'], description: 'Set target init system.')
22
option('distro_templates', type: 'array', value: [], description: 'Distro template files to install. WARNING: Templates may change in the future. If using this option, be sure to check new releases for template file changes.')
33
option('disable_sshd_keygen', type: 'boolean', value: false, description: 'Provide systemd service to disable sshd-keygen if present to avoid races with cloud-init.')
44
option('bash_completion', type: 'boolean', value: true, description: 'Bash completion for cloud-init.')

packages/pkg-deps.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,25 @@
9999
"sudo"
100100
]
101101
},
102+
"openbsd": {
103+
"renames" : {
104+
"pyserial" : "py3-serial",
105+
"pyyaml" : "py3-yaml",
106+
"pytest" : "py3-test",
107+
"pytest-cov" : "py3-test-cov",
108+
"pytest-mock" : "py3-test-mock",
109+
"pytest-xdist": "py3-test-xdist"
110+
},
111+
"build-requires" : [
112+
"bash",
113+
"bash-completion",
114+
"meson"
115+
],
116+
"requires" : [
117+
"e2fsprogs",
118+
"sudo--"
119+
]
120+
},
102121
"suse" : {
103122
"renames" : {
104123
"jinja2" : "python3-Jinja2",

tools/build-on-openbsd

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
#!/bin/sh
2+
# This script provides a quick and dirty way of building and installing
3+
# cloud-init on OpenBSD.
4+
5+
set -eux
26

37
fail() {
48
echo "FAILED:" "$@" 1>&2
@@ -13,42 +17,11 @@ fi
1317

1418
# Check dependencies:
1519
depschecked=/tmp/c-i.dependencieschecked
16-
pkgs="
17-
bash
18-
dmidecode
19-
py3-configobj
20-
py3-jinja2
21-
py3-jsonschema
22-
py3-jsonpatch
23-
py3-jsonpointer
24-
py3-oauthlib
25-
py3-requests
26-
py3-setuptools
27-
py3-serial
28-
py3-yaml
29-
sudo--
30-
wget
31-
"
32-
33-
[ -f $depschecked ] || echo "Installing the following packages: $pkgs"
34-
output=$(pkg_add -zI $pkgs 2>&1)
35-
36-
if echo "$output" | grep -q -e "Can't find" -e "Ambiguous"; then
37-
echo "Failed to find or install one or more packages"
38-
echo "Failed Package(s):"
39-
echo "$output"
40-
exit 1
41-
else
42-
echo Successfully installed packages
43-
touch $depschecked
44-
45-
python3 setup.py build
46-
python3 setup.py install -O1 --distro openbsd --skip-build --init-system sysvinit_openbsd
20+
[ -f "$depschecked" ] || ./tools/read-dependencies --distro openbsd -t || fail "install packages"
21+
touch "$depschecked"
4722

48-
echo "Installation completed."
23+
# Build the code and install in /usr/local/:
24+
meson setup builddir -Dinit_system=sysvinit_openbsd -Dsysconfdir=/etc
25+
meson install -C builddir
4926

50-
rcctl enable cloudinitlocal
51-
rcctl enable cloudinit
52-
rcctl enable cloudconfig
53-
rcctl enable cloudfinal
54-
fi
27+
echo "Installation completed."

tools/read-dependencies

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@ DEFAULT_REQUIREMENTS = "requirements.txt"
2323

2424
DEFAULT_PKG_PREFIX = "python3-"
2525
FREEBSD_PKG_PREFIX = f"py{sys.version_info.major}{sys.version_info.minor}-"
26+
OPENBSD_PKG_PREFIX = "py3-"
2627

2728
# Map the appropriate package dir needed for each distro choice
2829
DISTRO_PKG_TYPE_MAP = {
2930
"centos": "redhat",
3031
"eurolinux": "redhat",
3132
"miraclelinux": "redhat",
3233
"freebsd": "freebsd",
34+
"openbsd": "openbsd",
3335
"fedora": "fedora",
3436
"rocky": "redhat",
3537
"redhat": "redhat",
@@ -113,19 +115,22 @@ DRYRUN_DISTRO_INSTALL_PKG_CMD = {
113115
"redhat": ["yum", "install", "--assumeyes"],
114116
"fedora": ["yum", "install", "--assumeyes"],
115117
"freebsd": ["pkg", "install", "--yes"],
118+
"openbsd": ["pkg_add", "-n"],
116119
}
117120

118121
DISTRO_INSTALL_PKG_CMD = {
119122
"redhat": MAYBE_RELIABLE_YUM_INSTALL,
120123
"fedora": MAYBE_RELIABLE_YUM_INSTALL,
121124
"freebsd": ["pkg", "install", "--yes"],
125+
"openbsd": ["pkg_add", "-I"],
122126
"debian": ["apt", "install", "-y"],
123127
"suse": ZYPPER_INSTALL,
124128
}
125129

126130
DISTRO_UPDATE_PKG_CMD = {
127131
"redhat": ["yum", "update"],
128132
"freebsd": ["pkg", "update"],
133+
"openbsd": ["pkg_add", "-I", "-u"],
129134
"debian": ["apt", "update", "-q"],
130135
"suse": ["zypper", "update"],
131136
}
@@ -138,6 +143,7 @@ CI_SYSTEM_BASE_PKGS = {
138143
"miraclelinux": ["python3-tox"],
139144
"fedora": ["python3-tox"],
140145
"freebsd": [f"{FREEBSD_PKG_PREFIX}tox"],
146+
"openbsd": [f"{OPENBSD_PKG_PREFIX}tox"],
141147
"redhat": ["python3-tox"],
142148
"centos": ["python3-tox"],
143149
"ubuntu": [
@@ -284,6 +290,8 @@ def translate_pip_to_system_pkg(distro, pip_requires, renames):
284290
"""
285291
if distro in ("freebsd",):
286292
prefix = FREEBSD_PKG_PREFIX
293+
elif distro in ("openbsd",):
294+
prefix = OPENBSD_PKG_PREFIX
287295
else:
288296
prefix = DEFAULT_PKG_PREFIX
289297
standard_pkg_name = "{0}{1}"
@@ -376,7 +384,7 @@ def pkg_install(pkg_list, distro, test_distro=False, dry_run=False):
376384
"""Install a list of packages using the DISTRO_INSTALL_PKG_CMD."""
377385
if test_distro:
378386
pkg_list = list(pkg_list) + CI_SYSTEM_BASE_PKGS["common"]
379-
if distro not in ("freebsd",):
387+
if distro not in ("freebsd", "openbsd"):
380388
pkg_list += CI_SYSTEM_BASE_PKGS["linux_common"]
381389
distro_base_pkgs = CI_SYSTEM_BASE_PKGS.get(distro, [])
382390
pkg_list += distro_base_pkgs

0 commit comments

Comments
 (0)