6

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?

Suan
  • 163
  • 1
  • 5

1 Answers1

6

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.