Ubuntu – How to create directory and change it’s owner with the deb package


I need to create deb package that will create directory for logs. I want to create directory /var/logs/my_package and to change it's owner to my_user.

In the docs there is information that I can create file debian/dir. But there is info that this is not the best way to do it. And there is no info how one should change there directory owner (I'm thinking about placing command chown my_user.my_user /var/logs/my_packageit in debian/postinst file).

What is the recommended way to create directory with the deb package?

Best Answer

  • You were right, you need a debian/my_package.postinst file to perform such operation:

    set -e
    mkdir -p ${DIR}    
    if id -u ${USER} > /dev/null 2>&1; then    
        chown ${USER}:${USER} ${DIR}

    Note: The script checks if the user exists before calling chown.