You are not logged in.

#1 2021-09-06 20:38:37

MountainX
Member
Registered: 2016-02-08
Posts: 371

Working on pacman hook for btrbk. How to skip action on removing pkg?

I am working on pacman hooks that use btrbk to create pre/post btrfs snapshots. I've been using snapper and snap-pac previously, but I prefer btrbk over snapper. I do not find any btrbk package for pacman hooks, so I am working on something.

Assume this package will be named btrbk-pac. (Although btrbk-pacman-hook is another option.)

In the case where btrbk-pac is being uninstalled, it might be best to not run the pre-hook. I'm not sure how to accomplish that. Can anyone suggest how?

The normal pre-hook and post hook look like the following:

# cat /usr/share/libalpm/hooks/05-btrbk-pac-pre.hook

[Trigger]
Operation = Upgrade
Operation = Install
Operation = Remove
Type = Package
Target = *

[Action]
Description = Performing btrbk pre-pacman snapshots for the following configurations...
Depends = btrbk-pac
When = PreTransaction
Exec = /usr/bin/btrbk run root --preserve --override=snapshot_create=always
NeedsTargets
AbortOnFail
# cat /usr/share/libalpm/hooks/zz-btrbk-pac-post.hook

[Trigger]
Operation = Upgrade
Operation = Install
Operation = Remove
Type = Package
Target = *

[Action]
Description = Performing btrbk post-pacman snapshots for the following configurations...
Depends = btrbk-pac
When = PostTransaction
Exec = /usr/bin/btrbk run root --preserve --override=snapshot_create=always
NeedsTargets

How does that look?

The btrbk command in the hooks filters on "root". It depends upon the btrbk.conf file having a "root" item defined. That config item that matches the filter can be a group-name, volume-directory, etc. as per the btrbk man page. (I would recommend configuring a "root" group in the btrbk.conf file for this hook.)

Last edited by MountainX (2021-09-06 22:08:33)

Offline

#2 2021-09-06 20:44:11

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 21,427

Re: Working on pacman hook for btrbk. How to skip action on removing pkg?

Have you tried a second target line for the negation? I.e.

Target = *
Target = !btrbk-pac

Last edited by V1del (2021-09-06 20:45:13)

Offline

#3 2021-09-06 22:00:24

MountainX
Member
Registered: 2016-02-08
Posts: 371

Re: Working on pacman hook for btrbk. How to skip action on removing pkg?

V1del wrote:

Have you tried a second target line for the negation? I.e.

Target = *
Target = !btrbk-pac

I thought about that, but the inverted target !btrbk-pac needs to affect only the Remove operation and that's the issue that I got stuck on.

Offline

#4 2021-09-06 22:38:51

MountainX
Member
Registered: 2016-02-08
Posts: 371

Re: Working on pacman hook for btrbk. How to skip action on removing pkg?

In case anybody wants to try it out:

filename: PKGBUILD

# Maintainer: TODO
# Contributor: TODO

pkgname=btrbk-pac
pkgver=1.0.r4
pkgrel=1
pkgdesc="pacman hooks that use btrbk to create pre/post btrfs snapshots"
arch=('any')
url="TODO"
license=('GPL')
depends=('btrbk')
makedepends=('git')
source=("git+${url}")
sha256sums=('SKIP')

package() {
  cd "$srcdir/${pkgname}"

	install -m 0755 -d $pkgdir/usr/share/licenses/$pkgname
	install -m 0644 LICENSE $pkgdir/usr/share/licenses/$pkgname

	install -m 0755 -d $pkgdir/usr/share/doc/$pkgname
	install -m 0644 README.md $pkgdir/usr/share/doc/$pkgname

	install -m 0755 -d $pkgdir/usr/share/libalpm/hooks
	install -m 0644 05-btrbk-pac-pre.hook $pkgdir/usr/share/libalpm/hooks
	install -m 0644 zz-btrbk-pac-post.hook $pkgdir/usr/share/libalpm/hooks
}

filename: 05-btrbk-pac-pre.hook

[Trigger]
Operation = Upgrade
Operation = Install
Operation = Remove
Type = Package
Target = *

[Action]
Description = Performing btrbk pre-pacman snapshots for the following configurations...
Depends = btrbk-pac
When = PreTransaction
Exec = /usr/bin/btrbk run root --preserve --override=snapshot_create=always

filename: zz-btrbk-pac-post.hook

[Trigger]
Operation = Upgrade
Operation = Install
Operation = Remove
Type = Package
Target = *

[Action]
Description = Performing btrbk post-pacman snapshots for the following configurations...
Depends = btrbk-pac
When = PostTransaction
Exec = /usr/bin/btrbk run root --preserve --override=snapshot_create=always

filename: README.md

# btrbk-pac

pacman hooks that use btrbk to create pre/post btrfs snapshots on Arch Linux

filename: LICENSE 
Any license can be used afaic, but a file by this name is required by the PKGBUILD

Note: I am thinking of adding the `--quiet` option to the `Exec` command in the hooks. Currently, the btrbk output is shown in the pacman stdout. That was nice during testing, but it may be a bit much on continued use.

I will come back to address the issue of uninstalling btrbk-pac itself as soon as I understand how to do it.

Last edited by MountainX (2021-09-06 22:39:40)

Offline

Board footer

Powered by FluxBB