302302 echo " silent error warning debug info"
303303 echo " default loglevel is warning"
304304 echo " -m, --minionversion install salt-minion version, default[latest]"
305+ echo " 'latest' and four-digit major (e.g. 3006) pick"
306+ echo " newest GA onedir only; prerelease dirs need"
307+ echo " the exact directory name (e.g. 3008.0rc1)"
305308 echo " -n, --reconfig salt-minion restarts after reading updated config"
306309 echo " -q, --stop stop salt-minion"
307310 echo " -p, --start start salt-minion (restarts salt-minion)"
@@ -401,28 +404,42 @@ _set_log_level() {
401404
402405
403406
407+ #
408+ # _salt_onedir_dir_is_ga
409+ #
410+ # True (status 0) if the onedir directory name is GA numeric CalVer only
411+ # (digits and dots). Prerelease names (e.g. 3008.0rc1) are not GA.
412+ #
413+ # Results:
414+ # 0 if GA, 1 otherwise
415+ #
416+ _salt_onedir_dir_is_ga () {
417+ local _ga_re=' ^[0-9]+\.[0-9]+(\.[0-9]+)*$'
418+ [[ -n " $1 " && " $1 " =~ ${_ga_re} ]]
419+ }
420+
421+
404422#
405423# _get_desired_salt_version_fn
406424#
407425# Get the appropriate desirted salt version based on salt_url_version,
408- # latest or specified input Salt version, 3007 , 3006, 3006.x, 3007.1
426+ # latest or specified input Salt version, 3008 , 3006.10, 3008.0rc1
409427# and set salt_specific_version accordinly
410428#
411- # Note: typically Salt version includes the release number in addition to
412- # version number or 'latest' for the most recent release
413- #
414- # for example: currently major version 3006 implies 3006.9
415- # the latest version of Salt 3006.x
429+ # Note: 'latest' and four-digit major (e.g. 3006) choose the newest GA
430+ # onedir only (sort -V among dirs matching ^[0-9]+\\.[0-9]+(\\.[0-9]+)*$).
431+ # Prerelease directories must be requested by exact name (directory
432+ # match or legacy CalVer pattern).
416433#
417434# if an unsupported version is input, for example: 3004.2
418- # it will default to installing the latest version
435+ # it will default to installing the latest GA version
419436#
420437# Input:
421438# directory contains directory list of current available
422- # Salt versions, 3006.x - 3007.1
439+ # Salt versions, e.g. 3006.x, 3007.1, 3008.0rc1
423440#
424441# Results:
425- # Returns with exit code
442+ # Returns with exit code (1 if no GA match for latest/major/default)
426443#
427444_get_desired_salt_version_fn () {
428445
@@ -440,46 +457,79 @@ _get_desired_salt_version_fn() {
440457
441458 # something werid is happening with tail, that does not fail in test
442459 # programs getting failures inside tail hence use bash loop
460+ _GENERIC_PKG_VERSION=" "
443461 if [ " $salt_url_version " = " latest" ]; then
444462 # shellcheck disable=SC2010,SC2012
445- # # _GENERIC_PKG_VERSION=$(ls ./. | grep -v 'index.html' | sort -V -u | tail -n 1)
446463 test_dir=$( ls ./. | grep -v ' index.html' | sort -V -u)
447464 for idx in $test_dir
448465 do
449- _GENERIC_PKG_VERSION=" $idx "
466+ if _salt_onedir_dir_is_ga " $idx " ; then
467+ _GENERIC_PKG_VERSION=" $idx "
468+ fi
450469 done
451- _debug_log " $0 :${FUNCNAME[0]} latest found version '${_GENERIC_PKG_VERSION} '"
470+ if [[ -z " ${_GENERIC_PKG_VERSION} " ]]; then
471+ cd " ${curr_pwd} " || return 1
472+ _error_log " $0 :${FUNCNAME[0]} no GA onedir version directories " \
473+ " found for 'latest' at '${generic_versions_tmpdir} '"
474+ return 1
475+ fi
476+ _debug_log " $0 :${FUNCNAME[0]} latest found GA version " \
477+ " '${_GENERIC_PKG_VERSION} '"
452478
453- elif [ " $( echo " $ salt_url_version" | grep -E ' ^(3006|3007)$ ' ) " != " " ]; then
454- # want major latest version of Salt
479+ elif [[ " ${ salt_url_version} " =~ ^[0-9]{4}$ ] ]; then
480+ # want newest GA in this major series (3006, 3007, 3008, ...)
455481 # shellcheck disable=SC2010,SC2012
456- # # _GENERIC_PKG_VERSION =$(ls ./. | grep -v 'index.html' | sort -V -u | grep -E "$salt_url_version" | tail -n 1)
457- test_dir= $( ls ./. | grep -v ' index.html ' | sort -V -u | grep -E " $ salt_url_version" )
482+ test_dir =$( ls ./. | grep -v ' index.html' | sort -V -u \
483+ | grep -E " ^ ${ salt_url_version} \\ . " )
458484 for idx in $test_dir
459485 do
460- _GENERIC_PKG_VERSION=" $idx "
486+ if _salt_onedir_dir_is_ga " $idx " ; then
487+ _GENERIC_PKG_VERSION=" $idx "
488+ fi
461489 done
462- _debug_log " $0 :${FUNCNAME[0]} input $salt_url_version found " \
463- " version '${_GENERIC_PKG_VERSION} '"
490+ if [[ -z " ${_GENERIC_PKG_VERSION} " ]]; then
491+ cd " ${curr_pwd} " || return 1
492+ _error_log " $0 :${FUNCNAME[0]} no GA onedir version found for " \
493+ " major series '${salt_url_version} ' at " \
494+ " '${generic_versions_tmpdir} '"
495+ return 1
496+ fi
497+ _debug_log " $0 :${FUNCNAME[0]} input ${salt_url_version} found " \
498+ " GA version '${_GENERIC_PKG_VERSION} '"
499+
500+ elif [[ -d " ./${salt_url_version} " ]]; then
501+ _GENERIC_PKG_VERSION=" ${salt_url_version} "
502+ _debug_log " $0 :${FUNCNAME[0]} exact directory match " \
503+ " '${_GENERIC_PKG_VERSION} '"
464504
465505 elif [ " $( echo " $salt_url_version " | grep -E ' ^([3-9][0-5]{2}[6-9](\.[0-9]*)?)' ) " != " " ]; then
466- # Minor version Salt, want specific minor version
506+ # Minor version Salt, want specific minor version (incl. prerelease tags)
467507 # if old style VMTools version 3004.2-1 is used
468- # defaults to else and install latest
508+ # defaults to else and install latest GA
469509 _GENERIC_PKG_VERSION=" $salt_url_version "
510+ _debug_log " $0 :${FUNCNAME[0]} explicit version " \
511+ " '${_GENERIC_PKG_VERSION} '"
470512 else
471- # default to latest version Salt
513+ # default to latest GA version Salt
472514 # shellcheck disable=SC2010,SC2012
473- # # _GENERIC_PKG_VERSION=$(ls ./. | grep -v 'index.html' | sort -V -u | tail -n 1)
474515 test_dir=$( ls ./. | grep -v ' index.html' | sort -V -u)
475516 for idx in $test_dir
476517 do
477- _GENERIC_PKG_VERSION=" $idx "
518+ if _salt_onedir_dir_is_ga " $idx " ; then
519+ _GENERIC_PKG_VERSION=" $idx "
520+ fi
478521 done
479- _debug_log " $0 :${FUNCNAME[0]} default found version '${_GENERIC_PKG_VERSION} '"
522+ if [[ -z " ${_GENERIC_PKG_VERSION} " ]]; then
523+ cd " ${curr_pwd} " || return 1
524+ _error_log " $0 :${FUNCNAME[0]} no GA onedir version directories " \
525+ " found for default latest at '${generic_versions_tmpdir} '"
526+ return 1
527+ fi
528+ _debug_log " $0 :${FUNCNAME[0]} default found GA version " \
529+ " '${_GENERIC_PKG_VERSION} '"
480530
481531 fi
482- cd ${curr_pwd} || return 1
532+ cd " ${curr_pwd} " || return 1
483533
484534 # set specific version of Salt to use
485535 salt_specific_version=" ${_GENERIC_PKG_VERSION} "
@@ -926,7 +976,7 @@ _fetch_salt_minion() {
926976 _debug_log " $0 :${FUNCNAME[0]} current directory ${curr_dir} "
927977
928978 # get desired specific version of Salt
929- _get_desired_salt_version_fn " ${salt_url} "
979+ _get_desired_salt_version_fn " ${salt_url} " || return 1
930980 cd " ${salt_url} " || return 1
931981 cd " ${salt_specific_version} " || return 1
932982 salt_pkg_name=$( ls " ${salt_name} -${salt_specific_version} -onedir-linux-${sys_arch} .tar.xz" )
@@ -949,7 +999,12 @@ _fetch_salt_minion() {
949999 cd ${curr_pwd} || return 1
9501000
9511001 # get desired specific version of Salt
952- _get_desired_salt_version_fn " ${generic_versions_tmpdir} /artifactory/saltproject-generic/onedir"
1002+ if ! _get_desired_salt_version_fn \
1003+ " ${generic_versions_tmpdir} /artifactory/saltproject-generic/onedir"
1004+ then
1005+ rm -fR " ${generic_versions_tmpdir} "
1006+ return 1
1007+ fi
9531008
9541009 # clean up temp dir
9551010 rm -fR ${generic_versions_tmpdir}
0 commit comments