Files
pnpm/.github/scripts/netbsd-vm/enable-ssh.py
T
ef7956b277 feat(release): build NetBSD x64 binaries natively in a VM (#17830)
Build and publish the CLI for NetBSD x64.

The cross images cannot link pnpm for x86_64-unknown-netbsd: their
NetBSD 9 sysroot has no libexecinfo, which Rust's std links, and no
getentropy, which aws-lc calls. NetBSD 9 is end-of-life, and a native
build on NetBSD 10.2 needs no workaround.

The NetBSD entry of the CLI release build matrix runs on a GitHub-hosted
runner, which has KVM. A composite action installs NetBSD 10.2 with
anita from the official release files and boots it, and
.github/scripts/netbsd-vm/vm.sh builds inside it and copies the
artifacts back to where the existing archive, attest, and upload steps
expect them. The release files are checked against a committed SHA512
list, and anita and rustup-init against pinned SHA-256 hashes.

A separate workflow runs the same build, plus an install, on changes to
the VM files and weekly, since only a release tag runs the release jobs.

---------

Co-authored-by: Alessio Attilio <attilio.alessio@protonmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 12:25:37 +01:00

40 lines
1.2 KiB
Python

"""Log in on a fresh anita-installed NetBSD VM's serial console and start sshd.
Usage: enable-ssh.py <serial-port> <authorized-key-file>
"""
import socket
import sys
import time
import pexpect.fdpexpect
port = int(sys.argv[1])
with open(sys.argv[2], encoding='utf-8') as key_file:
authorized_key = key_file.read().strip()
deadline = time.monotonic() + 120
while True:
try:
console = socket.create_connection(('127.0.0.1', port))
break
except OSError:
if time.monotonic() > deadline:
raise
time.sleep(1)
session = pexpect.fdpexpect.fdspawn(console.fileno(), timeout=600, encoding='utf-8', logfile=sys.stdout)
session.send('\r')
session.expect('login:')
session.sendline('root')
session.expect('# ')
for command in [
'echo sshd=YES >> /etc/rc.conf && echo dhcpcd=YES >> /etc/rc.conf',
'echo "PermitRootLogin prohibit-password" >> /etc/ssh/sshd_config',
f'mkdir -p /root/.ssh && echo "{authorized_key}" > /root/.ssh/authorized_keys && chmod -R go= /root/.ssh',
# The quotes keep the console's echo of this line from matching the marker.
'/etc/rc.d/dhcpcd start && /etc/rc.d/sshd start && echo "SSH-""READY"',
]:
session.sendline(command)
session.expect('SSH-READY')