Packages offering Installation Script(s)

Some of our packages offer additional installation scripts, which, in general, you can use in your postinst or postrm scripts of your project.

For example, the snaplogger is used to manage the logs of other projects using services. When such other projects are created, they are expected to run as a user other than root. This means they will not have enough permissions to create log files or write to log files unless the logs are created with their user and/or group name. This is accomplished using a postinst script which makes sure that the location where logs are created is writable by the user running the given service.

As a result, we ended up creating a set of log directories for each project and manually set the correct user name, group name, and permissions on each file and folder. If we want to change the scheme (i.e. place the secure sub-directories under /var/log-secure instead of creating a sub-directory within the project log directory), then it becomes complicated since each project postinst script has to be edited to correct that.

Instead, we now offer installation scripts. These scripts get installed under:

/usr/lib/<project-name>/inst/<script-name>

Since the script is to be sourced like the "confmodule" from the debconf package, we do not add a suffix (no ".sh").

These installation scripts take a few parameters which often include the following:

ENVIRONMENT_NAME
PROJECT_NAME
USER_NAME
GROUP_NAME

The environment name is the name of the master project. This is "snapwebsites" in that master project. In contribs, it is nearly always the same as PROJECT_NAME.

In the snaplogger, the script defines two functions. To use it in your project, you first want to source the file:

. /usr/lib/snaplogger/inst/manage-log-dirs

This generally goes at the top of the script so the commands can be used anywhere in your postinst script.

Next you use one of the following functions to create (postinst) or destroy (postrm) the log environment for your project:

# Create (postinst)
create_log_dirs ${ENVIRONMENT_NAME} ${PACKAGE_NAME} ${USER_NAME} ${GROUP_NAME} true

# Destroy (postrm)
destroy_log_dirs ${ENVIRONMENT_NAME} ${PACKAGE_NAME} ${USER_NAME} ${GROUP_NAME}

The last parameter to the "create_log_dirs" defines whether a secure sub-directory should be created (true) or not (false).

Snap! Websites
An Open Source CMS System in C++

Contact Us Directly