From 4148b5e4b62eb8d958c85c4579aa3b1b252450ae Mon Sep 17 00:00:00 2001 From: Juan RP Date: Sun, 28 Dec 2008 08:44:01 +0100 Subject: [PATCH] Added support for pre/post installation script with binary packages. For now all is handled in a script "prepost-action.sh" in package's metadata directory, with a target in the shell script. --HG-- extra : convert_revision : 93ed92d9fbb12939c751354cff464cc097379520 --- doc/TODO | 2 -- include/plist.h | 4 ++-- lib/install.c | 53 ++++++++++++++++++++++++++++++++++++++++------- shutils/binpkg.sh | 6 +++++- 4 files changed, 53 insertions(+), 12 deletions(-) diff --git a/doc/TODO b/doc/TODO index 23edba3c12..ba31b036fb 100644 --- a/doc/TODO +++ b/doc/TODO @@ -13,6 +13,4 @@ Packages: build the binary package. xbps-bin: - * Add support to handle {pre,post} install/remove scripts in - binary packages. * Add support to handle conf_files and keep_dirs from package metadata. diff --git a/include/plist.h b/include/plist.h index c76fd01faa..00c6346a62 100644 --- a/include/plist.h +++ b/include/plist.h @@ -164,8 +164,8 @@ int xbps_install_binary_pkg(const char *, const char *); int xbps_install_binary_pkg_from_repolist(prop_object_t, void *, bool *); int xbps_register_pkg(const char *, const char *, const char *); int xbps_unpack_binary_pkg(prop_dictionary_t, prop_dictionary_t, - int (*cb)(struct archive *)); -int xbps_unpack_archive_cb(struct archive *); + int (*cb)(struct archive *, const char *)); +int xbps_unpack_archive_cb(struct archive *, const char *); bool xbps_pkg_has_rundeps(prop_dictionary_t); #endif /* !_XBPS_PLIST_H_ */ diff --git a/lib/install.c b/lib/install.c index d7dfb545fd..db685d5e05 100644 --- a/lib/install.c +++ b/lib/install.c @@ -259,32 +259,75 @@ xbps_register_pkg(const char *pkgname, const char *version, const char *desc) ARCHIVE_EXTRACT_UNLINK int -xbps_unpack_archive_cb(struct archive *ar) +xbps_unpack_archive_cb(struct archive *ar, const char *pkgname) { struct archive_entry *entry; + char buf[PATH_MAX]; int rv = 0, flags; + bool actgt = false; if (geteuid() == 0) flags = EXTRACT_FLAGS; else flags = 0; + if (snprintf(buf, sizeof(buf) - 1, ".%s/metadata/%s/prepost-action.sh", + XBPS_META_PATH, pkgname) < 0) + return -1; + while (archive_read_next_header(ar, &entry) == ARCHIVE_OK) { + /* + * Run the pre installation action target if there's a script + * before writing data to disk. + */ + if (strcmp(buf, archive_entry_pathname(entry)) == 0) { + actgt = true; + + if ((rv = archive_read_extract(ar, entry, flags)) != 0) + break; + + if ((rv = xbps_file_exec(buf, "preinst")) != 0) { + printf("%s: preinst action target error %s\n", + pkgname, strerror(errno)); + (void)fflush(stdout); + break; + } + + /* pass to the next entry if successful */ + continue; + } + /* + * Extract all data from the archive now. + */ if ((rv = archive_read_extract(ar, entry, flags)) != 0) { printf("\ncouldn't unpack %s (%s), exiting!\n", archive_entry_pathname(entry), strerror(errno)); + (void)fflush(stdout); archive_entry_free(entry); break; } } + if (rv == 0 && actgt) { + /* + * Run the post installaction action target, if package + * contains the script. + */ + if ((rv = xbps_file_exec(buf, "postinst")) != 0) { + printf("%s: postinst action target error %s\n", + pkgname, strerror(errno)); + (void)fflush(stdout); + } + } + archive_read_finish(ar); + return rv; } int xbps_unpack_binary_pkg(prop_dictionary_t repo, prop_dictionary_t pkg, - int (*cb)(struct archive *)) + int (*cb)(struct archive *, const char *)) { prop_string_t pkgname, version, filename, repoloc; struct archive *ar; @@ -333,11 +376,7 @@ xbps_unpack_binary_pkg(prop_dictionary_t repo, prop_dictionary_t pkg, return rv; } - if ((rv = (*cb)(ar)) == 0) { - printf("done.\n"); - (void)fflush(stdout); - } - + rv = (*cb)(ar, prop_string_cstring_nocopy(pkgname)); free(binfile); return rv; diff --git a/shutils/binpkg.sh b/shutils/binpkg.sh index f91fd07dac..d922d11bbe 100644 --- a/shutils/binpkg.sh +++ b/shutils/binpkg.sh @@ -133,7 +133,11 @@ xbps_make_binpkg() cd $destdir || exit 1 - run_rootcmd tar cfjp $XBPS_DESTDIR/$binpkg . + # + # Sort the tar archive to have a chance that metadata is at + # the beginning. + # + run_rootcmd tar cfjp $XBPS_DESTDIR/$binpkg . | sort -r if [ $? -eq 0 ]; then [ ! -d $XBPS_PACKAGESDIR ] && mkdir -p $XBPS_PACKAGESDIR mv -f $XBPS_DESTDIR/$binpkg $XBPS_PACKAGESDIR