|
23 | 23 |
|
24 | 24 | ### functions ################################################################## |
25 | 25 |
|
26 | | -# Nothing here. |
| 26 | +function _get_self_dir |
| 27 | +{ |
| 28 | + echo "$( |
| 29 | + cd "$(dirname "${BASH_SOURCE[0]}")" || exit 1 |
| 30 | + pwd |
| 31 | + )" |
| 32 | +} |
27 | 33 |
|
28 | | -### main ####################################################################### |
| 34 | +function _get_jhb_conf_dirs |
| 35 | +{ |
| 36 | + local conf_dirs |
| 37 | + conf_dirs=$(_get_self_dir)/jhb.conf.d |
29 | 38 |
|
30 | | -_SELF_DIR=$( |
31 | | - cd "$(dirname "${BASH_SOURCE[0]}")" || exit 1 |
32 | | - pwd |
33 | | -) |
34 | | - |
35 | | -_DIRS=$_SELF_DIR/jhb.conf.d |
36 | | -# shellcheck disable=SC1073 # this is more readable |
37 | | -# iterate through all conf.d directories |
38 | | -for _DIR in "$_SELF_DIR"{/,/../../}*{pre,post}.conf.d; do |
39 | | - # Check if _DIR is actually a valid/existing directory. Otherwise we |
40 | | - # end up adding an unresolved wildcard expression to _DIRS. |
41 | | - if [ -d "$_DIR" ]; then |
42 | | - # Decide if the directory needs to prepended or appended to the list. |
43 | | - if [[ $_DIR = *pre* ]]; then |
44 | | - _DIRS="$_DIR $_DIRS" # prepend |
45 | | - else |
46 | | - _DIRS="$_DIRS $_DIR" # append |
| 39 | + # iterate through all conf.d directories |
| 40 | + for dir in "$(_get_self_dir)"{/,/../../}*{pre,post}.conf.d; do |
| 41 | + # Check if dir is actually a valid/existing directory. Otherwise we |
| 42 | + # end up adding an unresolved wildcard expression to conf_dirs. |
| 43 | + if [ -d "$dir" ]; then |
| 44 | + # Decide if the directory needs to prepended or appended to the list. |
| 45 | + if [[ $dir = *pre* ]]; then |
| 46 | + conf_dirs="$dir $conf_dirs" # prepend |
| 47 | + else |
| 48 | + conf_dirs="$conf_dirs $dir" # append |
| 49 | + fi |
47 | 50 | fi |
48 | | - fi |
49 | | -done |
| 51 | + done |
| 52 | + |
| 53 | + echo "$conf_dirs" |
| 54 | +} |
| 55 | + |
| 56 | +### main ####################################################################### |
50 | 57 |
|
51 | 58 | # source items from configuration directories |
52 | | -for _DIR in $_DIRS; do |
53 | | - for _FILE in $("$_SELF_DIR"/../usr/bin/run-parts list "$_DIR"/'*.sh'); do |
| 59 | +for DIR in $(_get_jhb_conf_dirs); do |
| 60 | + for FILE in $("$(_get_self_dir)"/../usr/bin/run-parts list "$DIR"/'*.sh'); do |
54 | 61 | # shellcheck disable=SC1090 # can't point to a single source here |
55 | | - source "$_FILE" |
| 62 | + source "$FILE" |
56 | 63 | done |
57 | 64 | done |
58 | 65 |
|
59 | | -unset _FILE _DIR _DIRS |
60 | | -unset _SELF_DIR |
| 66 | +unset FILE DIR |
0 commit comments