Pregunta

My deb file installs to /opt/myCompany/myProgram, when I purge the package with dpkg -P myProgram everything is removed - even /opt (if mine is the only package with files in /opt) - How can I avoid removing the /opt folder during a purge?

I have tried checking if /opt exist in the postrm and adding it if it doesn't but no joy...It seems that the folder is deleted after the postrm script is run. Currently I am adding a hidden file in /opt with postinst - this stops opt from being removed but feels hackey - there should be a better way.

Thank you,

¿Fue útil?

Solución

That's just debian. Whenever it removes a package from a non-debian standard directory (such as /opt in your case) and there are no files left in that directory, dpkg will try to remove that directory.

If there are some other files in /opt at the time of removal, you'll get a message in the lines of "/opt is not empty; not removed" and that's it.

Another "hacky" way would be to add re-creation of /opt in postrm, but it's not way cleaner than your hidden file :)

Otros consejos

This question was asked almost 7 years ago now, but I stumbled across it in a Google search for a similar problem and thought I'd post an answer anyway, since the question has an answer that isn't really a solution.

The following question is also related (but pertains to /usr/local instead of /opt) and can be solved similarly:

dpkg: warning: while removing directory /usr/local not empty so not removed

I was able to solve this problem using the following technique.

A Debian package (.deb) is just an "ar" archive file with 3 members:

$ ar t package.deb
debian-binary
control.tar.gz
data.tar.xz

The data.tar.xz member may be named data.tar.gz depending on the age of the *.deb. Adjust commands accordingly.

The files that get installed to the target system are contained in the data.tar.xz member. If you extract the data.tar.xz member and list its contents, you will see something like the following for example.

$ ar p package.deb data.tar.xz | unzx -c | tar t
./
./opt/
./opt/myCompany/
./opt/myCompany/myProgram

Removing the ./opt/ directory member (but not its contents) from the data.tar.xz file will stop dpkg from trying to remove the /opt directory when the package is uninstalled.

$ ar x package.deb data.tar.xz
$ unzx data.tar.xz
$ tar --delete --occurrence -f data.tar ./opt/
$ #tar --delete --occurrence -f data.tar ./usr/local/

Now, if you list the contents of the data.tar file, you should see something like:

$ tar tf data.tar
./
./opt/myCompany/
./opt/myCompany/myProgram
  • Notice the ./opt/ member has been removed.

The last step is to re-compress the data.tar file and replace the data.tar.xz member in the deb with the modified one.

Here is one example of the complete process of removing the ./opt/ entry from the tar file archive and replacing the tar file archive in the deb with the modified one:

$ ar x package.deb data.tar.xz
$ unzx data.tar.xz
$ tar --delete --occurrence -f data.tar ./opt/
$ xz data.tar
$ ar r package.deb data.tar.xz
$ rm data.tar.xz

Now, dpkg will not try to remove the /opt directory when the deb is removed/uninstalled from the system.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top