tech-pkg archive

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

pkg_install patch to support sysutils/etckeeper



I just added sysutils/etckeeper, but to be fully support pkg_install
need to run pre and post install hooks.

The attached patch is my simple attempt at the needed hooks, does anyone
have any improvements or is this or to commit.

Notes:
1) The position in the code where the install hooks are called is important
and in the correct place.
2) The de-install hooks aren't actually needed I just added them for future
proofing.

-- 
Steven
Index: pkg_install/files/add/perform.c
===================================================================
--- pkg_install.orig/files/add/perform.c
+++ pkg_install/files/add/perform.c
@@ -1590,12 +1590,27 @@ clean_find_archive:
        return status;
 }
 
+void
+run_install_cmd(const char *cmd, const char *name)
+{
+       if (cmd == NULL || !strlen(cmd))
+               return;
+
+       if (Verbose)
+               printf("Running %s command.\n", name);
+
+       if (!Fake)
+               system(cmd);
+}
+
 int
 pkg_perform(lpkg_head_t *pkgs)
 {
        int     errors = 0;
        lpkg_t *lpp;
 
+       run_install_cmd(pre_install_cmd, "PRE_INSTALL");
+
        while ((lpp = TAILQ_FIRST(pkgs)) != NULL) {
                if (pkg_do(lpp->lp_name, Automatic, 1))
                        ++errors;
@@ -1603,5 +1618,7 @@ pkg_perform(lpkg_head_t *pkgs)
                free_lpkg(lpp);
        }
 
+       run_install_cmd(post_install_cmd, "POST_INSTALL");
+
        return errors;
 }
Index: pkg_install/files/lib/lib.h
===================================================================
--- pkg_install.orig/files/lib/lib.h
+++ pkg_install/files/lib/lib.h
@@ -444,6 +444,10 @@ extern const char *gpg_keyring_sign;
 extern const char *gpg_keyring_verify;
 extern const char *gpg_sign_as;
 extern char fetch_flags[];
+extern const char *pre_install_cmd;
+extern const char *post_install_cmd;
+extern const char *pre_deinstall_cmd;
+extern const char *post_deinstall_cmd;
 
 extern const char *pkg_vulnerabilities_dir;
 extern const char *pkg_vulnerabilities_file;
Index: pkg_install/files/lib/parse-config.c
===================================================================
--- pkg_install.orig/files/lib/parse-config.c
+++ pkg_install/files/lib/parse-config.c
@@ -85,6 +85,10 @@ 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 *pre_install_cmd = NULL;
+const char *post_install_cmd = NULL;
+const char *pre_deinstall_cmd = NULL;
+const char *post_deinstall_cmd = NULL;
 
 static struct config_variable {
        const char *name;
@@ -113,6 +117,10 @@ static struct config_variable {
        { "PKG_PATH", &config_pkg_path },
        { "PKG_REFCOUNT_DBDIR", &config_pkg_refcount_dbdir },
        { "PKGVULNDIR", &pkg_vulnerabilities_dir },
+       { "PRE_INSTALL", &pre_install_cmd },
+       { "POST_INSTALL", &post_install_cmd },
+       { "PRE_DEINSTALL", &pre_deinstall_cmd },
+       { "POST_DEINSTALL", &post_deinstall_cmd },
        { "PKGVULNURL", &pkg_vulnerabilities_url },
        { "VERBOSE_NETIO", &verbose_netio },
        { "VERIFIED_INSTALLATION", &verified_installation },
Index: pkg_install/files/lib/version.h
===================================================================
--- pkg_install.orig/files/lib/version.h
+++ pkg_install/files/lib/version.h
@@ -27,6 +27,6 @@
 #ifndef _INST_LIB_VERSION_H_
 #define _INST_LIB_VERSION_H_
 
-#define PKGTOOLS_VERSION 20130131
+#define PKGTOOLS_VERSION 20130523
 
 #endif /* _INST_LIB_VERSION_H_ */
Index: pkg_install/Makefile
===================================================================
--- pkg_install.orig/Makefile
+++ pkg_install/Makefile
@@ -7,7 +7,6 @@
 # change in the pkg_* tools that pkgsrc relies on for proper operation.
 
 DISTNAME=              pkg_install-${VERSION}
-PKGREVISION=           1
 CATEGORIES=            pkgtools
 MASTER_SITES=          # empty
 DISTFILES=             # empty
Index: pkg_install/files/delete/pkg_delete.c
===================================================================
--- pkg_install.orig/files/delete/pkg_delete.c
+++ pkg_install/files/delete/pkg_delete.c
@@ -768,6 +768,19 @@ remove_pkg(const char *pkg)
        return rv | late_error;
 }
 
+void
+run_deinstall_cmd(const char *cmd, const char *name)
+{
+       if (cmd == NULL || !strlen(cmd))
+               return;
+
+       if (Verbose)
+               printf("Running %s command.\n", name);
+
+       if (!Fake)
+               system(cmd);
+}
+
 int
 main(int argc, char *argv[])
 {
@@ -905,6 +918,8 @@ main(int argc, char *argv[])
 
        setenv(PKG_REFCOUNT_DBDIR_VNAME, pkgdb_refcount_dir(), 1);
 
+       run_deinstall_cmd(pre_deinstall_cmd, "PRE_DEINSTALL");
+
        bad_count = 0;
        while (!TAILQ_EMPTY(&sorted_pkgs)) {
                lpkg_t *lpp;
@@ -919,6 +934,8 @@ main(int argc, char *argv[])
                free_lpkg(lpp);
        }
 
+       run_deinstall_cmd(post_deinstall_cmd, "POST_DEINSTALL");
+
        pkgdb_close();
 
        if (Force && bad_count && Verbose)


Home | Main Index | Thread Index | Old Index