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 2c61a5fccd7b12f8d1598098030aaa702cf1b792..1b6866cd97b9582d3bb782b891597aafea2f6723 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 64ee70a00c401244e8a8e7c1d0c06a2a142d1250..c75acb6cd2144623fe0457a558619c56c0ec09db 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 775b656408cc47ec5ac704519ea1acd264856155..be98c7bf1e623fa82fdbee07f25fb0dce472f658 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);