From 33f31f3fc7769c067eadd392bd840d144adbb9b3 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Fri, 13 Feb 2015 02:54:37 -0800 Subject: [PATCH] shlib.sh: set some additional variables Set var_git_ver to the version number part of `git version`. Set var_have_git_172 to 1 if the Git version is at least 1.7.2. Provide vcmp shell function to compare dotted version numbers. --- shlib.sh | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/shlib.sh b/shlib.sh index e8d2eb5..7ff97ee 100644 --- a/shlib.sh +++ b/shlib.sh @@ -9,7 +9,34 @@ octet4="$octet$octet$octet$octet" octet19="$octet4$octet4$octet4$octet4$octet$octet$octet" octet20="$octet4$octet4$octet4$octet4$octet4" -get_girocco_config_var_list() { +vcmp() { + # Compare $1 to $2 each of which must match \d+(\.\d+)* + # An empty string ('') for $1 or $2 is treated like 0 + # Outputs: + # -1 if $1 < $2 + # 0 if $1 = $2 + # 1 if $1 > $2 + # Note that `vcmp 1.8 1.8.0.0.0.0` correctly outputs 0. + while + _a="${1%%.*}" + _b="${2%%.*}" + [ -n "$_a" -o -n "$_b" ] + do + if [ "${_a:-0}" -lt "${_b:-0}" ]; then + echo -1 + return + elif [ "${_a:-0}" -gt "${_b:-0}" ]; then + echo 1 + return + fi + _a2="${1#$_a}" + _b2="${2#$_b}" + set -- "${_a2#.}" "${_b2#.}" + done + echo 0 +} + +get_girocco_config_pm_var_list() { # Export all the variables from Girocco::Config to suitable var= lines # prefixing them with 'cfg_'. E.g. $cfg_admin is admin's mail address now # and also setting a 'defined_cfg_' prefix to 1 if they are not undef. @@ -27,6 +54,20 @@ get_girocco_config_var_list() { }' } +get_girocco_config_var_list() ( + # Same as get_girocco_config_pm_var_list except that + # the following variables (all starting with var_) are added: + # var_git_ver The version number part from `git version` + # var_have_git_172 Set to 1 if git version >= 1.7.2 otherwise '' + _cfg_vars="$(get_girocco_config_pm_var_list)" + eval "$_cfg_vars" + printf '%s\n' "$_cfg_vars" + _gver="$("$cfg_git_bin" version 2>/dev/null | \ + sed -ne 's/^[^0-9]*\([0-9][0-9]*\(\.[0-9][0-9]*\)*\).*$/\1/p')" + printf 'var_git_ver=%s\n' "$_gver" + printf "var_have_git_172=%s\n" "$([ $(vcmp "$_gver" 1.7.2) -ge 0 ] && echo 1)" +) + # If basedir has been replaced, and shlib_vars.sh exists, get the config # definitions from it rather than running Perl. if [ "@basedir@" = '@'basedir'@' ] || ! [ -r "@basedir@/shlib_vars.sh" ]; then -- 2.11.4.GIT