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:
parent
db1227ab76
commit
4148b5e4b6
4 changed files with 53 additions and 12 deletions
2
doc/TODO
2
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.
|
||||
|
|
|
@ -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_ */
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue