I've read that if you have to use the debian/[<package>.]dirs
file, that means your make install
step did not do its job properly. That step should create that folder.
Here are the issues I can see with this:
make install
can't install anything under a directory other than /usr
(for a Debian package), so it's useless if you want a directory under /etc/...
, /var/lib/<package>/...
, etc.
If you use mkdir -p ...
in your debian/[<package>.]postinst
script, then you need to manually remove it with an rmdir ...
in your debian/[<package>.].postrm
script.
So the solution proposed by Marek Šimon is the same as mine, the only difference is that I use chown ...
instead of install -d ...
although with the install -d ...
you can avoid the debian/[<package>.]dirs
altogether. Personally, I like to see a list of the directories I create in a separate file. It looks much clearer.
Example
Create the directories:
# in debian/package.dirs
/etc/package/magic/configuration
/var/www/package/data
Change the ownership:
# in debian/rules
override_dh_fixperms:
dh_fixperms
chmod 700 debian/tmp/var/www/package/data
chown www-data:www-data debian/tmp/var/www/package/data
WARNING: The debian/rules
file uses tabs to indent the code under a target name. This is important.
As shown in the example, I also often change the permissions (chmod
).
The debian/tmp/...
introducer is required if you create two or more packages. I'm not too sure what it is if you are creating a single package (in part because it's really rare for my projects to have a single package and also many paths change when you add a second package so instead I always include at least a package-doc.install
even if mostly empty so that way it won't change on me).
Final Note
If you are creating a public Debian package which is to be accepted by Debian or Ubuntu, you probably want to follow Sylvain Pineau's solution. Keep in mind that on a purge you need to remove your directory (unless the user created its own files in it).
This generally means there is a problem with the Makefile.
I understand this message that there is some other way to do it. And I want to find out what is the recomened way to do this task. – bessarabov Apr 01 '14 at 18:30debian/rules
which is theMakefile
for debian packages. Since I didn't know yourdebian/rules
I preferred to propose a solution based on a single file. But thechown
command must be a post-installation process. debian/dirs should be avoided but my initial answer is perfectly fine. Please vote and accept it, thanks. – Sylvain Pineau Apr 01 '14 at 18:49postinst
and notpostint
. – kayn Oct 26 '20 at 12:20