66

Software

obarun.org

execl-envfile

A mix of s6-envdir and importas. Reads files containing variable assignments in the given file/directory, adds the variables to the environment and then executes a program.

Interface

execl-envfile [ -h ] [ -v verbosity ] [ -l ] src prog

This program expects to find a regular file or a directory in src containing one or multiple key=value pair(s). It will parse that file, import the key=value and then exec the given prog with the modified environment. In case of directory for each file found it apply the same process. src can be an absolute or a relative path.

Options

File syntax

src is a text file or a directory containing lines of pairs with the syntax being: key = value Whitespace is permitted before and after key, and before or after value.

Empty lines, or lines containing only whitespace, are ignored. Lines beginning with # (possibly after some whitespace) are ignored (and typically used for comments). Leading and trailing whitespace is stripped from values; but a value can be double-quoted, which allows for inclusion of leading and trailing whitespace.

Escaping double-quoted can be done with backslash \. For instance,

cmd_args=-g \"daemon off;\"

C escapes, including hexadecimal and octal sequences, are supported in quoted values. Unicode codepoint sequences are not supported.

If value is empty, key is still added to the environment, with an empty value.

If you do not want key to be added to the environment at all, prefix the value with an exclamation mark !. Whitespace are not permitted between the ! and value. For instance,

    socket_name=!sname

In this case the key will be removed from the environment after the substitution.

Reusing the same variable or variable from the actual environment is allowed. In such case, variable name must be between ${} to get it value. For intance, an environment file can be declared

    PATH=/usr/local/bin:${PATH}
    socket_name=sname
    socket_dir=dname
    socket=${socket_dir}/${socket_name}

The order of key=value pair declaration do not matter

    PATH=/usr/local/bin:${PATH}
    socket=${socket_dir}/${socket_name}
    socket_name=sname
    socket_dir=dname

A variable calling itself is only allowed if the key name can be found at the environment of the current process. If the key of the key=value cannot not be found it left the pair as it. For intance,

    PATH=/usr/local/bin:${PATH}

will only works if PATH is already define at the current environment. If not the result will literally be PATH=/usr/local/bin:${PATH}.

Limits

src can not exceed more than 20 files. Each file can not contain more than 8191 bytes or more than 50 key=value pairs.

Usage example

    #!/usr/bin/execlineb -P
    fdmove -c 2 1
    execl-envfile /etc/66/conf/ntpd
    foreground { mkdir -p  -m 0755 ${RUNDIR} }
    execl-cmdline -s { ntpd ${CMD_ARGS} }

The equivalent with s6-envdir and importas would be:

    #!/usr/bin/execlineb -P
    fdmove -c 2 1
    s6-envdir /etc/66/conf
    importas -u RUNDIR RUNDIR
    importas -u CMD_ARGS CMD_ARGS
    foreground { mkdir -p  -m 0755 ${RUNDIR} }
    execl-cmdline -s { ntpd ${CMD_ARGS} }

where /etc/66/conf contains two named files RUNDIR and CMD_ARGS written with /run/openntpd and -d -s respectively.