mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-pkg
synced 2026-01-15 12:03:31 +01:00
Everywhere: Merge V_1_1_29_40_POST_ACCEPTANCE
This commit is contained in:
parent
4fa387b655
commit
2939f8e3a8
29 changed files with 743 additions and 125 deletions
|
|
@ -1,25 +1,188 @@
|
|||
export PATH=$PATH:/opt/ytools/bin
|
||||
|
||||
# -- private stuff not intended for use outside of this script
|
||||
_ytools_check_config_present()
|
||||
{
|
||||
if [ -z "$ytools_config_files" ]; then
|
||||
if [ "$1" = true ]; then
|
||||
ytools_log "warning: $0 tries to access configuration witout having a config file"
|
||||
fi
|
||||
return 1;
|
||||
fi
|
||||
return 0;
|
||||
}
|
||||
|
||||
_ytools_probe_default_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"
|
||||
done
|
||||
}
|
||||
|
||||
_ytools_cat_section()
|
||||
{
|
||||
if [ "$2" ]; then
|
||||
sed -n "/\[$2\]/,/[^ ]*\[/ p" $1 | sed '/[^ ]*\[/ d'
|
||||
return
|
||||
fi
|
||||
|
||||
sed -n '0,/[^ ]*\[/ p' | sed '/[^ ]*\[/ d; s/=.*/=/' $1
|
||||
}
|
||||
|
||||
_ytools_format_config()
|
||||
{
|
||||
sed '/^$/d; s/$/;/'
|
||||
}
|
||||
|
||||
_ytools_format_section()
|
||||
{
|
||||
_ytools_cat_section $* | _ytools_format_config
|
||||
}
|
||||
|
||||
_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()
|
||||
{
|
||||
echo "# $@" >&2
|
||||
}
|
||||
|
||||
ytools_log_stdout()
|
||||
{
|
||||
echo "# $@"
|
||||
}
|
||||
|
||||
ytools_log_stderr()
|
||||
{
|
||||
echo "# $@" >&2
|
||||
}
|
||||
|
||||
ytools_log_syslog()
|
||||
{
|
||||
logger -t $ytools_basename "$*"
|
||||
}
|
||||
|
||||
ytools_log()
|
||||
{
|
||||
echo $@
|
||||
local logger
|
||||
for logger in $ytools_loggers; do
|
||||
eval ytools_log_$logger "$@"
|
||||
done
|
||||
}
|
||||
|
||||
ytools_log_err()
|
||||
ytools_empty_config()
|
||||
{
|
||||
echo $@ >&2
|
||||
local o_verbose=""
|
||||
local o_section
|
||||
|
||||
set -- `getopt 'vs:' $*`
|
||||
|
||||
while [ "$1" != -- ]; do
|
||||
case $1 in
|
||||
-v)
|
||||
o_verbose=true;;
|
||||
-s)
|
||||
o_section=$2; shift;;
|
||||
*)
|
||||
ytools_log_err unknown option $1
|
||||
exit 1;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
shift
|
||||
|
||||
_ytools_check_config_present $o_verbose || return 1
|
||||
|
||||
[ ! -r "$1" ] && return
|
||||
[ "$o_verbose" ] && ytools_log o resetting config "\"$1\""
|
||||
if [ "$o_section" ]; then
|
||||
[ "$o_verbose" ] && ytools_log o resetting section "[$o_section]" of config "\"$1\""
|
||||
fi
|
||||
|
||||
eval `_ytools_format_section $1 $o_section | sed 's/=[^;]*;/=;/g'`
|
||||
}
|
||||
|
||||
ytools_empty_configs()
|
||||
{
|
||||
local section
|
||||
local c
|
||||
local o_verbose=""
|
||||
local o_section
|
||||
local opts=""
|
||||
|
||||
set -- `getopt 'vs:' $*`
|
||||
while [ "$1" != -- ]; do
|
||||
case $1 in
|
||||
-v)
|
||||
o_verbose=true
|
||||
opts="$opts -v"
|
||||
;;
|
||||
-s)
|
||||
o_section="-s $2"; shift;;
|
||||
*)
|
||||
ytools_log_err unknown option $1
|
||||
exit 1;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
shift
|
||||
|
||||
_ytools_check_config_present $o_verbose || return 1
|
||||
|
||||
for section in "" `ytools_config_sections`; do
|
||||
|
||||
for c in $ytools_config_files; do
|
||||
|
||||
ytools_empty_config -s "$section" section $opts $c
|
||||
|
||||
if [ -d $c.d ]; then
|
||||
|
||||
local dirconfs=`find $c.d -maxdepth 1 -type f`
|
||||
local f
|
||||
for f in $dirconfs; do
|
||||
ytools_empty_config -s "$section" $opts $f
|
||||
done
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
ytools_source_config()
|
||||
{
|
||||
local o_verbose=""
|
||||
local o_section
|
||||
|
||||
set -- `getopt 'v' $*`
|
||||
set -- `getopt 'vs:' $*`
|
||||
|
||||
while [ "$1" != -- ]; do
|
||||
case $1 in
|
||||
-v)
|
||||
o_verbose=true;;
|
||||
o_verbose=true
|
||||
;;
|
||||
-s)
|
||||
o_section=$2; shift;;
|
||||
*)
|
||||
ytools_log_err unknown option $1
|
||||
exit 1;;
|
||||
|
|
@ -28,25 +191,38 @@ ytools_source_config()
|
|||
done
|
||||
shift
|
||||
|
||||
[ ! -r "$1" ] && return
|
||||
[ "$o_verbose" ] && ytools_log o reading config "<$1>"
|
||||
. $1
|
||||
_ytools_check_config_present $o_verbose || return 1
|
||||
|
||||
if [ "$o_verbose" = true ]; then
|
||||
if [ "$o_section" ]; then
|
||||
ytools_log o sourcing section "[$o_section]" from config file "\"$1\""
|
||||
else
|
||||
ytools_log o sourcing config "\"$1\""
|
||||
fi
|
||||
|
||||
_ytools_cat_section $1 $o_section
|
||||
fi
|
||||
|
||||
_ytools_source_section $1 $o_section
|
||||
}
|
||||
|
||||
ytools_source_configs()
|
||||
{
|
||||
local c
|
||||
local basename=${myname/.*/}
|
||||
local rc="$basename"rc
|
||||
local project=ytools
|
||||
local source_opts=""
|
||||
local o_verbose=""
|
||||
|
||||
set -- `getopt 'v' $*`
|
||||
set -- `getopt 'vs:' $*`
|
||||
|
||||
while [ "$1" != -- ]; do
|
||||
case $1 in
|
||||
-v)
|
||||
o_verbose=true;;
|
||||
o_verbose=true
|
||||
source_opts="$source_opts -v"
|
||||
;;
|
||||
-s)
|
||||
source_opts="$source_opts -s $2"
|
||||
shift;;
|
||||
*)
|
||||
ytools_log_err unknown option $1
|
||||
exit 1;;
|
||||
|
|
@ -55,27 +231,84 @@ ytools_source_configs()
|
|||
done
|
||||
shift
|
||||
|
||||
config_files="
|
||||
/etc/opt/$project/$basename.conf
|
||||
$HOME/.$project/$basename.conf
|
||||
$HOME/.$project/$rc
|
||||
$HOME/.$basename/$basename.conf
|
||||
$HOME/.$basename/$rc
|
||||
$HOME/.$rc
|
||||
"
|
||||
_ytools_check_config_present $o_verbose || return 1
|
||||
|
||||
for c in $config_files; do
|
||||
ytools_source_config $c
|
||||
for c in $ytools_config_files; do
|
||||
ytools_source_config $source_opts $c
|
||||
if [ -d $c.d ]; then
|
||||
local dirconfs=`find $c.d -maxdepth 1 -type f`
|
||||
local f
|
||||
for f in $dirconfs; do
|
||||
ytools_source_config $f
|
||||
ytools_source_config $source_opts $f
|
||||
done
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
ytools_config_sections()
|
||||
{
|
||||
local o_verbose=""
|
||||
local o_section
|
||||
local o_file
|
||||
local o_exact=false
|
||||
|
||||
OPTIND=1
|
||||
while getopts ves:f: flag; do
|
||||
|
||||
case $flag in
|
||||
v)
|
||||
o_verbose=true;;
|
||||
s)
|
||||
o_section="$OPTARG";;
|
||||
f)
|
||||
o_file="$OPTARG";;
|
||||
e)
|
||||
o_exact=true;;
|
||||
*)
|
||||
ytools_log_err "unknown option -$flag"
|
||||
exit 1;;
|
||||
esac
|
||||
|
||||
done
|
||||
|
||||
shift $(($OPTIND - 1))
|
||||
|
||||
_ytools_check_config_present $o_verbose || return 1
|
||||
|
||||
[ "$o_file" ] || o_file="$ytools_config_files"
|
||||
|
||||
if [ "$o_exact" = false ]; then
|
||||
|
||||
if [ "$o_section" ]; then
|
||||
sed "
|
||||
/^[ ]*\[$o_section\.\(.*\)\]/ !d
|
||||
s/^[ ]*\[$o_section\.\(.*\)\].*/\1/
|
||||
" $o_file 2>/dev/null | sort -u
|
||||
else
|
||||
sed "
|
||||
/^[ ]*\[\(.*\)\]/ !d
|
||||
s/^[ ]*\[\(.*\)\].*/\1/
|
||||
" $o_file 2>/dev/null | sort -u
|
||||
fi
|
||||
|
||||
else
|
||||
|
||||
if [ "$o_section" ]; then
|
||||
sed "
|
||||
/^[ ]*\[$o_section\.\([^.]*\)\]/ !d
|
||||
s/^[ ]*\[$o_section\.\([^.]*\)\].*/\1/
|
||||
" $o_file 2>/dev/null | sort -u
|
||||
else
|
||||
sed "
|
||||
/^[ ]*\[\([^.]*\)\]/ !d
|
||||
s/^[ ]*\[\([^.]*\)\].*/\1/
|
||||
" $o_file 2>/dev/null | sort -u
|
||||
fi
|
||||
fi
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
ytools_cat()
|
||||
{
|
||||
cat | sed 's/^[ ]*|//'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue