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

chowndebdirectorypackage-managementpermissions

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:

#!/bin/sh

#DEBHELPER#

set -e

DIR="/var/log/my_package/"
USER="my_user"

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

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

Related Question