|
|
|
|
fertieg50
Stały
Dołączył: 24 Wrz 2010
Posty: 399
Przeczytał: 0 tematów
Ostrzeżeń: 0/5 Skąd: England
|
|
|
|
|
|
Wysłany: Wto 2:21, 12 Paź 2010 Temat postu: s complicated in “ |
|
|
What’s complicated in “rm”?
Automating everything with dpkg-maintscript-helper
Phewww… that’s a lot of things to do for a seemingly simple task. Fortunately everything can be automated with dpkg-maintscript-helper. Let’s assume you want to remove /etc/foo/conf.d/bar because it’s obsolete and you’re going to prepare a new version 1.2-1 with the appropriate code to remove the file on upgrade. You just have to put this snippet in the 3 relevant scripts (preinst, postinst,[link widoczny dla zalogowanych], postrm):
So you want to remove the conffile. Adding an “rm” command in debian/postinst sounds easy. Except it’s not the right thing to do. The conffile might contain customizations made by the administrator and you don’t want to wipe those. Instead you want to keep the file around so that he can get his changes back and do whatever is required with those.
if dpkg-maintscript-helper supports rm_conffile 2>/dev/null; then dpkg-maintscript-helper rm_conffile /etc/foo/conf.d/bar 1.2-1 -- "$@"
fi
You can avoid the preliminary test if you pre-depend on “dpkg (>= 1.15.7.2)” or if enough time has passed to assume that everybody has a newer version anyway. You can learn all the details in dpkg-maintscript-helper’s manual page.
dpkg errs on the side of safety by not removing the file until purge but in most cases it’s best to remove it sooner so as to not confuse the user. In some cases, it’s even required because keeping the file could break the software (for example if the file is in a .d configuration directory, and if it contains directives that are either no longer supported by the new version or in conflict with other new configuration files).
When is that needed?
A conffile is a configuration file managed by dpkg, I’m sure you remember the introductory article about conffiles. When your package stops providing a conffile, the file stays on disk and it’s recorded as obsolete by the package manager. It’s only removed during purge. If you want the file to go away, you have to remove it yourself within your package’s configuration scripts. You will now learn how to do this right.
The correct action is thus to move the file away in the prerm, to ensure it doesn’t disturb the new version. At the same time,[link widoczny dla zalogowanych], you need to verify whether the conffile has been modified by the administrator and remember it for later. In the postinst, you need to remove the file if it’s unmodified, or keep it under a different name that doesn’t interfere with the software. In many cases adding a simple .dpkg-bak suffix is enough. For instance,[link widoczny dla zalogowanych], run-parts ignore files that contain a dot, and many other software are configured to only include files with a certain extension―say *.conf. In the postrm, you have to remove the obsolete conffiles that were kept due to local changes and you should also restore the original conffile in case the upgrade obsoleting the conffile is aborted.
I hope you found this article helpful. You can follow me on Identi.ca, Twitter and Facebook.
Post został pochwalony 0 razy
|
|