Technical data

8. Documentation for Developers
#--------------------------------------------------------------------
# /etc/rc.d/rc500.dummy - start my cool dummy server
#
# Creation: 19.07.2001 Sheldon Cooper <sheldon@nerd.net>
# Last Update: 11.11.2001 Howard Wolowitz <howard@nerd.net>
#--------------------------------------------------------------------
Now for the real stuff to start...
8.4.2. Handling of Configuration Variables
Packages are configured via the file config/<PACKAGE>.txt. The active variables (Page 291)
contained there are transferred to the file rc.cfg during creation of the medium. This file
is processed during router boot before any rc-script (scripts under /etc/rc.d/) gets started.
The script then may access all configuration variables by reading the content of $<variable
name>.
If the values of configuration variables are needed after booting the may be extracted from
/etc/rc.cfg to which the configuration of the boot medium was written during the boot
process. If for example the value of the variable OPT_DNS should be processed in a script this
can be achieved as follows:
eval $(grep "^OPT_DNS=" /etc/rc.cfg)
This works efficiently also with multiple variables (with calling the grep program only once):
eval $(grep "^\(HOSTNAME\|DOMAIN_NAME\|OPT_DNS\|DNS_LISTEN_N\)=" /etc/rc.cfg)
8.4.3. Persistent Data Storage
Occasionally a package needs the possibility to store data persistent, surviving the reboot of
the router. For this purpose, the function map2persistent exists and can be called from a
script in /etc/rc.d/. It expects a variable that contains a path and a subdirectory. The idea
is that the variable is either describing an actual path then this path is used because the user
explicitely has done so, or the string “auto” then a subdirectory on a persistent medium is
created corresponding to the second parameter. The function returns the result in the variable
passed by name as the first parameter. An example will make this clear. VBOX_SPOOLPATH is a
variable, that ’contains a path or the string “auto” . The call
begin_script VBOX "Configuring vbox ..."
[...]
map2persistent VBOX_SPOOLPATH /spool
[...]
end_script
results in the variable VBOX_SPOOLPATH either not being changed at all (if it contains a path),
or being changed to /var/lib/persistent/vbox/spool (if it contains the string “auto”).
/var/lib/persistent then points
6
to a directory on a non-volatile and writable storage
medium, <SCRIPT> is the name of the calling script in lowercase (this name is derived from
6
by the use of a so-called “bind”-mount
318