1

I have this code in my PKGBUILD

package() {
        cd "$pkgname"
        install -Dm755 ./lnScript.sh "$pkgdir/opt/pycharm-professional/bin/re
lnScript.sh"
        install -Dm751 ./lnp.hook "$pkgdir/etc/pacman.d/hooks/lnp.hook"
        cd /opt/pycharm-professional/bin
        sudo patch --forward --strip=4 --input="${srcdir}/$pkgname/lnsh.pat
ch"

I need to reverse this patch when the user uninstalls the package because the original program does not belong to this package.

So, Is this possible to execute a script when is the user uninstalling an aur package?

Ron
  • 453
  • 4
  • 10

1 Answers1

0

You should get used to reading the Arch Wiki, Anyways It's Mentioned Here: https://wiki.archlinux.org/title/PKGBUILD

6.3 install

The name of the .install script to be included in the package.

pacman has the ability to store and execute a package-specific script when it installs, removes or upgrades a package. The script contains the following functions which run at different times:

  • pre_install — The script is run right before files are extracted. One argument is passed: new package version.
  • post_install — The script is run right after files are extracted. One argument is passed: new package version.
  • pre_upgrade — The script is run right before files are extracted. Two arguments are passed in the following order: new package version, old package version.
  • post_upgrade — The script is run right after files are extracted. Two arguments are passed in the following order: new package version, old package version.
  • pre_remove — The script is run right before files are removed. One argument is passed: old package version.
  • post_remove — The script is run right after files are removed. One argument is passed: old package version.

this is a sample .install file:

# This is a default template for a post-install scriptlet.
# Uncomment only required functions and remove any functions
# you don't need (and this header).

## arg 1:  the new package version
pre_install() {
    # do something here
}

## arg 1:  the new package version
post_install() {
    # do something here
}

## arg 1:  the new package version
## arg 2:  the old package version
pre_upgrade() {
    # do something here
}

## arg 1:  the new package version
## arg 2:  the old package version
post_upgrade() {
    # do something here
}

## arg 1:  the old package version
pre_remove() {
    # do something here
}

## arg 1:  the old package version
post_remove() {
    # do something here
}
Aditya
  • 1,132
  • 1
  • 9
  • 28
  • Thanks for your answer, Well, I need to reverse the patch (`--reverse`) but the patch file is in $srcdir, not in $pkgdir. They chroot into the package dir, right? in that case, I need to locate the $srcdir when the package is being removed. Is that possible? – Ron Sep 21 '22 at 05:30