7

I'm making a deb package to install a custom application. I changed all files/folders ownership to root in order to avoid the warnings I was getting during installation, and in Ubuntu all runs smoothly, as Ubuntu changes the ownership of the files/folders to the user installing the package.

But when I'm installing on Debian, root remains the owner. The application uses a folder to write data, and here is the problem. Running as a standard user, the app does not have permission to write on the folder.

Now, how should I deal with this problem? Should I make a post install script on the deb package, doing the chmod o+w? Should I package the directory already with those permissions set?

Or is there any way of setting the owner of the files to the user that installs the app automatically (like Ubuntu does)?

7
  • 1
    A little more context might be helpful. I'm unclear why you need custom permissions. Can you elaborate? Commented Feb 24, 2016 at 20:14
  • Root owns the folder, but the program is run by standard user. When the program attempts to write on the folder, it fails due to lack of permissions. Commented Feb 25, 2016 at 8:48
  • Well, ok, but why is it set up this way, and do you have the ability to change it? Needless to say, this isn't a standard setup. One way to go is to create a system user/group for that program. There are many such on your system. You can see them in /etc/group. Regular owners do not normally own system files. Commented Feb 25, 2016 at 10:03
  • 1
    Note that if you are installing using a deb, then you should not install in /usr/local. That would be a violation of the FHS and Debian policy, and generally a bad idea. I recommend using a proper build system. Both autotools and cmake are popular. A handwritten makefile or similar is also an option, but would require more manual work. Commented Feb 25, 2016 at 11:21
  • 2
    Debs are by definition not locally installed. Commented Feb 25, 2016 at 14:22

2 Answers 2

13

I'm not sure what the behaviour is in Ubuntu, but in general for a .deb package containing files or directories with non-standard permissions you need to ensure those permissions are set after dh_fixperms is run. If you're using a dh-style rules, you can do this as follows:

override_dh_fixperms:
        dh_fixperms
        chmod o+w debian/yourpackage/yourfolder

or

execute_after_dh_fixperms:
        chmod o+w debian/yourpackage/yourfolder

You can also do this in a postinst:

if [ "$1" = "configure" ]; then
    chmod o+w yourfolder
fi

but the rules approach is simpler (at least, I prefer doing that rather than relying on maintainer scripts).

There are more examples in the dh man page.

2

I don't have the reputation to comment, so I'm providing another answer.

I created a directory using dh_installdirs, but I couldn't get "override_dh_fixperms" or the newer "execute_after_dh_fixperms" rules to work. I tried a variety of paths including "debian/<package_name>/path/to/dir" as per "https://manpages.debian.org/testing/debhelper/dh.1.en.html"

Ultimately, the only thing that worked was providing a "postinst" script. I would have preferred to specify the permissions in "rules", but sometimes you just have to do what it takes.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.