me

/

vinix-ports Public
382 commits 0 issues 0 pull requests 1 contributor Discussions Projects Snippets LOC history Platform CI

Package the release cron, locale and removable-media filesystem layout

diviocity committed 5 days ago · fb9317f5bc3388baf1f9c9acbdbbe50e5b81b02b View patch
Unverified signature 6 files changed +66 -8
tests/layout.py +34 -1

@@ -2,6 +2,7 @@

22import argparse

33import os

44import stat

5+import subprocess

56from pathlib import Path

67

78

@@ -10,6 +11,34 @@ def require(condition, message):

1011 raise ValueError(message)

1112

1213

14+def check_periodic(root):

15+ crontabs = root / "var/spool/cron/crontabs"

16+ require(os.readlink(crontabs) == "../../../etc/crontabs", "wrong cron spool")

17+ require(os.readlink(root / "var/spool/mail") == "../mail" and (root / "var/mail").is_dir(), "wrong mail spool")

18+ require(stat.S_IMODE((crontabs / "root").stat().st_mode) == 0o600, "root crontab is not private")

19+ jobs = [line.split() for line in (crontabs / "root").read_text().splitlines() if line and not line.startswith("#")]

20+ schedules = {"15min": "*/15 * * * *", "hourly": "0 * * * *", "daily": "0 2 * * *",

21+ "weekly": "0 3 * * 6", "monthly": "0 5 1 * *"}

22+ require(len(jobs) == len(schedules), "unexpected number of cron schedules")

23+ for job in jobs:

24+ require(len(job) == 7 and job[5] == "run-parts" and (root / job[6][1:]).is_dir(), "invalid scheduled task")

25+ period = job[6].removeprefix("/etc/periodic/")

26+ require(schedules.pop(period, None) == " ".join(job[:5]), f"incorrect interval for {period}")

27+ mounts = set()

28+ for entry in (root / "etc/fstab").read_text().splitlines():

29+ if entry and not entry.startswith("#"):

30+ device, mountpoint, _, flags, _, _ = entry.split()

31+ require(device.startswith("/dev/") and (root / mountpoint[1:]).is_dir() and "noauto" in flags.split(","),

32+ "invalid removable-media mount")

33+ mounts.add(mountpoint)

34+ require(mounts == {"/media/usb", "/media/cdrom"}, "missing removable-media mount")

35+ script = root / "etc/profile.d/20locale.sh"

36+ for env, expected in [({}, "C.UTF-8 UTF-8 C"), ({"LANG": "custom", "LC_COLLATE": "other"}, "custom UTF-8 other")]:

37+ result = subprocess.check_output(["/bin/sh", "-c", '. "$1"; echo "$LANG $CHARSET $LC_COLLATE"', "sh", script],

38+ env=env, text=True)

39+ require(result.strip() == expected, "locale profile overwrote the caller's environment")

40+

41+

1342def check(root):

1443 for path, mode in (("tmp", 0o1777), ("var/tmp", 0o1777), ("root", 0o700),

1544 ("etc/shadow", 0o600), ("etc/passwd", 0o644), ("etc/group", 0o644)):

@@ -33,4 +62,8 @@ def check(root):

3362if __name__ == "__main__":

3463 parser = argparse.ArgumentParser(description=__doc__)

3564 parser.add_argument("root", type=Path)

36- check(parser.parse_args().root)

65+ parser.add_argument("--periodic", action="store_true", help="check the filesystem release 2 cron, locale and mount layout")

66+ args = parser.parse_args()

67+ check(args.root)

68+ if args.periodic:

69+ check_periodic(args.root)

vinix-filesystem/20locale.sh new file +3 -0

@@ -0,0 +1,3 @@

1+export LANG=${LANG:-C.UTF-8}

2+export CHARSET=${CHARSET:-UTF-8}

3+export LC_COLLATE=${LC_COLLATE:-C}

vinix-filesystem/PKGBUILD.vile +19 -7

@@ -1,20 +1,26 @@

11defpkgbuild(vinix-filesystem,

22 #:pkgname, "vinix-filesystem",

33 #:pkgver, "0.1.0",

4- #:pkgrel, 1,

4+ #:pkgrel, 2,

55 #:pkgdesc, "Vinix filesystem directories, runtime links, host policy and login environment",

66 #:arch, [#:any],

77 #:url, "https://github.com/vlang/vinix",

88 #:license, "GPL-2.0-or-later",

9- #:backup, ["etc/hosts", "etc/hostname", "etc/nsswitch.conf", "etc/shells", "etc/profile"],

10- #:source, ["hosts", "hostname", "nsswitch.conf", "shells", "profile"],

9+ #:backup, ["etc/hosts", "etc/hostname", "etc/nsswitch.conf", "etc/shells", "etc/profile",

10+ "etc/crontabs/root", "etc/fstab", "etc/profile.d/20locale.sh", "etc/sysctl.conf"],

11+ #:source, ["hosts", "hostname", "nsswitch.conf", "shells", "profile", "20locale.sh", "root.crontab", "fstab", "sysctl.conf"],

1112 #:sha256sums, ["b69b2c741be48691edabe3771c644c70473ccd6aa8effd9f17cc07fa129917f9",

1213 "251a9fbf3ef48f76ea758f161e04f8e2ffc27d712bd4993a4763e53163dbd0f4",

1314 "2ad90a00ddc40e2931e9da1b7c943a5d40d15039436ea2e20442d47c0916959e",

1415 "7da658925aa565924877b098d2d61eba65190943266973a37182fc96b8f89cdb",

15- "1ecc0432bad0127ea5747b9741c5706427b71536fd7ac4426b4a59b532753835"],

16+ "1ecc0432bad0127ea5747b9741c5706427b71536fd7ac4426b4a59b532753835",

17+ "73fa681126789a1c8e73f04b436b028b1940f32d85ba6a2ea36a9401bc43a87d",

18+ "2a04bebac7881eb2d6c9627e028a6819480f308741107f6989a405b44c5adaa8",

19+ "5fed085bb3a0938b04e8b53e4d92049153c42954f077b5ed3aadfc53a217eea6",

20+ "3134041675887f0fe3493fde7820bb49382840223c6cb02dbd822f4accac371c"],

1621 #:check, fn() {

1722 run("sh", "-n", "profile")

23+ run("sh", "-n", "20locale.sh")

1824 run("grep", "-Fx", "/bin/sh", "shells")

1925 run("grep", "-Fx", "hosts: files dns", "nsswitch.conf")

2026 },

@@ -22,14 +28,20 @@ defpkgbuild(vinix-filesystem,

2228 for-each(fn(dir) {

2329 run("install", "-d", "-m755", string-append(pkgdir(), "/", dir))

2430 }, list("bin", "sbin", "dev", "dev/pts", "dev/shm", "proc", "sys", "home", "etc/profile.d",

25- "etc/sysctl.d", "run/lock", "mnt", "media", "opt", "srv", "lib", "usr/bin", "usr/lib",

31+ "etc/sysctl.d", "etc/crontabs", "run/lock", "mnt", "media/cdrom", "media/usb", "opt", "srv", "lib", "usr/bin", "usr/lib",

2632 "usr/sbin", "usr/share", "usr/local/bin", "usr/local/lib", "usr/local/sbin", "usr/local/share",

27- "var/cache", "var/lib", "var/log", "var/spool"))

33+ "var/cache", "var/lib", "var/log", "var/mail", "var/spool/cron"))

34+ for-each(fn(period) { run("install", "-d", "-m755", string-append(pkgdir(), "/etc/periodic/", period)) },

35+ list("15min", "hourly", "daily", "weekly", "monthly"))

2836 run("install", "-d", "-m700", string-append(pkgdir(), "/root"))

2937 run("install", "-d", "-m1777", string-append(pkgdir(), "/tmp"), string-append(pkgdir(), "/var/tmp"))

3038 for-each(fn(file) {

3139 run("install", "-Dm644", file, string-append(pkgdir(), "/etc/", file))

32- }, list("hosts", "hostname", "nsswitch.conf", "shells", "profile"))

40+ }, list("hosts", "hostname", "nsswitch.conf", "shells", "profile", "fstab", "sysctl.conf"))

41+ run("install", "-Dm644", "20locale.sh", string-append(pkgdir(), "/etc/profile.d/20locale.sh"))

42+ run("install", "-Dm600", "root.crontab", string-append(pkgdir(), "/etc/crontabs/root"))

43+ run("ln", "-s", "../mail", string-append(pkgdir(), "/var/spool/mail"))

44+ run("ln", "-s", "../../../etc/crontabs", string-append(pkgdir(), "/var/spool/cron/crontabs"))

3345 run("ln", "-s", "../run", string-append(pkgdir(), "/var/run"))

3446 run("ln", "-s", "../run/lock", string-append(pkgdir(), "/var/lock"))

3547 run("ln", "-s", "/proc/mounts", string-append(pkgdir(), "/etc/mtab"))

vinix-filesystem/fstab new file +3 -0

@@ -0,0 +1,3 @@

1+# Optional removable media. Mount explicitly when the device is present.

2+/dev/cdrom /media/cdrom iso9660 noauto,ro 0 0

3+/dev/usbdisk /media/usb vfat noauto,ro 0 0

vinix-filesystem/root.crontab new file +6 -0

@@ -0,0 +1,6 @@

1+# Minute hour day-of-month month day-of-week command

2+*/15 * * * * run-parts /etc/periodic/15min

3+0 * * * * run-parts /etc/periodic/hourly

4+0 2 * * * run-parts /etc/periodic/daily

5+0 3 * * 6 run-parts /etc/periodic/weekly

6+0 5 1 * * run-parts /etc/periodic/monthly

vinix-filesystem/sysctl.conf new file +1 -0

@@ -0,0 +1 @@

1+# Local settings for the sysctl command.