From fb9317f5bc3388baf1f9c9acbdbbe50e5b81b02b Mon Sep 17 00:00:00 2001 From: diviocity Date: Mon, 30 Nov 2026 02:36:04 +0100 Subject: [PATCH] Package the release cron, locale and removable-media filesystem layout --- tests/layout.py | 35 +++++++++++++++++++++++++++++++++- vinix-filesystem/20locale.sh | 3 +++ vinix-filesystem/PKGBUILD.vile | 26 ++++++++++++++++++------- vinix-filesystem/fstab | 3 +++ vinix-filesystem/root.crontab | 6 ++++++ vinix-filesystem/sysctl.conf | 1 + 6 files changed, 66 insertions(+), 8 deletions(-) create mode 100644 vinix-filesystem/20locale.sh create mode 100644 vinix-filesystem/fstab create mode 100644 vinix-filesystem/root.crontab create mode 100644 vinix-filesystem/sysctl.conf diff --git a/tests/layout.py b/tests/layout.py index dfa403d..6aeff45 100644 --- a/tests/layout.py +++ b/tests/layout.py @@ -2,6 +2,7 @@ import argparse import os import stat +import subprocess from pathlib import Path @@ -10,6 +11,34 @@ def require(condition, message): raise ValueError(message) +def check_periodic(root): + crontabs = root / "var/spool/cron/crontabs" + require(os.readlink(crontabs) == "../../../etc/crontabs", "wrong cron spool") + require(os.readlink(root / "var/spool/mail") == "../mail" and (root / "var/mail").is_dir(), "wrong mail spool") + require(stat.S_IMODE((crontabs / "root").stat().st_mode) == 0o600, "root crontab is not private") + jobs = [line.split() for line in (crontabs / "root").read_text().splitlines() if line and not line.startswith("#")] + schedules = {"15min": "*/15 * * * *", "hourly": "0 * * * *", "daily": "0 2 * * *", + "weekly": "0 3 * * 6", "monthly": "0 5 1 * *"} + require(len(jobs) == len(schedules), "unexpected number of cron schedules") + for job in jobs: + require(len(job) == 7 and job[5] == "run-parts" and (root / job[6][1:]).is_dir(), "invalid scheduled task") + period = job[6].removeprefix("/etc/periodic/") + require(schedules.pop(period, None) == " ".join(job[:5]), f"incorrect interval for {period}") + mounts = set() + for entry in (root / "etc/fstab").read_text().splitlines(): + if entry and not entry.startswith("#"): + device, mountpoint, _, flags, _, _ = entry.split() + require(device.startswith("/dev/") and (root / mountpoint[1:]).is_dir() and "noauto" in flags.split(","), + "invalid removable-media mount") + mounts.add(mountpoint) + require(mounts == {"/media/usb", "/media/cdrom"}, "missing removable-media mount") + script = root / "etc/profile.d/20locale.sh" + for env, expected in [({}, "C.UTF-8 UTF-8 C"), ({"LANG": "custom", "LC_COLLATE": "other"}, "custom UTF-8 other")]: + result = subprocess.check_output(["/bin/sh", "-c", '. "$1"; echo "$LANG $CHARSET $LC_COLLATE"', "sh", script], + env=env, text=True) + require(result.strip() == expected, "locale profile overwrote the caller's environment") + + def check(root): for path, mode in (("tmp", 0o1777), ("var/tmp", 0o1777), ("root", 0o700), ("etc/shadow", 0o600), ("etc/passwd", 0o644), ("etc/group", 0o644)): @@ -33,4 +62,8 @@ def check(root): if __name__ == "__main__": parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("root", type=Path) - check(parser.parse_args().root) + parser.add_argument("--periodic", action="store_true", help="check the filesystem release 2 cron, locale and mount layout") + args = parser.parse_args() + check(args.root) + if args.periodic: + check_periodic(args.root) diff --git a/vinix-filesystem/20locale.sh b/vinix-filesystem/20locale.sh new file mode 100644 index 0000000..4d1c148 --- /dev/null +++ b/vinix-filesystem/20locale.sh @@ -0,0 +1,3 @@ +export LANG=${LANG:-C.UTF-8} +export CHARSET=${CHARSET:-UTF-8} +export LC_COLLATE=${LC_COLLATE:-C} diff --git a/vinix-filesystem/PKGBUILD.vile b/vinix-filesystem/PKGBUILD.vile index 32bdb12..73ce30b 100644 --- a/vinix-filesystem/PKGBUILD.vile +++ b/vinix-filesystem/PKGBUILD.vile @@ -1,20 +1,26 @@ defpkgbuild(vinix-filesystem, #:pkgname, "vinix-filesystem", #:pkgver, "0.1.0", - #:pkgrel, 1, + #:pkgrel, 2, #:pkgdesc, "Vinix filesystem directories, runtime links, host policy and login environment", #:arch, [#:any], #:url, "https://github.com/vlang/vinix", #:license, "GPL-2.0-or-later", - #:backup, ["etc/hosts", "etc/hostname", "etc/nsswitch.conf", "etc/shells", "etc/profile"], - #:source, ["hosts", "hostname", "nsswitch.conf", "shells", "profile"], + #:backup, ["etc/hosts", "etc/hostname", "etc/nsswitch.conf", "etc/shells", "etc/profile", + "etc/crontabs/root", "etc/fstab", "etc/profile.d/20locale.sh", "etc/sysctl.conf"], + #:source, ["hosts", "hostname", "nsswitch.conf", "shells", "profile", "20locale.sh", "root.crontab", "fstab", "sysctl.conf"], #:sha256sums, ["b69b2c741be48691edabe3771c644c70473ccd6aa8effd9f17cc07fa129917f9", "251a9fbf3ef48f76ea758f161e04f8e2ffc27d712bd4993a4763e53163dbd0f4", "2ad90a00ddc40e2931e9da1b7c943a5d40d15039436ea2e20442d47c0916959e", "7da658925aa565924877b098d2d61eba65190943266973a37182fc96b8f89cdb", - "1ecc0432bad0127ea5747b9741c5706427b71536fd7ac4426b4a59b532753835"], + "1ecc0432bad0127ea5747b9741c5706427b71536fd7ac4426b4a59b532753835", + "73fa681126789a1c8e73f04b436b028b1940f32d85ba6a2ea36a9401bc43a87d", + "2a04bebac7881eb2d6c9627e028a6819480f308741107f6989a405b44c5adaa8", + "5fed085bb3a0938b04e8b53e4d92049153c42954f077b5ed3aadfc53a217eea6", + "3134041675887f0fe3493fde7820bb49382840223c6cb02dbd822f4accac371c"], #:check, fn() { run("sh", "-n", "profile") + run("sh", "-n", "20locale.sh") run("grep", "-Fx", "/bin/sh", "shells") run("grep", "-Fx", "hosts: files dns", "nsswitch.conf") }, @@ -22,14 +28,20 @@ defpkgbuild(vinix-filesystem, for-each(fn(dir) { run("install", "-d", "-m755", string-append(pkgdir(), "/", dir)) }, list("bin", "sbin", "dev", "dev/pts", "dev/shm", "proc", "sys", "home", "etc/profile.d", - "etc/sysctl.d", "run/lock", "mnt", "media", "opt", "srv", "lib", "usr/bin", "usr/lib", + "etc/sysctl.d", "etc/crontabs", "run/lock", "mnt", "media/cdrom", "media/usb", "opt", "srv", "lib", "usr/bin", "usr/lib", "usr/sbin", "usr/share", "usr/local/bin", "usr/local/lib", "usr/local/sbin", "usr/local/share", - "var/cache", "var/lib", "var/log", "var/spool")) + "var/cache", "var/lib", "var/log", "var/mail", "var/spool/cron")) + for-each(fn(period) { run("install", "-d", "-m755", string-append(pkgdir(), "/etc/periodic/", period)) }, + list("15min", "hourly", "daily", "weekly", "monthly")) run("install", "-d", "-m700", string-append(pkgdir(), "/root")) run("install", "-d", "-m1777", string-append(pkgdir(), "/tmp"), string-append(pkgdir(), "/var/tmp")) for-each(fn(file) { run("install", "-Dm644", file, string-append(pkgdir(), "/etc/", file)) - }, list("hosts", "hostname", "nsswitch.conf", "shells", "profile")) + }, list("hosts", "hostname", "nsswitch.conf", "shells", "profile", "fstab", "sysctl.conf")) + run("install", "-Dm644", "20locale.sh", string-append(pkgdir(), "/etc/profile.d/20locale.sh")) + run("install", "-Dm600", "root.crontab", string-append(pkgdir(), "/etc/crontabs/root")) + run("ln", "-s", "../mail", string-append(pkgdir(), "/var/spool/mail")) + run("ln", "-s", "../../../etc/crontabs", string-append(pkgdir(), "/var/spool/cron/crontabs")) run("ln", "-s", "../run", string-append(pkgdir(), "/var/run")) run("ln", "-s", "../run/lock", string-append(pkgdir(), "/var/lock")) run("ln", "-s", "/proc/mounts", string-append(pkgdir(), "/etc/mtab")) diff --git a/vinix-filesystem/fstab b/vinix-filesystem/fstab new file mode 100644 index 0000000..880e339 --- /dev/null +++ b/vinix-filesystem/fstab @@ -0,0 +1,3 @@ +# Optional removable media. Mount explicitly when the device is present. +/dev/cdrom /media/cdrom iso9660 noauto,ro 0 0 +/dev/usbdisk /media/usb vfat noauto,ro 0 0 diff --git a/vinix-filesystem/root.crontab b/vinix-filesystem/root.crontab new file mode 100644 index 0000000..ec605de --- /dev/null +++ b/vinix-filesystem/root.crontab @@ -0,0 +1,6 @@ +# Minute hour day-of-month month day-of-week command +*/15 * * * * run-parts /etc/periodic/15min +0 * * * * run-parts /etc/periodic/hourly +0 2 * * * run-parts /etc/periodic/daily +0 3 * * 6 run-parts /etc/periodic/weekly +0 5 1 * * run-parts /etc/periodic/monthly diff --git a/vinix-filesystem/sysctl.conf b/vinix-filesystem/sysctl.conf new file mode 100644 index 0000000..27f892d --- /dev/null +++ b/vinix-filesystem/sysctl.conf @@ -0,0 +1 @@ +# Local settings for the sysctl command. -- 2.56.1