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
This commit is contained in:
Juan RP 2008-12-28 08:44:01 +01:00
parent db1227ab76
commit 4148b5e4b6
4 changed files with 53 additions and 12 deletions

View file

@ -13,6 +13,4 @@ Packages:
build the binary package. build the binary package.
xbps-bin: 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. * Add support to handle conf_files and keep_dirs from package metadata.

View file

@ -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_install_binary_pkg_from_repolist(prop_object_t, void *, bool *);
int xbps_register_pkg(const char *, const char *, const char *); int xbps_register_pkg(const char *, const char *, const char *);
int xbps_unpack_binary_pkg(prop_dictionary_t, prop_dictionary_t, int xbps_unpack_binary_pkg(prop_dictionary_t, prop_dictionary_t,
int (*cb)(struct archive *)); int (*cb)(struct archive *, const char *));
int xbps_unpack_archive_cb(struct archive *); int xbps_unpack_archive_cb(struct archive *, const char *);
bool xbps_pkg_has_rundeps(prop_dictionary_t); bool xbps_pkg_has_rundeps(prop_dictionary_t);
#endif /* !_XBPS_PLIST_H_ */ #endif /* !_XBPS_PLIST_H_ */

View file

@ -259,32 +259,75 @@ xbps_register_pkg(const char *pkgname, const char *version, const char *desc)
ARCHIVE_EXTRACT_UNLINK ARCHIVE_EXTRACT_UNLINK
int int
xbps_unpack_archive_cb(struct archive *ar) xbps_unpack_archive_cb(struct archive *ar, const char *pkgname)
{ {
struct archive_entry *entry; struct archive_entry *entry;
char buf[PATH_MAX];
int rv = 0, flags; int rv = 0, flags;
bool actgt = false;
if (geteuid() == 0) if (geteuid() == 0)
flags = EXTRACT_FLAGS; flags = EXTRACT_FLAGS;
else else
flags = 0; 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) { 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) { if ((rv = archive_read_extract(ar, entry, flags)) != 0) {
printf("\ncouldn't unpack %s (%s), exiting!\n", printf("\ncouldn't unpack %s (%s), exiting!\n",
archive_entry_pathname(entry), strerror(errno)); archive_entry_pathname(entry), strerror(errno));
(void)fflush(stdout);
archive_entry_free(entry); archive_entry_free(entry);
break; 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); archive_read_finish(ar);
return rv; return rv;
} }
int int
xbps_unpack_binary_pkg(prop_dictionary_t repo, prop_dictionary_t pkg, 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; prop_string_t pkgname, version, filename, repoloc;
struct archive *ar; struct archive *ar;
@ -333,11 +376,7 @@ xbps_unpack_binary_pkg(prop_dictionary_t repo, prop_dictionary_t pkg,
return rv; return rv;
} }
if ((rv = (*cb)(ar)) == 0) { rv = (*cb)(ar, prop_string_cstring_nocopy(pkgname));
printf("done.\n");
(void)fflush(stdout);
}
free(binfile); free(binfile);
return rv; return rv;

View file

@ -133,7 +133,11 @@ xbps_make_binpkg()
cd $destdir || exit 1 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 if [ $? -eq 0 ]; then
[ ! -d $XBPS_PACKAGESDIR ] && mkdir -p $XBPS_PACKAGESDIR [ ! -d $XBPS_PACKAGESDIR ] && mkdir -p $XBPS_PACKAGESDIR
mv -f $XBPS_DESTDIR/$binpkg $XBPS_PACKAGESDIR mv -f $XBPS_DESTDIR/$binpkg $XBPS_PACKAGESDIR