Pages

Wednesday, 14 October 2009

Debian packaging: Changing permissions and ownership of dirs

Regarding creating users and permissions our beloved Debian Policy [chap. 10.9] tells us:
...you must arrange for your package to create the user or group if necessary using adduser in the preinst or postinst script (again, the latter is to be preferred if it is possible).

I wanted to stick to the postinst since it's preferrable so I couldn't change the permissions in the rules file.

Now the thing is I need to give this user permissions for the dirs it will need to own/write and so on. I already have the dirs listed in debian/dirs and I don't want to hardcode anything else in the rules or in the postinst. Of course not being a so experienced debian devel I started to google but didn't find anything... asked around but nothing yet... so I hacked it in this way in the end:
debian/rules:
...
MYDIRS := $(shell cat $(CURDIR)/debian/dirs)
SUBME := $(foreach dir, $(MYDIRS), chown -R \$$the_user $(dir);)
SUBFRIENDLY := $(shell echo "$(SUBME)" | sed -e 's/\//\\\//g')
...
binary-indep: build install
...
dh_installdeb
sed -i -e 's/PLACEHOLDER/$(SUBFRIENDLY)/' $(DESTDIR)/DEBIAN/postinst
...
...

debian/postinst:
...
configure)
the_user="xyz"
#Creating the user if it does not exist
if ! getent passwd $the_user > /dev/null; then
adduser $the_user
fi

#Changing the permissions for the given dirs
PLACEHOLDER
...


(user=xyz can be easily changed to numeric ID)

I don't know if this is the 'standard' way to do it (nor if there is a standard way) but it's at least a way that worked... If anybody there can give me an hint on how to do it better, it would be really appreciated.

2 comments:

  1. To complicated.

    Consider following example:

    [andy@dhcppc74 proof]$ make
    sed -e 's,@DIRS@,aaa bbb/llll/ ccc/r/l/m ddd/eee,' lss > lss.new


    [andy@dhcppc74 proof]$ sh lss.new
    aaa
    bbb/llll/
    ccc/r/l/m
    ddd/eee


    [andy@dhcppc74 proof]$ cat Makefile
    FILE = lll
    CONTENTS = $(shell cat $(FILE))
    SCRIPT = lss

    all:
    sed -e 's,@DIRS@,$(CONTENTS),' $(SCRIPT) > $(SCRIPT).new


    [andy@dhcppc74 proof]$ cat lll
    aaa
    bbb/llll/
    ccc/r/l/m
    ddd/eee


    [andy@dhcppc74 proof]$ cat lss
    DIRS="@DIRS@"

    for xdir in $DIRS; do
    echo $xdir
    done

    ReplyDelete
  2. Who can i get an in addres asked by the DEBIAN/config to the DEBIAN/postinst????????

    ReplyDelete