jw-build-functions.sh: Rename ytools-build-functions.sh to jw-build-functions.sh

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2017-04-07 14:58:51 +00:00
commit 32e4a703d7

View file

@ -1,11 +1,11 @@
export PATH=$PATH:/opt/ytools/bin
export PATH=$PATH:/opt/jwbuild/bin
# -- private stuff not intended for use outside of this script
_ytools_check_config_present()
_jwbuild_check_config_present()
{
if [ -z "$ytools_config_files" ]; then
if [ -z "$jwbuild_config_files" ]; then
if [ "$1" = true ]; then
ytools_log "warning: $0 tries to access configuration witout having a config file"
jwbuild_log "warning: $0 tries to access configuration witout having a config file"
fi
return 1;
fi
@ -13,31 +13,31 @@ _ytools_check_config_present()
}
_ytools_check_config_files_readable()
_jwbuild_check_config_files_readable()
{
local new=""
for f in $ytools_config_files; do
for f in $jwbuild_config_files; do
[ -f "$f" -a -r "$f" ] && new="$new $f"
done
ytools_config_files="$new"
jwbuild_config_files="$new"
}
_ytools_probe_config_paths()
_jwbuild_probe_config_paths()
{
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
[ ! "$jwbuild_config_files" ] && jwbuild_config_files="
/etc/opt/$jwbuild_project/$jwbuild_basename.conf
$HOME/.$jwbuild_project/$jwbuild_basename.conf
$HOME/.$jwbuild_project/$rc
$HOME/.$jwbuild_basename/$jwbuild_basename.conf
$HOME/.$jwbuild_basename/$rc
$HOME/.$rc
"
_ytools_check_config_files_readable
_jwbuild_check_config_files_readable
# add includes
new=""
for f in $ytools_config_files; do
for f in $jwbuild_config_files; do
exp=`sed '
/^[ ]*include[ ]/ !d
@ -54,12 +54,12 @@ _ytools_probe_config_paths()
fi
done
[ "$new" ] && ytools_config_files="$new"
[ "$new" ] && jwbuild_config_files="$new"
_ytools_check_config_files_readable
_jwbuild_check_config_files_readable
}
_ytools_cat_section()
_jwbuild_cat_section()
{
if [ "$2" ]; then
sed -n "/\[$2\]/,/[^ ]*\[/ p" $1 | sed '/[^ ]*\[/ d; /^[ ]*include[ ]/ d'
@ -69,19 +69,19 @@ _ytools_cat_section()
sed -n '0,/[^ ]*\[/ p' $1 | sed '/[^ ]*\[/ d; /^[ ]*include[ ]/ d'
}
_ytools_format_config()
_jwbuild_format_config()
{
sed '/^ *$/d; s/$/;/g' | sed 's/ *= */=/'
}
_ytools_format_section()
_jwbuild_format_section()
{
_ytools_cat_section $* | _ytools_format_config
_jwbuild_cat_section $* | _jwbuild_format_config
}
_ytools_source_section()
_jwbuild_source_section()
{
eval `_ytools_cat_section $* | _ytools_format_config`
eval `_jwbuild_cat_section $* | _jwbuild_format_config`
}
_uniq()
@ -90,35 +90,35 @@ _uniq()
}
# -- exported utilities
ytools_log_err()
jwbuild_log_err()
{
echo "# $@" >&2
}
ytools_log_stdout()
jwbuild_log_stdout()
{
echo "# $@"
}
ytools_log_stderr()
jwbuild_log_stderr()
{
echo "# $@" >&2
}
ytools_log_syslog()
jwbuild_log_syslog()
{
logger -t $ytools_basename "$*"
logger -t $jwbuild_basename "$*"
}
ytools_log()
jwbuild_log()
{
local logger
for logger in $ytools_loggers; do
eval ytools_log_$logger "$@"
for logger in $jwbuild_loggers; do
eval jwbuild_log_$logger "$@"
done
}
ytools_empty_config()
jwbuild_empty_config()
{
local o_verbose=""
local o_section
@ -132,25 +132,25 @@ ytools_empty_config()
-s)
o_section=$2; shift;;
*)
ytools_log_err unknown option $1
jwbuild_log_err unknown option $1
exit 1;;
esac
shift
done
shift
_ytools_check_config_present $o_verbose || return 1
_jwbuild_check_config_present $o_verbose || return 1
[ ! -r "$1" ] && return
[ "$o_verbose" ] && ytools_log o resetting config "\"$1\""
[ "$o_verbose" ] && jwbuild_log o resetting config "\"$1\""
if [ "$o_section" ]; then
[ "$o_verbose" ] && ytools_log o resetting section "[$o_section]" of config "\"$1\""
[ "$o_verbose" ] && jwbuild_log o resetting section "[$o_section]" of config "\"$1\""
fi
eval `_ytools_format_section $1 $o_section | sed 's/=[^;]*;/=;/g'`
eval `_jwbuild_format_section $1 $o_section | sed 's/=[^;]*;/=;/g'`
}
ytools_empty_configs()
jwbuild_empty_configs()
{
local section
local c
@ -168,27 +168,27 @@ ytools_empty_configs()
-s)
o_section="-s $2"; shift;;
*)
ytools_log_err unknown option $1
jwbuild_log_err unknown option $1
exit 1;;
esac
shift
done
shift
_ytools_check_config_present $o_verbose || return 1
_jwbuild_check_config_present $o_verbose || return 1
for section in "" `ytools_config_sections`; do
for section in "" `jwbuild_config_sections`; do
for c in $ytools_config_files; do
for c in $jwbuild_config_files; do
ytools_empty_config -s "$section" section $opts $c
jwbuild_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
jwbuild_empty_config -s "$section" $opts $f
done
fi
done
@ -197,7 +197,7 @@ ytools_empty_configs()
return 0
}
ytools_source_config()
jwbuild_source_config()
{
local o_verbose=""
local o_section
@ -212,29 +212,29 @@ ytools_source_config()
-s)
o_section=$2; shift;;
*)
ytools_log_err unknown option $1
jwbuild_log_err unknown option $1
exit 1;;
esac
shift
done
shift
_ytools_check_config_present $o_verbose || return 1
_jwbuild_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\""
jwbuild_log o sourcing section "[$o_section]" from config file "\"$1\""
else
ytools_log o sourcing config "\"$1\""
jwbuild_log o sourcing config "\"$1\""
fi
_ytools_cat_section $1 $o_section
_jwbuild_cat_section $1 $o_section
fi
_ytools_source_section $1 $o_section
_jwbuild_source_section $1 $o_section
}
ytools_source_configs()
jwbuild_source_configs()
{
local c
local source_opts=""
@ -252,28 +252,28 @@ ytools_source_configs()
source_opts="$source_opts -s $2"
shift;;
*)
ytools_log_err unknown option $1
jwbuild_log_err unknown option $1
exit 1;;
esac
shift
done
shift
_ytools_check_config_present $o_verbose || return 1
_jwbuild_check_config_present $o_verbose || return 1
for c in $ytools_config_files; do
ytools_source_config $source_opts $c
for c in $jwbuild_config_files; do
jwbuild_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 $source_opts $f
jwbuild_source_config $source_opts $f
done
fi
done
}
ytools_config_sections()
jwbuild_config_sections()
{
local o_verbose=""
local o_section
@ -293,7 +293,7 @@ ytools_config_sections()
e)
o_exact=true;;
*)
ytools_log_err "unknown option -$flag"
jwbuild_log_err "unknown option -$flag"
exit 1;;
esac
@ -301,9 +301,9 @@ ytools_config_sections()
shift $(($OPTIND - 1))
_ytools_check_config_present $o_verbose || return 1
_jwbuild_check_config_present $o_verbose || return 1
[ "$o_file" ] || o_file="$ytools_config_files"
[ "$o_file" ] || o_file="$jwbuild_config_files"
if [ "$o_exact" = false ]; then
@ -337,12 +337,12 @@ ytools_config_sections()
return
}
ytools_cat()
jwbuild_cat()
{
cat | sed 's/^[ ]*|//'
}
ytools_waitpid()
jwbuild_waitpid()
{
local pid=$1
local t=5
@ -359,19 +359,19 @@ ytools_waitpid()
return 1
}
ytools_terminate()
jwbuild_terminate()
{
local pid
for pid in $@; do
[ -f /proc/$pid/status ] && {
echo terminating process $pid
kill $pid
ytools_waitpid $pid || {
jwbuild_waitpid $pid || {
echo "failed to normally terminate process $pid, killing it" >&2
kill -9 $pid
ytools_waitpid $pid || {
jwbuild_waitpid $pid || {
echo "failed to kill process $pid" >&2
return 1
}
@ -382,13 +382,13 @@ ytools_terminate()
}
# -- exported variables
if [ "$ytools_functions_sourced" != "yes" ]; then
if [ "$jwbuild_functions_sourced" != "yes" ]; then
ytools_functions_sourced="yes"
jwbuild_functions_sourced="yes"
[ -z "$ytools_basename" ] && ytools_basename=`echo "$0" | sed 's/^-*//' | xargs basename | 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"
[ -z "$jwbuild_basename" ] && jwbuild_basename=`echo "$0" | sed 's/^-*//' | xargs basename | sed 's/\.sh$//'`
[ -z "$jwbuild_project" ] && jwbuild_project="jwbuild"
[ -z "$jwbuild_rc" ] && jwbuild_rc="$jwbuild_basename"rc
_jwbuild_probe_config_paths
[ -z "$jwbuild_loggers" ] && jwbuild_loggers="stdout"
fi