Files
everest-qemu/scripts/vm-drive.py
T
lw-everestlinuxandClaude Opus 5.5 f687558b66 Initial import: build and boot Everest Linux in QEMU
everest.sh builds Everest's signed packages in an Alpine container,
publishes the base, extra and extra-src repositories, installs the
system with glacier-bootstrap into an initramfs and boots it in QEMU.
The image carries glacier, a toolchain and the repositories, and builds
packages from source inside the VM.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 09:33:38 -04:00

64 lines
2.0 KiB
Python

# vm-drive.py LOG CMDS: boot `everest.sh boot` (8 GB, 8 CPUs) on a pty,
# log in as root and run each line of CMDS (blank and # lines skipped),
# printing its exit status; answers "Proceed?" with y and a repository
# choice with 2 (the -src one). Example CMDS: scripts/vmtests/builds.txt.
# python3 scripts/vm-drive.py /tmp/vm.log scripts/vmtests/builds.txt
import os, pty, re, sys, time, select
LOG = open(sys.argv[1], "w")
CMDS = [l.rstrip("\n") for l in open(sys.argv[2]) if l.strip() and not l.startswith("#")]
env = dict(os.environ, EVEREST_MEM="8192", EVEREST_CPUS="8")
pid, fd = pty.fork()
if pid == 0:
os.chdir(os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))
os.execvpe("./everest.sh", ["./everest.sh", "boot"], env)
buf = ""
def read(timeout):
global buf
r, _, _ = select.select([fd], [], [], timeout)
if not r:
return False
try:
d = os.read(fd, 65536).decode("utf-8", "replace")
except OSError:
raise SystemExit("qemu exited")
LOG.write(d); LOG.flush()
buf += d
return True
def wait(pat, timeout, answers=()):
global buf
end = time.time() + timeout
while time.time() < end:
m = re.search(pat, buf)
if m:
buf = buf[m.end():]
return m
for q, a in answers:
if re.search(q, buf):
buf = re.sub(q, "", buf, count=1)
os.write(fd, (a + "\n").encode())
read(5)
raise SystemExit("timeout waiting for " + pat)
def send(s):
os.write(fd, (s + "\n").encode())
wait(r"Please press Enter", 300)
send("")
wait(r"# $", 60)
send("stty -echo")
time.sleep(1)
ans = [(r"Proceed\? \(y/N\): ", "y"),
(r"Select a repository \[1-\d+, Enter = 1\]: ", "2")]
for c in CMDS:
buf = ""
print(">>> " + c, flush=True)
LOG.write("\n>>> " + c + "\n")
send(c + '; echo "@@RC=$?@@"')
m = wait(r"@@RC=(\d+)@@", 3 * 3600, ans)
print(" rc=" + m.group(1), flush=True)
send("poweroff -f")
time.sleep(5)