Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

The default nginx package creates a symlink named default in the sites-enabled dir, which points to a default config file in sites-available. I'm currently creating a package for an app that sits on top of Nginx, and I want to remove or move away the default symlink, and replace it with the config file from my package. Ideally, in the event that my package is removed, the original default symlink will be restored.

I've been reading the manpage and examples of dpkg-divert, but I don't quite see that it can do this. Is this achievable with dpkg-divert, or do I have to think of another way?

share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

If you want to divert a file owned by another package:

  • In your preinst, divert the file away.

    dpkg-divert --add --package $your_package_name --rename \
       --divert /etc/nginx/sites-available/default.disabled \
                /etc/nginx/sites-available/default
    
  • In your postrm, divert the file back.

    dpkg-divert --remove --package $your_package_name --rename \
                /etc/nginx/sites-available/default
    

This won't work for the symlink /etc/nginx/sites-enabled/default, because it's created by the nginx package's postinst rather than being part of the package. Since the symlink is part of the package, you can just rename it with mv. I don't know if this is compliant with the Debian packaging policy; if this matters to you, as this is a rather specialized question, I recommend searching or asking on debian-devel.

share|improve this answer
add comment

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.