libopkg: pass PKG_UPGRADE variable to package scripts
authorJo-Philipp Wich <jo@mein.io>
Fri, 10 Feb 2017 09:31:55 +0000 (10:31 +0100)
committerJo-Philipp Wich <jo@mein.io>
Fri, 10 Feb 2017 09:33:29 +0000 (10:33 +0100)
When installing or upgrading packages, pass an PKG_UPGRADE environment
variable to maintainer scripts to allow the to perform different actions
depending on whether a package is freshly installed or upgraded.

During installs the PKG_UPGRADE variable will be set to 0 and during
upgrades to 1.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
libopkg/opkg_install.c
libopkg/pkg.c
libopkg/pkg.h

index 2c61a5f..1b6866c 100644 (file)
@@ -1405,9 +1405,11 @@ opkg_install_pkg(pkg_t *pkg, int from_upgrade)
          opkg_state_changed++;
          pkg->state_flag |= SF_FILELIST_CHANGED;
 
-         if (old_pkg)
+         if (old_pkg) {
                pkg_remove_orphan_dependent(pkg, old_pkg);
-
+              old_pkg->is_upgrade = 1;
+              pkg->is_upgrade = 1;
+         }
          /* XXX: BUG: we really should treat replacement more like an upgrade
           *      Instead, we're going to remove the replacees
           */
@@ -1466,7 +1468,7 @@ opkg_install_pkg(pkg_t *pkg, int from_upgrade)
          }
 
 
-         opkg_msg(INFO, "Installing maintainer scripts.\n");
+         opkg_msg(INFO, "%s maintainer scripts.\n", (pkg->is_upgrade) ? ("Upgrading") : ("Installing"));
          if (install_maintainer_scripts(pkg, old_pkg)) {
                opkg_msg(ERROR, "Failed to extract maintainer scripts for %s."
                               " Package debris may remain!\n",
index 64ee70a..c75acb6 100644 (file)
@@ -1285,6 +1285,12 @@ pkg_run_script(pkg_t *pkg, const char *script, const char *args)
      setenv("PKG_ROOT",
            pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir, 1);
 
+       if (pkg->is_upgrade)
+               setenv("PKG_UPGRADE", "1", 1);
+       else
+               setenv("PKG_UPGRADE", "0", 1);
+
+
      if (! file_exists(path)) {
          free(path);
          return 0;
index 775b656..be98c7b 100644 (file)
@@ -184,6 +184,7 @@ struct pkg
      /* this flag specifies whether the package was installed to satisfy another
       * package's dependancies */
      int auto_installed;
+     int is_upgrade;
 };
 
 pkg_t *pkg_new(void);