From 9ecd49641e53ae5353e2b355d7828de30b463dba Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Fri, 10 Feb 2017 10:31:55 +0100 Subject: [PATCH] libopkg: pass PKG_UPGRADE variable to package scripts 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 --- libopkg/opkg_install.c | 8 +++++--- libopkg/pkg.c | 6 ++++++ libopkg/pkg.h | 1 + 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/libopkg/opkg_install.c b/libopkg/opkg_install.c index 2c61a5f..1b6866c 100644 --- a/libopkg/opkg_install.c +++ b/libopkg/opkg_install.c @@ -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", diff --git a/libopkg/pkg.c b/libopkg/pkg.c index 64ee70a..c75acb6 100644 --- a/libopkg/pkg.c +++ b/libopkg/pkg.c @@ -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; diff --git a/libopkg/pkg.h b/libopkg/pkg.h index 775b656..be98c7b 100644 --- a/libopkg/pkg.h +++ b/libopkg/pkg.h @@ -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); -- 2.25.1