mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-pkg
synced 2026-01-15 20:13:32 +01:00
jw-build-functions.sh: Support config file include statement
- Add support for include statement in config files - Discard unreadable config files from ytools_config_files
This commit is contained in:
parent
97e810e711
commit
2cd9d26eef
1 changed files with 43 additions and 20 deletions
|
|
@ -12,21 +12,40 @@ _ytools_check_config_present()
|
|||
return 0;
|
||||
}
|
||||
|
||||
_ytools_probe_default_config_paths()
|
||||
_ytools_probe_config_paths()
|
||||
{
|
||||
[ "$ytools_config_files" ] && return 0
|
||||
|
||||
local f
|
||||
for f in \
|
||||
/etc/opt/$ytools_project/$ytools_basename.conf \
|
||||
$HOME/.$ytools_project/$ytools_basename.conf \
|
||||
$HOME/.$ytools_project/$rc \
|
||||
$HOME/.$ytools_basename/$ytools_basename.conf \
|
||||
$HOME/.$ytools_basename/$rc \
|
||||
$HOME/.$rc \
|
||||
; do
|
||||
[ -r "$f" ] && ytools_config_file="$ytools_config_files $f"
|
||||
local f new exp dir
|
||||
[ ! "$ytools_config_files" ] && ytools_config_files = "
|
||||
/etc/opt/$ytools_project/$ytools_basename.conf
|
||||
$HOME/.$ytools_project/$ytools_basename.conf
|
||||
$HOME/.$ytools_project/$rc
|
||||
$HOME/.$ytools_basename/$ytools_basename.conf
|
||||
$HOME/.$ytools_basename/$rc
|
||||
$HOME/.$rc
|
||||
"
|
||||
for f in $ytools_config_files; do
|
||||
[ -r "$f" ] && new="$new $f"
|
||||
done
|
||||
|
||||
ytools_config_files="$new"
|
||||
|
||||
# add includes
|
||||
new=""
|
||||
for f in $ytools_config_files; do
|
||||
exp=`sed '
|
||||
/^[ ]*include[ ]/ !d
|
||||
s/^[ ]*include[ ]*//g
|
||||
' $f`
|
||||
if [ "$exp" ]; then
|
||||
if [ "${exp:0:1}" != '/' ]; then
|
||||
dir=`dirname $f`
|
||||
exp=$dir/$exp
|
||||
fi
|
||||
exp=`ls -d $exp 2>/dev/null`
|
||||
new="$new $f $exp"
|
||||
fi
|
||||
done
|
||||
[ "$new" ] && ytools_config_files="$new"
|
||||
}
|
||||
|
||||
_ytools_cat_section()
|
||||
|
|
@ -54,13 +73,6 @@ _ytools_source_section()
|
|||
eval `_ytools_cat_section $* | _ytools_format_config`
|
||||
}
|
||||
|
||||
# -- exported variables
|
||||
[ -z "$ytools_basename" ] && ytools_basename=`basename $0 | sed 's/\.sh$//'`
|
||||
[ -z "$ytools_project" ] && ytools_project="ytools"
|
||||
[ -z "$ytools_rc" ] && ytools_rc="$ytools_basename"rc
|
||||
[ -z "$ytools_config_files" ] && _ytools_probe_default_config_paths
|
||||
[ -z "$ytools_loggers" ] && ytools_loggers="stdout"
|
||||
|
||||
# -- exported utilities
|
||||
ytools_log_err()
|
||||
{
|
||||
|
|
@ -353,3 +365,14 @@ ytools_terminate()
|
|||
return 0
|
||||
}
|
||||
|
||||
# -- exported variables
|
||||
if [ "$ytools_functions_sourced" != "yes" ]; then
|
||||
|
||||
ytools_functions_sourced="yes"
|
||||
|
||||
[ -z "$ytools_basename" ] && ytools_basename=`basename $0 | sed 's/\.sh$//'`
|
||||
[ -z "$ytools_project" ] && ytools_project="ytools"
|
||||
[ -z "$ytools_rc" ] && ytools_rc="$ytools_basename"rc
|
||||
_ytools_probe_config_paths
|
||||
[ -z "$ytools_loggers" ] && ytools_loggers="stdout"
|
||||
fi
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue