conf.sh(3) -- easy loading of configuration files ============================================== ## SYNOPSIS `. $(librelib conf)` ## DESCRIPTION `conf.sh` is a Bash(1) library to easily load various configuration files related to Arch Linux/Parabola(7) and libretools(7). I recommend reading the source yourself--it is mostly self-explanatory, and is shorter than this document. ### VARIABLES When loading configuration files in a program run with `sudo`(8), it is often desirable to load the configuration files from the home directory of the user who called `sudo`, instead of from /root. To accommodate this, instead of using the usual $ and $, `conf.sh` sets $ and $, which it then uses. * : If $ is set, then $ is set to that. Otherwise, $ is set to the value of $. * : If $ == $, then $ is set to the value of $. Otherwise, it is set to the default home directory of the user $. Further, `conf.sh` works with XDG; it sets and uses $ and $ with the following values: * : If it isn't already set, it is set to "$/.config" and exported. * : If it isn't already set, it is set to "$/.cache" and exported. Note that only the XDG_* variables are exported. ### GENERIC ROUTINES The following routines take a "slug" to refer to a group of configuration files; that is the basename of the files. For example, ='abs' will identify `/etc/abs.conf` and `$/.abs.conf`. The routines you will likely actually use are: * `load_files` : Loads the configuration files for , loading the files in the correct order, and checking the appropriate environmental variables. * `check_vars` ...: Checks to see if all of are defined. If any of them aren't, it prints a message to configure them in the configuration files for , and returns with a non-zero status. * `get_var` : If is set in the configuration for , print it's value, considering environmental variables. If it is not set, return . This does NOT work for array variables. * `set_var` : Set the variable equal to in the configuration file for of highest precedence that already exists, and is writable. If no files fit this description, the routine does nothing and returns a non-zero exit status. This does NOT work for array variables. There are two more routines the above routines use internally that are used internally by . You are unlikely to use them directly, but they might be useful for debugging, or at least describing behavior. * `list_files` : Lists (newline-separated) the configuration files that must be considered for . Files listed later take precedence over files listed earlier. * `list_envvars` : Lists (newline-separated) the environmental variables that take precedence over the settings in the configuration files for . For example, in `makepkg.conf`(8) (=makepkg), if the environmental variable is set, the value in the configuration file is ignored. ### PKGBUILD ROUTINES These two routines deal with loading `PKGBUILD`(5) files. * `unset_PKGBUILD`: Unsets all variables and functions that might be set in a `PKGBUILD`(5) file, including those specific to `librefetch`(8). * `load_PKGBUILD` []: "Safely" loads a PKGBUILD. Everything that it would normally set is unset first, $ is set according to `makepkg.conf`(5), then the file is loaded. The file to be loaded is , or "./PKGBUILD" by default. This isn't safe, security wise, in that the PKGBUILD is free to execute code. ### SLUGS The differences in behavior for anything that takes a slug comes down to the differences in the output for `list_files` and `list_envvars`. The "known" slugs are "abs", "makepkg", and "libretools". If anything else is given, then: * `list_files` will give back "/etc/libretools.d/.conf" and "$/libretools/.conf" * `list_envvars` will give back an empty list. The rules for =(abs|makepkg|libretools) are more easily expressed in code than prose, so it is recommended that you look at that. ## BUGS `get_var` and `set_var` do not work with arrays. ## SEE ALSO librelib(7) abs.conf(5), makepkg.conf(5), libretools.conf(5), PKGBUILD(5) chroot.conf(5), librefetch.conf(5)