Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am maintaining a debian package, which includes some config files that are installed under /etc/. Is there a way I can somehow make the package to always automatically --purge itself whenever a user does a regular apt-get remove mypackage ?

The reason is that I have some config files in /etc that should really be removed when the binaries are removed, otherwise it can lead to weird behavior. However I still want to treat them as conf files, i.e. make sure apt does not just wipe them on every upgrade of the package. But they should be removed when the package is uninstalled.

Currently I am manually deleting the /etc conf files in my postrm script. However I just found out that this has a unfortunate side effect: if the user uninstalls and then later re-installs the package, the conf files won't be reinstalled, because apt thinks that they are still there. So is there a way I can manually trigger a full 'purge' in my postrm, such that apt knows that the conf files are gone?

share|improve this question
    
Can you elaborate more on what is going wrong? Is it perhaps a crontab or something erroring when the binary is missing? You should add logic to your crontabs or anything else to only run if the package is actually installed. –  Zoredache Oct 18 '12 at 8:17

3 Answers 3

up vote 4 down vote accepted

The debian policy forbids you from messing around with files that belong to other packages and/or system changes. (or at least I think it does)

Teach your users

You may instruct users to use purge instead of remove:

sudo apt-get purge mypackage

Automatic overwrite

If you need to overwrite configuration files, debian may prompt the user to install the maintainer configuration files: http://www.debian.org/doc/manuals/maint-guide/dother.en.html#conffiles

One of the most annoying things about software is when you spend a great deal of time and effort customizing a program, only to have an upgrade stomp all over your changes. Debian solves this problem by marking such configuration files as conffiles. [55] When you upgrade a package, you'll be asked whether you want to keep your old configuration files or not.

Force new configuration files by default

You may do that automatically while upgrading:

apt-get -o Dpkg::Options::="--force-confnew" dist-upgrade

Sources: http://raphaelhertzog.com/2010/09/21/debian-conffile-configuration-file-managed-by-dpkg/ and http://askubuntu.com/a/104912/5538

Provides/Conflicts/Replaces

I'm not sure about this, but I think you may can fully purge and replace an old package version with a new package version.

Read here: http://www.debian.org/doc/debian-policy/ch-relationships.html#s-replaces

share|improve this answer

open the terminal and type this command.

alias remove='apt-get remove --purge

It will create an alias called remove and define it to include remove --purge

share|improve this answer
    
Alias is for apt-get remove --purge right? remove by itself is another command/function. –  saji89 Oct 18 '12 at 6:05
    
Thats not what I meant. I am a package developer, and I would like this to apply to anyone who install my package. I rephrased the post a bit, hopefully it is clear now. –  Jeroen Oct 18 '12 at 6:25
    
@Jeroen Oh sorry. I misunderstood you –  Suhaib Oct 18 '12 at 20:10
    
@saji89 Yea, I had the same idea. But when I typed alias in the terminal it showed me this alias ls='ls --color=auto' so a you can see that the command ls is already assigned to another command ls --color=auto –  Suhaib Oct 18 '12 at 20:12
1  
@Suhaib, I think you got me wrong. I meant that you should change the alias to alias remove='apt-get remove --purge'. And not an alias to remove --purge as you have told. –  saji89 Oct 19 '12 at 3:59

I occasionally run aptitude purge '~c' which purges everything that hasn't been purged before. Encourage people to do that.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.