pkg(7): expand VERSION_MAJOR, VERSION_MINOR, RELEASE and OSNAME

Catchup with pkg(8) by expanding more variable when parsing repositories
The only missing variable now is ARCH, this will have to wait for
pkg 2.0 to be the lowest supported version.
This commit is contained in:
Baptiste Daroussin 2025-01-16 14:50:42 +01:00
parent 7c882c69a4
commit e3b4a51580

View file

@ -477,11 +477,26 @@ read_conf_file(const char *confpath, const char *requested_repo,
struct ucl_parser *p;
ucl_object_t *obj = NULL;
const char *abi = pkg_get_myabi();
char *major, *minor;
struct utsname uts;
if (uname(&uts))
err(EXIT_FAILURE, "uname");
if (abi == NULL)
errx(EXIT_FAILURE, "Failed to determine ABI");
p = ucl_parser_new(0);
asprintf(&major, "%d", __FreeBSD_version/100000);
if (major == NULL)
err(EXIT_FAILURE, "asprintf");
asprintf(&minor, "%d", (__FreeBSD_version / 1000) % 100);
if (minor == NULL)
err(EXIT_FAILURE, "asprintf");
ucl_parser_register_variable(p, "ABI", abi);
ucl_parser_register_variable(p, "OSNAME", uts.sysname);
ucl_parser_register_variable(p, "RELEASE", major);
ucl_parser_register_variable(p, "VERSION_MAJOR", major);
ucl_parser_register_variable(p, "VERSION_MINOR", minor);
if (!ucl_parser_add_file(p, confpath)) {
if (errno != ENOENT)
@ -505,6 +520,8 @@ read_conf_file(const char *confpath, const char *requested_repo,
ucl_object_unref(obj);
ucl_parser_free(p);
free(major);
free(minor);
return (0);
}