My deb file removes /opt
Asked Answered
J

2

3

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,

Jolo answered 22/10, 2012 at 22:42 Comment(3)
so why do you want to remove /opt if there are no files in it anyhow?Headward
@umlaeute I want to avoid removing the /opt folder when myProgram is removed with dpkg -P.Jolo
yes i understood that; however, i was wondering why you would want to do that in the first place...maybe you could just live with the way debian handles (empty) /opt directories...Headward
M
1

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 :)

Meunier answered 23/10, 2012 at 1:42 Comment(2)
Thanks for your response - You said - non-debian standard directory (such as /opt) - what is the debian standard directory to install software in? I was using /opt because of information found here. And, I did try to recreate /opt in the postrm - but the deletion happens after postrm is run.Jolo
Yeah, FHS... FHS != Debian ;) Debian wants everything reside under /usrMeunier
B
3

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.

Barbur answered 23/9, 2019 at 15:59 Comment(0)
M
1

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 :)

Meunier answered 23/10, 2012 at 1:42 Comment(2)
Thanks for your response - You said - non-debian standard directory (such as /opt) - what is the debian standard directory to install software in? I was using /opt because of information found here. And, I did try to recreate /opt in the postrm - but the deletion happens after postrm is run.Jolo
Yeah, FHS... FHS != Debian ;) Debian wants everything reside under /usrMeunier

© 2022 - 2024 — McMap. All rights reserved.