permissioin with deb

I cpack a deb and install it with sudo dpkg -i xx.deb.
The program will be install /opt/xxx
But the /opt/xxx permission is root:root
How can I solve it?

I add some command on the postinst script. But the user is root, not my default user sam

chown -R "$USER:$USER" "/opt/xxx"

dpkg always installs as root, so any install script is going to do that. I recommend looking at Debian packaging guidelines for how to do this properly and, if not supported, get switches to control that implemented in CPack.

Do you have the method to get the user name when run the postinst on deb

AFAIK, the postinst user is always root.