tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: pkgsrc RC scripts



On Mon, 19 Oct 2009, Joerg Sonnenberger wrote:

> I dislike this a lot. Pushing down a random amount of variables is the
> wrong approach, IMO. 

My first draft (against pkg_install-20090724) looked for the wanted variables 
using the same method as the internal variables did, then I thought that 
because these variables (the ones my patch was looking for) are not used
internal why not be generic about it. People could add variables to the
templates in pkgsrc/mk/pkginstall without having to modify pkg_install.
(Plus variables could be used in any +INSTALL script to modify it's
behavior.)

> (1) It overrides mk.conf, so it changes existing behavior.

Could change the third argument of setenv to 0.

> (2) It parses variables differently than the internal use.

Had to in order to do what i was wanting.

> (3) No changes to the ignore / keep white space without proper
> discussion, please.

Can you elaborate on what you mean?

> 
> > I've noted that some of the script templates in pkgsrc/mk/pkginstall are 
> > already setup to use variables passed to them, i.e.:
> > PKG_CREATE_USERGROUP, PKG_CONFIG, PKG_CONFIG_PERMS, PKG_RCD_SCRIPTS,
> > PKG_UPDATE_FONTS_DB, FONTS_VERBOSE, INFO_FILES_VERBOSE, PKG_REGISTER_SHELLS.
> 
> Exactly, as that is the way it gets the data from mk.conf too.

Didn't realize that's why they were done that way. I thought that someone
already had this idea, but the variables had to be set in root's envron
before executing pkg_add.


Anyway i've completely redone the patch taking your points into
consideration, tell me what you think!

-- 
Steven


--- lib/parse-config.c.orig     2009-10-20 09:03:05.000000000 +1300
+++ lib/parse-config.c  2009-10-20 09:52:19.000000000 +1300
@@ -72,32 +72,53 @@ const char *pkg_vulnerabilities_url;
 const char *ignore_advisories = NULL;
 const char tnf_vulnerability_base[] = 
"http://ftp.NetBSD.org/pub/NetBSD/packages/vulns";;
 const char *acceptable_licenses = NULL;
+const char *pkg_create_usergroup;
+const char *pkg_config;
+const char *pkg_config_perms;
+const char *pkg_rcd_scripts;
+const char *pkg_update_fonts_db;
+const char *fonts_verbose;
+const char *info_files_verbose;
+const char *pkg_register_shells;
+const char *rcd_scripts_dir;
+const char *rc_subr_dir;
 
 static struct config_variable {
        const char *name;
        const char **var;
+       const _Bool export;
 } config_variables[] = {
-       { "ACCEPTABLE_LICENSES", &acceptable_licenses },
-       { "ACTIVE_FTP", &active_ftp },
-       { "CERTIFICATE_ANCHOR_PKGS", &certs_packages },
-       { "CERTIFICATE_ANCHOR_PKGVULN", &certs_pkg_vulnerabilities },
-       { "CERTIFICATE_CHAIN", &cert_chain_file },
-       { "CHECK_LICENSE", &do_license_check },
-       { "CHECK_VULNERABILITIES", &check_vulnerabilities },
-       { "DEFAULT_ACCEPTABLE_LICENSES", &default_acceptable_licenses },
-       { "GPG", &gpg_cmd },
-       { "GPG_KEYRING_PKGVULN", &gpg_keyring_pkgvuln },
-       { "GPG_KEYRING_SIGN", &gpg_keyring_sign },
-       { "GPG_KEYRING_VERIFY", &gpg_keyring_verify },
-       { "GPG_SIGN_AS", &gpg_sign_as },
-       { "IGNORE_PROXY", &ignore_proxy },
-       { "IGNORE_URL", &ignore_advisories },
-       { "PKG_PATH", &config_pkg_path },
-       { "PKGVULNDIR", &pkg_vulnerabilities_dir },
-       { "PKGVULNURL", &pkg_vulnerabilities_url },
-       { "VERBOSE_NETIO", &verbose_netio },
-       { "VERIFIED_INSTALLATION", &verified_installation },
-       { NULL, NULL }
+       { "ACCEPTABLE_LICENSES", &acceptable_licenses, 0 },
+       { "ACTIVE_FTP", &active_ftp, 0 },
+       { "CERTIFICATE_ANCHOR_PKGS", &certs_packages, 0 },
+       { "CERTIFICATE_ANCHOR_PKGVULN", &certs_pkg_vulnerabilities, 0 },
+       { "CERTIFICATE_CHAIN", &cert_chain_file, 0 },
+       { "CHECK_LICENSE", &do_license_check, 0 },
+       { "CHECK_VULNERABILITIES", &check_vulnerabilities, 0 },
+       { "DEFAULT_ACCEPTABLE_LICENSES", &default_acceptable_licenses, 0 },
+       { "GPG", &gpg_cmd, 0 },
+       { "GPG_KEYRING_PKGVULN", &gpg_keyring_pkgvuln, 0 },
+       { "GPG_KEYRING_SIGN", &gpg_keyring_sign, 0 },
+       { "GPG_KEYRING_VERIFY", &gpg_keyring_verify, 0 },
+       { "GPG_SIGN_AS", &gpg_sign_as, 0 },
+       { "IGNORE_PROXY", &ignore_proxy, 0 },
+       { "IGNORE_URL", &ignore_advisories, 0 },
+       { "PKG_PATH", &config_pkg_path, 1 },
+       { "PKGVULNDIR", &pkg_vulnerabilities_dir, 0 },
+       { "PKGVULNURL", &pkg_vulnerabilities_url, 0 },
+       { "VERBOSE_NETIO", &verbose_netio, 0 },
+       { "VERIFIED_INSTALLATION", &verified_installation, 0 },
+       { "PKG_CREATE_USERGROUP", &pkg_create_usergroup, 1 },
+       { "PKG_CONFIG", &pkg_config, 1 },
+       { "PKG_CONFIG_PERMS", &pkg_config_perms, 1 },
+       { "PKG_RCD_SCRIPTS", &pkg_rcd_scripts, 1 },
+       { "PKG_UPDATE_FONTS_DB", &pkg_update_fonts_db, 1 },
+       { "FONTS_VERBOSE", &fonts_verbose, 1 },
+       { "INFO_FILES_VERBOSE", &info_files_verbose, 1 },
+       { "PKG_REGISTER_SHELLS", &pkg_register_shells, 1 },
+       { "RCD_SCRIPTS_DIR", &rcd_scripts_dir, 1 },
+       { "RC_SUBR_DIR", &rc_subr_dir, 1 },
+       { NULL, NULL, 0 }
 };
 
 char *config_tmp_variables[sizeof config_variables/sizeof config_variables[0]];
@@ -128,6 +149,11 @@ parse_pkg_install_conf(void)
                                continue;
                        line += var_len + 1;
                        len -= var_len + 1;
+                       /* handle "VAR= value" lines! */
+                       if (*line == ' ') {
+                               line++;
+                               len--;
+                       }
                        if (config_tmp_variables[i])
                                value = xasprintf("%s\n%.*s",
                                    config_tmp_variables[i], (int)len, line);
@@ -143,6 +169,13 @@ parse_pkg_install_conf(void)
                if (config_tmp_variables[i] == NULL)
                        continue;
                *var->var = config_tmp_variables[i];
+               if (var->export) {
+                       if ((value = getenv(var->name)) != NULL) {
+                               *var->var = value;
+                       } else {
+                               setenv(var->name, *var->var, 0);
+                       }
+               }
                config_tmp_variables[i] = NULL;
        }
 


Home | Main Index | Thread Index | Old Index