9.1.2. Site-specific programs

As mandated by the FHS, packages must not place any files in /usr/local, either by putting them in the file system archive to be unpacked by dpkg or by manipulating them in their maintainer scripts.

However, the package may create empty directories below /usr/local so that the system administrator knows where to place site-specific files. These are not directories in /usr/local, but are children of directories in /usr/local. These directories (/usr/local/*/dir/) should be removed on package removal if they are empty.

Note that this applies only to directories below /usr/local, not in /usr/local. Packages must not create sub-directories in the directory /usr/local itself, except those listed in FHS, section 4.9. However, you may create directories below them as you wish. You must not remove any of the directories listed in 4.9, even if you created them.

If /etc/staff-group-for-usr-local does not exist, /usr/local and all subdirectories created by packages should have permissions 0755 and be owned by root:root. If /etc/staff-group-for-usr-local exists, /usr/local and subdirectories should have permissions 2775 (group-writable and set-group-id) and be owned by root:staff.

Since /usr/local can be mounted read-only from a remote server, /usr/local/*/dir/ directories must be created and removed by the postinst and prerm maintainer scripts and not be included in the .deb archive. These scripts must not fail if either of these operations fail.

For example, the emacsen-common package could contain something like

  1. if [ ! -e /usr/local/share/emacs ]; then
  2. if mkdir /usr/local/share/emacs 2>/dev/null; then
  3. if test -e /etc/staff-group-for-usr-local ; then
  4. if chown root:staff /usr/local/share/emacs; then
  5. chmod 2775 /usr/local/share/emacs || true
  6. fi
  7. elif chown root:root /usr/local/share/emacs; then
  8. chmod 0755 /usr/local/share/emacs || true
  9. fi
  10. fi
  11. fi

in its postinst script, and

  1. rmdir /usr/local/share/emacs/site-lisp 2>/dev/null || true
  2. rmdir /usr/local/share/emacs 2>/dev/null || true

in the prerm script. (Note that this form is used to ensure that if the script is interrupted, the directory /usr/local/share/emacs will still be removed.)

If you do create a directory in /usr/local for local additions to a package, you should ensure that settings in /usr/local take precedence over the equivalents in /usr.

However, because /usr/local and its contents are for exclusive use of the local administrator, a package must not rely on the presence or absence of files or directories in /usr/local for normal operation.