mag

a binary package manager in one C file: apk and pacman repos, CRUX, Void and Exherbo ports
git clone https://github.com/tortr-rs/mag
Log | Files | Refs | README | LICENSE

commit c8fe16dc904aac95ad55964d71b300758dec028e
parent cbc3410138a5481f0fab1ac7bbf113d017399dfe
Author: torter <koubbamohamedrayan@gmail.com>
Date:   Sat, 14 Nov 2026 19:26:08 +0000

mag sync, cfdisk in util-linux, zfs and its kernel module, CONFIGURE_ARGS.name in mag.conf

Diffstat:
MREADME.md | 6+++++-
Mmag.c | 40+++++++++++++++++++++++++++++++++++-----
Mrepo/sys-apps/util-linux | 6+++---
Arepo/sys-fs/zfs | 10++++++++++
Arepo/sys-kernel/zfs-module | 13+++++++++++++
Mtests/run.sh | 7+++++++
6 files changed, 73 insertions(+), 9 deletions(-)

diff --git a/README.md b/README.md @@ -29,6 +29,10 @@ are put in place with a rename so a running program is never half written, and a already there is left alone (a changed one comes as `.new`). Every package keeps its file list in `var/lib/mag`, so `remove`, `files`, `owns` and `autoremove` need nothing else. -`MAG_ROOT` installs somewhere else than /, `MAG_REPO` is a list of repos split by colons, `MAG_FETCH` is the +`MAG_ROOT` installs somewhere else than /, `MAG_REPO` is a list of repos split by colons (default +`/usr/share/mag/repo:/usr/pkgsrc`), `MAG_FETCH` is the download command (it needs https, which mag doesn't do itself: curl by default). tar and rm come from the system, which here means rifle and a tar. + +`mag sync` downloads the pkgsrc tree (`MAG_SYNC_URL`, NetBSD's `pkgsrc.tar.xz` if unset) with the same download command and +unpacks it into `/usr/pkgsrc`, or `$MAG_ROOT/usr/pkgsrc`. `CONFIGURE_ARGS.name` in `/etc/mag.conf` adds configure arguments to one pkgsrc package. diff --git a/mag.c b/mag.c @@ -616,7 +616,7 @@ static void compute_options(struct vars *vs) free(out); } -/* /etc/mag.conf in the root: pkgsrc's mk.conf, plain VAR=value lines. JOBS, CFLAGS and the like for every build, PKG_DEFAULT_OPTIONS and PKG_OPTIONS.name for the pkgsrc packages */ +/* /etc/mag.conf in the root: pkgsrc's mk.conf, plain VAR=value lines. JOBS, CFLAGS and the like for every build, PKG_DEFAULT_OPTIONS and PKG_OPTIONS.name and CONFIGURE_ARGS.name (extra configure arguments) for the pkgsrc packages */ static struct vars conf; static void read_makefile(struct vars *vs, const char *file, const char *pkgdir, const char *repo, struct list *bl, int depth); static void load_conf(void) @@ -976,6 +976,9 @@ static struct recipe *parse_pkgsrc(const char *id, const char *dir, const char * { const char *prefix_args = ""; char *cfg = var_get(&vs, "CONFIGURE_ARGS") ? expand(&vs, var_get(&vs, "CONFIGURE_ARGS"), 0) : xstrdup(""); + char *ckey = fmt("CONFIGURE_ARGS.%s", strrchr(id, '/') ? strrchr(id, '/') + 1 : id); + if (conf_get(ckey)) cfg = fmt("%s %s", cfg, conf_get(ckey)); + free(ckey); char *mflags = fmt("%s%s%s %s", var_get(&vs, "USE_BSD_MAKEFILE") ? "BINDIR=$PREFIX/bin MANDIR=$PREFIX/man LIBDIR=$PREFIX/lib BINOWN=$(id -un) BINGRP=$(id -gn) MANOWN=$(id -un) MANGRP=$(id -gn) LIBOWN=$(id -un) LIBGRP=$(id -gn) " : "", var_get(&vs, "USE_LIBTOOL") ? "LIBTOOL=libtool " : "", var_get(&vs, "MAKE_FLAGS") ? expand(&vs, var_get(&vs, "MAKE_FLAGS"), 0) : "", var_get(&vs, "BUILD_MAKE_FLAGS") ? expand(&vs, var_get(&vs, "BUILD_MAKE_FLAGS"), 0) : ""); char *menv = var_get(&vs, "MAKE_ENV") ? expand(&vs, var_get(&vs, "MAKE_ENV"), 0) : xstrdup(""); char *cenv = var_get(&vs, "CONFIGURE_ENV") ? expand(&vs, var_get(&vs, "CONFIGURE_ENV"), 0) : xstrdup(""); @@ -1019,7 +1022,7 @@ static struct recipe *parse_pkgsrc(const char *id, const char *dir, const char * if (hook[3]) cmd += sprintf(cmd, "%s\n", hook[3]); else if (hasconfig && !cmake) { const char *scr = var_get(&vs, "CONFIGURE_SCRIPT") ? var_get(&vs, "CONFIGURE_SCRIPT") : "./configure"; - if (gnu || !var_get(&vs, "CONFIGURE_SCRIPT")) cmd += sprintf(cmd, "%s %s --prefix=$PREFIX --mandir=$PREFIX/man --sysconfdir=/etc --localstatedir=/var %s\n", cenv, scr, cfg); + if (gnu || !var_get(&vs, "CONFIGURE_SCRIPT")) cmd += sprintf(cmd, "%s %s %s %s --sysconfdir=/etc --localstatedir=/var %s\n", cenv, scr, strstr(cfg, "--prefix=") ? "" : "--prefix=$PREFIX", strstr(cfg, "--mandir=") ? "" : "--mandir=$PREFIX/man", cfg); else cmd += sprintf(cmd, "%s %s %s\n", cenv, scr, cfg); } if (hook[4]) cmd += sprintf(cmd, "%s\n", hook[4]); @@ -1739,6 +1742,31 @@ static int cmd_hash(int n, char **files) return bad; } +static int cmd_sync(void) +{ + const char *url = getenv("MAG_SYNC_URL"), *cmd = getenv("MAG_FETCH"); + char *file = fmt("%s/var/cache/mag/pkgsrc.tar.xz", root), *part = fmt("%s.part", file), *tmp = fmt("%s/usr/pkgsrc.sync", root), *tree = fmt("%s/usr/pkgsrc", root), *from = fmt("%s/pkgsrc", tmp); + char *dl[] = { "/bin/sh", "-c", "set -f; $0 \"$1\" \"$2\"", (char *)(cmd ? cmd : "curl -fsSL -o"), part, (char *)(url ? url : "https://cdn.netbsd.org/pub/pkgsrc/current/pkgsrc.tar.xz"), NULL }; + char *un[] = { "tar", "-xf", file, "-C", tmp, NULL }; + char *rm[] = { "rm", "-rf", tree, NULL }; + char *dir = xstrdup(file); + *strrchr(dir, '/') = 0; + if (mkpath(dir, 0755) < 0) die("cannot make %s: %s", dir, strerror(errno)); + printf("==> fetching %s\n", dl[5]); + if (run(dl, NULL)) { unlink(part); die("could not fetch %s", dl[5]); } + if (rename(part, file)) die("cannot write %s: %s", file, strerror(errno)); + rmtree(tmp); + if (mkpath(tmp, 0755) < 0) die("cannot make %s: %s", tmp, strerror(errno)); + printf("==> unpacking into %s\n", tree); + if (run(un, NULL)) { rmtree(tmp); die("could not unpack %s", file); } + run(rm, NULL); + if (rename(from, tree)) { rmtree(tmp); die("cannot move the tree to %s: %s", tree, strerror(errno)); } + rmdir(tmp); + unlink(file); + free(dir); + return 0; +} + static int cmd_fetch(int n, char **names) { int i; @@ -1837,14 +1865,15 @@ static void usage(void) " deps PKG its dependencies, rdeps PKG for what needs it\n" " fetch PKG... only download and check the sources\n" " build PKG build into a stage directory, install nothing\n" + " sync download the pkgsrc tree to /usr/pkgsrc\n" " hash FILE... sha256 of files, for writing recipes\n" "\n" " -n only say what would happen -f go on when files clash or something needs the package\n" " -k keep the build directory\n" "\n" "MAG_ROOT installs somewhere else than /, MAG_REPO is a list of repos split by colons (default\n" - "/usr/share/mag/repo), MAG_FETCH is the download command, which gets a file and an url (default\n" - "curl -fsSL -o), MAG_PREFIX is $PREFIX for the steps, /usr, and MAG_JOBS is $JOBS, 4"); + "/usr/share/mag/repo:/usr/pkgsrc), MAG_SYNC_URL is where sync gets the tree,\n" + "MAG_FETCH is the download command, which gets a file and an url (default curl -fsSL -o), MAG_PREFIX is $PREFIX for the steps, /usr, and MAG_JOBS is $JOBS, 4"); } int main(int argc, char **argv) @@ -1854,7 +1883,7 @@ int main(int argc, char **argv) int i = 1, rc; root = ""; if (r && strcmp(r, "/")) { rr = xstrdup(r); s = rr + strlen(rr); while (s > rr + 1 && s[-1] == '/') *--s = 0; root = rr; } - rp = rp && *rp ? rp : "/usr/share/mag/repo"; + rp = rp && *rp ? rp : "/usr/share/mag/repo:/usr/pkgsrc"; rr = xstrdup(rp); for (s = rr; s; ) { char *e = strchr(s, ':'); @@ -1892,6 +1921,7 @@ int main(int argc, char **argv) else if (!strcmp(cmd, "fetch") && n) rc = cmd_fetch(n, a); else if (!strcmp(cmd, "build") && n == 1) rc = cmd_build(a[0]); else if (!strcmp(cmd, "relocate") && n <= 1) rc = cmd_relocate(n ? a[0] : NULL); + else if (!strcmp(cmd, "sync") && !n) rc = cmd_sync(); else if (!strcmp(cmd, "hash") && n) rc = cmd_hash(n, a); else { say("'%s' with %d argument%s makes no sense, mag help says what there is", cmd, n, n == 1 ? "" : "s"); return 1; } } diff --git a/repo/sys-apps/util-linux b/repo/sys-apps/util-linux @@ -1,9 +1,9 @@ -desc: mount, fdisk, lsblk, losetup and the other basics from the kernel people +desc: mount, fdisk, cfdisk, lsblk, losetup and the other basics from the kernel people version: 2.42 url: https://cdn.kernel.org/pub/linux/utils/util-linux/v2.42/util-linux-${version}.tar.xz sha256: 3452b260bbaa775d6e749ac3bb22111785003fc1f444970025c8da26dfa758e9 -deps: sys-kernel/linux-headers devel/gmake +deps: sys-kernel/linux-headers devel/gmake devel/pkgconf dev-libs/netbsd-curses steps: - ./configure --prefix=$PREFIX --disable-shared --disable-nls --disable-liblastlog2 --disable-nsenter --without-ncurses --without-tinfo --without-readline --without-python --without-systemd --without-udev --disable-makeinstall-chown --disable-makeinstall-setuid + ./configure NCURSESW6_CONFIG=false NCURSESW5_CONFIG=false ac_cv_header_ncursesw_ncurses_h=no ac_cv_header_ncursesw_term_h=no --prefix=$PREFIX --disable-shared --with-pic --disable-nls --disable-liblastlog2 --disable-nsenter --with-ncursesw --without-tinfo --without-readline --without-python --without-systemd --without-udev --disable-makeinstall-chown --disable-makeinstall-setuid gmake -j$JOBS gmake DESTDIR=$DESTDIR install diff --git a/repo/sys-fs/zfs b/repo/sys-fs/zfs @@ -0,0 +1,10 @@ +desc: OpenZFS, zpool and zfs; the module comes with sys-kernel/zfs-module +version: 2.4.4 +url: https://github.com/openzfs/zfs/releases/download/zfs-${version}/zfs-${version}.tar.gz +sha256: 2a3c70d55a37cc71618a95a60e81ad66530201eb118d37741dc92efcf848c8b1 +deps: sys-apps/util-linux devel/libtirpc security/libressl devel/zlib devel/pkgconf devel/gmake +steps: + ./configure --prefix=$PREFIX --sysconfdir=/etc --localstatedir=/var --with-config=user --with-tirpc --with-udevdir=$PREFIX/lib/udev --enable-pyzfs=no --enable-pam=no --disable-sysvinit --disable-systemd --disable-static + gmake -j$JOBS + gmake DESTDIR=$DESTDIR install + rm -rf $DESTDIR$PREFIX/share/man $DESTDIR$PREFIX/lib/systemd $DESTDIR$PREFIX/share/zfs diff --git a/repo/sys-kernel/zfs-module b/repo/sys-kernel/zfs-module @@ -0,0 +1,13 @@ +desc: the ZFS kernel modules for the prebuilt kernel, 2.4.4 +version: 6.18.63 +url: https://dl-cdn.alpinelinux.org/alpine/v3.24/main/x86_64/zfs-lts-${version}-r0.apk +sha256: bfb2737afdd286a920256568e0c9057b6c54e90ec8b954c8f3b0681a523e6ddf +deps: sys-kernel/linux +steps: + tar -xzf zfs-lts-*.apk 2>/dev/null || true + kv=$(ls lib/modules) + mkdir -p $DESTDIR/lib/modules/$kv/extra + for f in lib/modules/$kv/extra/*.ko.gz; do + gzip -dc $f > ${f%.gz} + llvm-strip --strip-debug -o $DESTDIR/lib/modules/$kv/extra/$(basename ${f%.gz}) ${f%.gz} + done diff --git a/tests/run.sh b/tests/run.sh @@ -211,5 +211,12 @@ printf 'PKG_DEFAULT_OPTIONS=-beta\nPKG_OPTIONS.opt=gamma -alpha\n' >"$T/root/etc check 'package option variable' " options: gamma" "$($MAG info devel/opt | grep '^ options:')" rm "$T/root/etc/mag.conf" +mkdir -p "$T/ps/pkgsrc/cat/pkg"; echo one >"$T/ps/pkgsrc/cat/pkg/Makefile" +tar -C "$T/ps" -cf "$T/ps.tar" pkgsrc +MAG_SYNC_URL=file://$T/ps.tar $MAG sync >/dev/null 2>&1; check 'sync' "one" "$(cat "$T/root/usr/pkgsrc/cat/pkg/Makefile")" +echo two >"$T/ps/pkgsrc/cat/pkg/Makefile" +tar -C "$T/ps" -cf "$T/ps.tar" pkgsrc +MAG_SYNC_URL=file://$T/ps.tar $MAG sync >/dev/null 2>&1; check 'sync again' "two" "$(cat "$T/root/usr/pkgsrc/cat/pkg/Makefile")" + echo "$pass passed, $fail failed" [ $fail = 0 ]