From a362dd3d72b37da75cf462d8c853b8cf39491107 Mon Sep 17 00:00:00 2001 From: Jephte CLAIN Date: Fri, 3 Jan 2014 00:01:32 +0400 Subject: [PATCH] maj ulib/base --- ucrontab | 71 +++++++++++++++++++++++++-------- ulib/.ulib_version | 2 +- ulib/support/install-pubkeys.sh | 59 ++++++++++++++++++++------- 3 files changed, 101 insertions(+), 31 deletions(-) diff --git a/ucrontab b/ucrontab index 536ce93..97ba746 100755 --- a/ucrontab +++ b/ucrontab @@ -732,10 +732,14 @@ function uaddpath() { local _qdir="${1//\//\\/}" eval "export ${2:-PATH}; "'[ "${'"${2:-PATH}"'#$1:}" == "$'"${2:-PATH}"'" -a "${'"${2:-PATH}"'%:$1}" == "$'"${2:-PATH}"'" -a "${'"${2:-PATH}"'//:$_qdir:/:}" == "$'"${2:-PATH}"'" -a "$'"${2:-PATH}"'" != "$1" ] && '"${2:-PATH}"'="${'"${2:-PATH}"':+$'"${2:-PATH}"':}$1"' } -function uinspath() { +function uinspathm() { local _qdir="${1//\//\\/}" eval "export ${2:-PATH}; "'[ "${'"${2:-PATH}"'#$1:}" == "$'"${2:-PATH}"'" -a "${'"${2:-PATH}"'%:$1}" == "$'"${2:-PATH}"'" -a "${'"${2:-PATH}"'//:$_qdir:/:}" == "$'"${2:-PATH}"'" -a "$'"${2:-PATH}"'" != "$1" ] && '"${2:-PATH}"'="$1${'"${2:-PATH}"':+:$'"${2:-PATH}"'}"' } +function uinspath() { + udelpath "$@" + uinspathm "$@" +} function withpath() { [ "${1#./}" != "$1" -o "${1#../}" != "$1" -o "${1#/}" != "$1" ] @@ -902,6 +906,7 @@ function deref() { local max_deref=50 local file="$1" + local basedir link while [ -L "$file" ]; do basedir="$(dirname "$file")" link="$(readlink "$file")" @@ -916,6 +921,9 @@ function deref() { done abspath "$file" } +function readlinkm() { + readlink -m "$1" +} function path_if_test() { local op="$1"; shift local file="$1"; shift @@ -2011,17 +2019,22 @@ function awkdef() { __ad_value="${1:$__ad_vpos}" [ ${#__ad_value} -ne 0 ] || __ad_value="$__ad_name" elif [[ "$__ad_arg" == *=* ]]; then - local __ad_int= + local __ad_int= __ad_str= __ad_name="${__ad_arg%%=*}" __ad_vpos=$((${#__ad_name} + 1)) - [ "${__ad_name%:int}" != "$__ad_name" ] && { + if [ "${__ad_name%:int}" != "$__ad_name" ]; then __ad_int=1 __ad_name="${__ad_name%:int}" - } + elif [ "${__ad_name%:str}" != "$__ad_name" ]; then + __ad_str=1 + __ad_name="${__ad_name%:str}" + fi [ -z "${__ad_name//[a-zA-Z0-9_]/}" ] || break __ad_value="${1:$__ad_vpos}" if [ -n "$__ad_int" ]; then echo "$__ad_name = int($(quoted_awk "$__ad_value") + 0)" + elif [ -n "$__ad_str" ]; then + echo "$__ad_name = $(quoted_awk "$__ad_value")" elif [ ${#__ad_value} -lt 256 ] && isnum "$__ad_value"; then echo "$__ad_name = $__ad_value" else @@ -2255,10 +2268,13 @@ function __genparse_shortopt() { shortopt="${shortopt,,}" [ -n "$shortopt" ] && echo "$shortopt" } +HELP_DESC= +HELP_USAGE= +HELP_OPTIONS= function genparse() { - local -a descs vars options - local desc var option name value shortopt + local -a names descs vars options + local i desc var option name value shortopt for var in "$@"; do if [[ "$var" == *=* ]]; then @@ -2266,6 +2282,7 @@ function genparse() { shortopt="$(__genparse_shortopt "$name")" option="${name,,}" name="${option//-/_}" + array_add names "$name" array_add descs "${shortopt:+-$shortopt, }--$option VALUE" array_add vars "$(set_var_cmd "$name" "$value")" array_add options "${shortopt:+-$shortopt:,}--$option: $name=" @@ -2274,6 +2291,7 @@ function genparse() { shortopt="$(__genparse_shortopt "$name")" option="${name,,}" name="${option//-/_}" + array_add names "$name" array_add descs "${shortopt:+-$shortopt, }--$option" array_add vars "$name=" array_add options "${shortopt:+-$shortopt,}--$option $name=1" @@ -2281,19 +2299,30 @@ function genparse() { done echo -n 'function display_help() { - uecho "\ -USAGE + [ -n "$HELP_USAGE" ] || HELP_USAGE="USAGE $scriptname' + [ -n "$descs" ] && echo -n ' [options]' + echo '"' if [ -n "$descs" ]; then - echo -n ' [options] - -OPTIONS' - for desc in "${descs[@]}"; do + echo -n ' [ -n "$HELP_OPTIONS" ] || HELP_OPTIONS="OPTIONS' + i=0 + while [ $i -lt ${#descs[*]} ]; do + name="${names[$i]}" + desc="${descs[$i]}" echo -n " - $desc" +\${HELP_${name^^}_OPTION:- $desc\${HELP_${name^^}_DESC:+ + \${HELP_${name^^}_DESC// +/ + }}}" + i=$(($i + 1)) done + echo '"' fi - echo '" + echo ' uecho "${HELP_DESC:+$HELP_DESC + +}$HELP_USAGE${HELP_OPTIONS:+ + +$HELP_OPTIONS}" } ' for var in "${vars[@]}"; do @@ -3720,6 +3749,8 @@ uprovide compat urequire base sysinfos if check_sysinfos -s macosx; then + function __rlnp() { local p="$1" np f; [ "${p#/}" == "$p" ] && p="$(pwd)/$p"; while [[ "$p" == *//* ]]; do p="${p//\/\///}"; done; p="${p%/}"; p="${p#/}"; np=; while [ -n "$p" ]; do if [[ "$p" == */* ]]; then f="${p%%/*}"; p="${p#*/}"; else f="$p"; p=; fi; if [ "$f" == . ]; then :; elif [ "$f" == .. ]; then if [[ "$np" == */* ]]; then np="${np%/*}"; else np=; fi; else [ -n "$np" ] && np="$np/"; np="$np$f"; fi; done; echo "/$np"; } + function readlinkm() { local p="$(__rlnp "$1")" np n; while [ -n "$p" ]; do local max=50; while [ -L "$p" -a $max -gt 0 ]; do n="$(readlink "$p")"; if [ "${n#/}" != "$n" ]; then p="$n"; else p="${p%/*}/$n"; fi; p="$(__rlnp "$p")"; max=$(($max-1)); done; [ -n "$np" ] && np="/$np"; if [[ "$p" == */* ]]; then np="${p##*/}$np"; p="${p%/*}"; else np="$p$np"; p=; fi; done; echo "/$np"; } function _nl2lf() { awk '{ sub(/\r$/, ""); gsub(/\r/, "\n"); print }'; } function _nl2crlf() { _nl2lf | awk '{ print $0 "\r" }'; } function _nl2cr() { _nl2lf | awk 'BEGIN { ORS="" } { print $0 "\r" }'; } @@ -4175,8 +4206,16 @@ BEGIN { next } /^\$.+/ { - sub(/^\$/, "", $0) - print + if ($0 ~ /^\$\{([ \t]*(#.*)?)?$/) { + getline + while ($0 !~ /^\$\}([ \t]*(#.*)?)?$/) { + print + if (getline <= 0) break + } + } else { + sub(/^\$/, "", $0) + print + } next } /^[ \t]*[-0-9/*,]+[ ]*[-0-9/*,]+[ ]*[-0-9/*,]+[ ]*[-0-9/*,]+[ ]*[-0-9/*,]+/ { diff --git a/ulib/.ulib_version b/ulib/.ulib_version index 60d3b2f..b6a7d89 100644 --- a/ulib/.ulib_version +++ b/ulib/.ulib_version @@ -1 +1 @@ -15 +16 diff --git a/ulib/support/install-pubkeys.sh b/ulib/support/install-pubkeys.sh index 5ef0a48..3541b93 100755 --- a/ulib/support/install-pubkeys.sh +++ b/ulib/support/install-pubkeys.sh @@ -645,10 +645,14 @@ function uaddpath() { local _qdir="${1//\//\\/}" eval "export ${2:-PATH}; "'[ "${'"${2:-PATH}"'#$1:}" == "$'"${2:-PATH}"'" -a "${'"${2:-PATH}"'%:$1}" == "$'"${2:-PATH}"'" -a "${'"${2:-PATH}"'//:$_qdir:/:}" == "$'"${2:-PATH}"'" -a "$'"${2:-PATH}"'" != "$1" ] && '"${2:-PATH}"'="${'"${2:-PATH}"':+$'"${2:-PATH}"':}$1"' } -function uinspath() { +function uinspathm() { local _qdir="${1//\//\\/}" eval "export ${2:-PATH}; "'[ "${'"${2:-PATH}"'#$1:}" == "$'"${2:-PATH}"'" -a "${'"${2:-PATH}"'%:$1}" == "$'"${2:-PATH}"'" -a "${'"${2:-PATH}"'//:$_qdir:/:}" == "$'"${2:-PATH}"'" -a "$'"${2:-PATH}"'" != "$1" ] && '"${2:-PATH}"'="$1${'"${2:-PATH}"':+:$'"${2:-PATH}"'}"' } +function uinspath() { + udelpath "$@" + uinspathm "$@" +} function withpath() { [ "${1#./}" != "$1" -o "${1#../}" != "$1" -o "${1#/}" != "$1" ] @@ -815,6 +819,7 @@ function deref() { local max_deref=50 local file="$1" + local basedir link while [ -L "$file" ]; do basedir="$(dirname "$file")" link="$(readlink "$file")" @@ -829,6 +834,9 @@ function deref() { done abspath "$file" } +function readlinkm() { + readlink -m "$1" +} function path_if_test() { local op="$1"; shift local file="$1"; shift @@ -1924,17 +1932,22 @@ function awkdef() { __ad_value="${1:$__ad_vpos}" [ ${#__ad_value} -ne 0 ] || __ad_value="$__ad_name" elif [[ "$__ad_arg" == *=* ]]; then - local __ad_int= + local __ad_int= __ad_str= __ad_name="${__ad_arg%%=*}" __ad_vpos=$((${#__ad_name} + 1)) - [ "${__ad_name%:int}" != "$__ad_name" ] && { + if [ "${__ad_name%:int}" != "$__ad_name" ]; then __ad_int=1 __ad_name="${__ad_name%:int}" - } + elif [ "${__ad_name%:str}" != "$__ad_name" ]; then + __ad_str=1 + __ad_name="${__ad_name%:str}" + fi [ -z "${__ad_name//[a-zA-Z0-9_]/}" ] || break __ad_value="${1:$__ad_vpos}" if [ -n "$__ad_int" ]; then echo "$__ad_name = int($(quoted_awk "$__ad_value") + 0)" + elif [ -n "$__ad_str" ]; then + echo "$__ad_name = $(quoted_awk "$__ad_value")" elif [ ${#__ad_value} -lt 256 ] && isnum "$__ad_value"; then echo "$__ad_name = $__ad_value" else @@ -2168,10 +2181,13 @@ function __genparse_shortopt() { shortopt="${shortopt,,}" [ -n "$shortopt" ] && echo "$shortopt" } +HELP_DESC= +HELP_USAGE= +HELP_OPTIONS= function genparse() { - local -a descs vars options - local desc var option name value shortopt + local -a names descs vars options + local i desc var option name value shortopt for var in "$@"; do if [[ "$var" == *=* ]]; then @@ -2179,6 +2195,7 @@ function genparse() { shortopt="$(__genparse_shortopt "$name")" option="${name,,}" name="${option//-/_}" + array_add names "$name" array_add descs "${shortopt:+-$shortopt, }--$option VALUE" array_add vars "$(set_var_cmd "$name" "$value")" array_add options "${shortopt:+-$shortopt:,}--$option: $name=" @@ -2187,6 +2204,7 @@ function genparse() { shortopt="$(__genparse_shortopt "$name")" option="${name,,}" name="${option//-/_}" + array_add names "$name" array_add descs "${shortopt:+-$shortopt, }--$option" array_add vars "$name=" array_add options "${shortopt:+-$shortopt,}--$option $name=1" @@ -2194,19 +2212,30 @@ function genparse() { done echo -n 'function display_help() { - uecho "\ -USAGE + [ -n "$HELP_USAGE" ] || HELP_USAGE="USAGE $scriptname' + [ -n "$descs" ] && echo -n ' [options]' + echo '"' if [ -n "$descs" ]; then - echo -n ' [options] - -OPTIONS' - for desc in "${descs[@]}"; do + echo -n ' [ -n "$HELP_OPTIONS" ] || HELP_OPTIONS="OPTIONS' + i=0 + while [ $i -lt ${#descs[*]} ]; do + name="${names[$i]}" + desc="${descs[$i]}" echo -n " - $desc" +\${HELP_${name^^}_OPTION:- $desc\${HELP_${name^^}_DESC:+ + \${HELP_${name^^}_DESC// +/ + }}}" + i=$(($i + 1)) done + echo '"' fi - echo '" + echo ' uecho "${HELP_DESC:+$HELP_DESC + +}$HELP_USAGE${HELP_OPTIONS:+ + +$HELP_OPTIONS}" } ' for var in "${vars[@]}"; do @@ -3433,6 +3462,8 @@ uprovide compat urequire base sysinfos if check_sysinfos -s macosx; then + function __rlnp() { local p="$1" np f; [ "${p#/}" == "$p" ] && p="$(pwd)/$p"; while [[ "$p" == *//* ]]; do p="${p//\/\///}"; done; p="${p%/}"; p="${p#/}"; np=; while [ -n "$p" ]; do if [[ "$p" == */* ]]; then f="${p%%/*}"; p="${p#*/}"; else f="$p"; p=; fi; if [ "$f" == . ]; then :; elif [ "$f" == .. ]; then if [[ "$np" == */* ]]; then np="${np%/*}"; else np=; fi; else [ -n "$np" ] && np="$np/"; np="$np$f"; fi; done; echo "/$np"; } + function readlinkm() { local p="$(__rlnp "$1")" np n; while [ -n "$p" ]; do local max=50; while [ -L "$p" -a $max -gt 0 ]; do n="$(readlink "$p")"; if [ "${n#/}" != "$n" ]; then p="$n"; else p="${p%/*}/$n"; fi; p="$(__rlnp "$p")"; max=$(($max-1)); done; [ -n "$np" ] && np="/$np"; if [[ "$p" == */* ]]; then np="${p##*/}$np"; p="${p%/*}"; else np="$p$np"; p=; fi; done; echo "/$np"; } function _nl2lf() { awk '{ sub(/\r$/, ""); gsub(/\r/, "\n"); print }'; } function _nl2crlf() { _nl2lf | awk '{ print $0 "\r" }'; } function _nl2cr() { _nl2lf | awk 'BEGIN { ORS="" } { print $0 "\r" }'; }