Is it possible to abort a pacman installation from pre_install()

834 Views Asked by At

When creating a PKGBUILD file one can execute hooks at pre_install(), post_install(), etc.

I now have a custom arch linux pacman package that I need some custom checks done before it is installed to determine if it is safe to install or not.

I would like to run my test in the pre_istall() script and have pacman abort the installation if I say so in the script.

So, how can this be accomplished? So far all I have accomplished is getting an error message in the log but pacman continues with the istall...

2

There are 2 best solutions below

0
On

You could call a command, which returns a non-zero exit-code, to cancel the build process. The simplest command I could think of is sh -c "exit 1", since just exit 1 results in an immediate exit without any proper cleanup.

Here is a simple example that checks if a file exists and cancels the build process if not:

prepare() {
    if ! [ -f "/usr/bin/ffmpeg" ]; then
        echo "Error: FFmpeg executable '/usr/bin/ffmpeg' is missing."
        sh -c "exit 1"
    fi
}

However, galaux is right. Usually such checks should happen upstream.

0
On

I would not recommend this as it sounds like a code smell: in my opinion the pre_install() hook is designed to perform actions before package files are actually installed on your drive, but it is not meant to check whether the package should be installed.

In my opinion, such a check belongs to some other place out of the package.