Question

I have a custom built Debian package which right now installs and uninstalls fine but have a couple of issues:

  1. I would like to know how I can make the uninstall process check for a file on the disk. Let's say if file /etc/file.conf exists, I don't want the package to be uninstalled. Is that possible? I tried adding the check to prerm and postrm, but all the files installed by the package get removed anyway even IF prerm and postrm scripts exits with an error.

I am guessing there is probably a specific exit code that I should be using in those scripts?

  1. During uninstall sometimes some directories created by packages are NOT removed as they are not empty. The error is like: "dpkg: warning: while removing packagename, directory '/opt/packagename/' not empty so not removed." Is there a way to forcefully remove all files installed by the package despite the contents?

I have been through documentation a few times looking for answers, but it seems I haven't been looking at the right place.

Was it helpful?

Solution

I would like to know how I can make the uninstall process check for a file on the disk. Let's say if file /etc/file.conf exists, I don't want the package to be uninstalled. Is that possible? I tried adding the check to prerm and postrm, but all the files installed by > the package gets removed anyway even IF prerm and postrm scripts exits with an error.

A non zero exit from the prerm script will not delete all the installed files.

#!/bin/sh
if [ -x /etc/file.conf ]; then
  echo "You shall not remove me" >&2
  exit 1
fi

During uninstall sometimes some directories created by packaged are NOT removed as they are not empty. The error is like: "dpkg: warning: while removing packagename, directory '/opt/packagename/' not empty so not removed." Is there a way to forcefully remove all files installed by the package despite the contents?

The file installed by the package will be removed. That warning signals files created during the application's lifetime. You can use the postrm script to remove them.

As a side note, a package shouldn't put stuff into /opt.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top