Split installation/removal parts in prepost-action scripts.
There are two scripts that can be used now: - prepost-inst: for pre/post actions at installation. - prepost-rm: for pre/post actions at removal. --HG-- extra : convert_revision : 5e054758f549f5c81693b825795fbb36e2d5513a
This commit is contained in:
parent
388dd30b45
commit
6c252d43d4
8 changed files with 33 additions and 29 deletions
|
@ -9,7 +9,8 @@ with bzip2 and has the following structure:
|
||||||
/var/cache/xbps/metadata/$pkgname
|
/var/cache/xbps/metadata/$pkgname
|
||||||
/var/cache/xbps/metadata/$pkgname/flist
|
/var/cache/xbps/metadata/$pkgname/flist
|
||||||
/var/cache/xbps/metadata/$pkgname/props.plist
|
/var/cache/xbps/metadata/$pkgname/props.plist
|
||||||
/var/cache/xbps/metadata/$pkgname/postpre-action
|
/var/cache/xbps/metadata/$pkgname/prepost-inst
|
||||||
|
/var/cache/xbps/metadata/$pkgname/prepost-rm
|
||||||
|
|
||||||
Metadata info is stored in the "/var/cache/xbps/metadata/$pkgname"
|
Metadata info is stored in the "/var/cache/xbps/metadata/$pkgname"
|
||||||
directory and two files will be always be present: flist and props.plist.
|
directory and two files will be always be present: flist and props.plist.
|
||||||
|
@ -56,10 +57,8 @@ has the following structure:
|
||||||
...
|
...
|
||||||
</dict>
|
</dict>
|
||||||
|
|
||||||
The prepost-action is an executable script/command that allows you to
|
The prepost-* executables allows you to trigger any action
|
||||||
trigger any action at pre/post installation/removal of the binary
|
at pre/post installation/removal of the binary package.
|
||||||
package. If return value is not 0, the package won't be registered into
|
|
||||||
the database.
|
|
||||||
|
|
||||||
The package's dictionary will also be written into the repository's package
|
The package's dictionary will also be written into the repository's package
|
||||||
index file, that describes information about a binary package on it.
|
index file, that describes information about a binary package on it.
|
||||||
|
|
2
doc/TODO
2
doc/TODO
|
@ -5,7 +5,7 @@ xbps-src:
|
||||||
* More robust and fast dependency checking.
|
* More robust and fast dependency checking.
|
||||||
* $version needs to have a dot to be found by xbps.sh.
|
* $version needs to have a dot to be found by xbps.sh.
|
||||||
Some packages do not have a dot on its version, like udev-130.
|
Some packages do not have a dot on its version, like udev-130.
|
||||||
* Add support to run the prepost-action scripts, so that the same actions are
|
* Add support to run the prepost-* scripts, so that the same actions are
|
||||||
performed in source/bin packages.
|
performed in source/bin packages.
|
||||||
|
|
||||||
xbps-cmpver:
|
xbps-cmpver:
|
||||||
|
|
|
@ -269,7 +269,7 @@ xbps_unpack_archive_cb(struct archive *ar, prop_dictionary_t pkg)
|
||||||
{
|
{
|
||||||
struct archive_entry *entry;
|
struct archive_entry *entry;
|
||||||
size_t len;
|
size_t len;
|
||||||
const char *prepost = "./XBPS_PREPOST_ACTION";
|
const char *prepost = "./XBPS_PREPOST_INSTALL";
|
||||||
const char *pkgname, *version;
|
const char *pkgname, *version;
|
||||||
char *buf;
|
char *buf;
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
|
@ -282,15 +282,15 @@ xbps_unpack_archive_cb(struct archive *ar, prop_dictionary_t pkg)
|
||||||
prop_dictionary_get_cstring_nocopy(pkg, "version", &version);
|
prop_dictionary_get_cstring_nocopy(pkg, "version", &version);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This length is '.%s/metadata/%s/prepost-action' not
|
* This length is '.%s/metadata/%s/prepost-inst' not
|
||||||
* including nul.
|
* including nul.
|
||||||
*/
|
*/
|
||||||
len = strlen(XBPS_META_PATH) + strlen(pkgname) + 26;
|
len = strlen(XBPS_META_PATH) + strlen(pkgname) + 24;
|
||||||
buf = malloc(len + 1);
|
buf = malloc(len + 1);
|
||||||
if (buf == NULL)
|
if (buf == NULL)
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
|
|
||||||
if (snprintf(buf, len + 1, ".%s/metadata/%s/prepost-action",
|
if (snprintf(buf, len + 1, ".%s/metadata/%s/prepost-inst",
|
||||||
XBPS_META_PATH, pkgname) < 0) {
|
XBPS_META_PATH, pkgname) < 0) {
|
||||||
free(buf);
|
free(buf);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -310,7 +310,7 @@ xbps_unpack_archive_cb(struct archive *ar, prop_dictionary_t pkg)
|
||||||
EXTRACT_FLAGS)) != 0)
|
EXTRACT_FLAGS)) != 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if ((rv = xbps_file_exec(buf, chroot_dir, "preinst",
|
if ((rv = xbps_file_exec(buf, chroot_dir, "pre",
|
||||||
pkgname, version, NULL)) != 0) {
|
pkgname, version, NULL)) != 0) {
|
||||||
printf("%s: preinst action target error %s\n",
|
printf("%s: preinst action target error %s\n",
|
||||||
pkgname, strerror(errno));
|
pkgname, strerror(errno));
|
||||||
|
@ -338,7 +338,7 @@ xbps_unpack_archive_cb(struct archive *ar, prop_dictionary_t pkg)
|
||||||
* Run the post installaction action target, if package
|
* Run the post installaction action target, if package
|
||||||
* contains the script.
|
* contains the script.
|
||||||
*/
|
*/
|
||||||
if ((rv = xbps_file_exec(buf, chroot_dir, "postinst",
|
if ((rv = xbps_file_exec(buf, chroot_dir, "post",
|
||||||
pkgname, version, NULL)) != 0) {
|
pkgname, version, NULL)) != 0) {
|
||||||
printf("%s: postinst action target error %s\n",
|
printf("%s: postinst action target error %s\n",
|
||||||
pkgname, strerror(errno));
|
pkgname, strerror(errno));
|
||||||
|
|
12
lib/remove.c
12
lib/remove.c
|
@ -96,21 +96,21 @@ xbps_remove_binary_pkg(const char *pkgname, const char *destdir)
|
||||||
return ENOENT;
|
return ENOENT;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This length is '%s%s/metadata/%s/prepost-action' not
|
* This length is '%s%s/metadata/%s/prepost-rm' not
|
||||||
* including nul.
|
* including nul.
|
||||||
*/
|
*/
|
||||||
len = strlen(XBPS_META_PATH) + strlen(destdir) + strlen(pkgname) + 26;
|
len = strlen(XBPS_META_PATH) + strlen(destdir) + strlen(pkgname) + 22;
|
||||||
buf = malloc(len + 1);
|
buf = malloc(len + 1);
|
||||||
if (buf == NULL)
|
if (buf == NULL)
|
||||||
return errno;
|
return errno;
|
||||||
|
|
||||||
if (snprintf(buf, len + 1, "%s%s/metadata/%s/prepost-action",
|
if (snprintf(buf, len + 1, "%s%s/metadata/%s/prepost-rm",
|
||||||
destdir, XBPS_META_PATH, pkgname) < 0) {
|
destdir, XBPS_META_PATH, pkgname) < 0) {
|
||||||
free(buf);
|
free(buf);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Find out if the prepost-action file exists */
|
/* Find out if the prepost-rm file exists */
|
||||||
if ((fd = open(buf, O_RDONLY)) == -1) {
|
if ((fd = open(buf, O_RDONLY)) == -1) {
|
||||||
if (errno != ENOENT) {
|
if (errno != ENOENT) {
|
||||||
rv = errno;
|
rv = errno;
|
||||||
|
@ -120,7 +120,7 @@ xbps_remove_binary_pkg(const char *pkgname, const char *destdir)
|
||||||
/* Run the preremove action */
|
/* Run the preremove action */
|
||||||
(void)close(fd);
|
(void)close(fd);
|
||||||
prepostf = true;
|
prepostf = true;
|
||||||
if ((rv = xbps_file_exec(buf, destdir, "prerm", pkgname,
|
if ((rv = xbps_file_exec(buf, destdir, "pre", pkgname,
|
||||||
NULL)) != 0) {
|
NULL)) != 0) {
|
||||||
printf("%s: prerm action target error (%s)\n", pkgname,
|
printf("%s: prerm action target error (%s)\n", pkgname,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
|
@ -194,7 +194,7 @@ next:
|
||||||
if (rv == 0) {
|
if (rv == 0) {
|
||||||
if (((rv = xbps_unregister_pkg(pkgname)) == 0) && prepostf) {
|
if (((rv = xbps_unregister_pkg(pkgname)) == 0) && prepostf) {
|
||||||
/* Run the postremove action target */
|
/* Run the postremove action target */
|
||||||
if ((rv = xbps_file_exec(buf, destdir, "postrm",
|
if ((rv = xbps_file_exec(buf, destdir, "post",
|
||||||
pkgname, NULL)) != 0) {
|
pkgname, NULL)) != 0) {
|
||||||
printf("%s: postrm action target error (%s)\n",
|
printf("%s: postrm action target error (%s)\n",
|
||||||
pkgname, strerror(errno));
|
pkgname, strerror(errno));
|
||||||
|
|
|
@ -125,10 +125,15 @@ _EOF
|
||||||
chmod 644 $metadir/*
|
chmod 644 $metadir/*
|
||||||
rm -f $TMPFLIST $TMPFPROPS
|
rm -f $TMPFLIST $TMPFPROPS
|
||||||
|
|
||||||
if [ -f "$XBPS_TEMPLATESDIR/$pkgname.prepost-action" ]; then
|
if [ -f "$XBPS_TEMPLATESDIR/$pkgname.prepost-inst" ]; then
|
||||||
cp -f $XBPS_TEMPLATESDIR/$pkgname.prepost-action \
|
cp -f $XBPS_TEMPLATESDIR/$pkgname.prepost-inst \
|
||||||
$destdir/XBPS_PREPOST_ACTION
|
$destdir/XBPS_PREPOST_INSTALL
|
||||||
chmod +x $destdir/XBPS_PREPOST_ACTION
|
chmod +x $destdir/XBPS_PREPOST_INSTALL
|
||||||
|
fi
|
||||||
|
if [ -f "$XBPS_TEMPLATESDIR/$pkgname.prepost-rm" ]; then
|
||||||
|
cp -f $XBPS_TEMPLATESDIR/$pkgname.prepost-rm \
|
||||||
|
$metadir/prepost-rm
|
||||||
|
chmod +x $metadir/prepost-rm
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,9 +8,9 @@ export PATH="/bin:/sbin:/usr/bin:/usr/sbin"
|
||||||
# $4 = version
|
# $4 = version
|
||||||
|
|
||||||
case "$2" in
|
case "$2" in
|
||||||
preinst)
|
pre)
|
||||||
;;
|
;;
|
||||||
postinst)
|
post)
|
||||||
echo "Running $3-$4 post-installation command..."
|
echo "Running $3-$4 post-installation command..."
|
||||||
if [ "$1" = "NOTSET" ]; then
|
if [ "$1" = "NOTSET" ]; then
|
||||||
run_cmd="/sbin/genrunlevel --all"
|
run_cmd="/sbin/genrunlevel --all"
|
|
@ -8,9 +8,9 @@ export PATH="/bin:/sbin:/usr/bin:/usr/sbin"
|
||||||
# $4 = version
|
# $4 = version
|
||||||
|
|
||||||
case "$2" in
|
case "$2" in
|
||||||
preinst)
|
pre)
|
||||||
;;
|
;;
|
||||||
postinst)
|
post)
|
||||||
echo "Running $3-$4 post-installation command..."
|
echo "Running $3-$4 post-installation command..."
|
||||||
if [ "$1" = "NOTSET" ]; then
|
if [ "$1" = "NOTSET" ]; then
|
||||||
if $(mount|grep "^/proc" 2>&1 >/dev/null); then
|
if $(mount|grep "^/proc" 2>&1 >/dev/null); then
|
|
@ -44,9 +44,9 @@ _EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
case "$2" in
|
case "$2" in
|
||||||
preinst)
|
pre)
|
||||||
;;
|
;;
|
||||||
postinst)
|
post)
|
||||||
if [ "$1" = "NOTSET" ]; then
|
if [ "$1" = "NOTSET" ]; then
|
||||||
run_cmd="pwconv"
|
run_cmd="pwconv"
|
||||||
else
|
else
|
||||||
|
@ -58,7 +58,7 @@ postinst)
|
||||||
|
|
||||||
if [ ! -f ./etc/shadow ]; then
|
if [ ! -f ./etc/shadow ]; then
|
||||||
echo "Enabling shadow passwords..."
|
echo "Enabling shadow passwords..."
|
||||||
${run_cmd}
|
${run_cmd}
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
Loading…
Reference in a new issue