moved helpers separately
This commit is contained in:
+4
-29
@@ -40,14 +40,11 @@ export BASE_URL="https://git.geoffray-levasseur.org/fatalerrors/profile"
|
||||
# UPDT_DEFAULT_BRANCH (if set in profile.conf) is already available.
|
||||
load_conf "updates"
|
||||
|
||||
# Common helpers, then the ones private to this module (helpers/updates.sh)
|
||||
declare -F _profile_load_helpers >/dev/null || . "$(dirname -- "${BASH_SOURCE[0]}")/../helpers/common.sh"
|
||||
_profile_load_helpers "${BASH_SOURCE[0]}"
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Check a branch name. It ends up in URLs and in git command lines, so it is
|
||||
# restricted to plain ref characters, without a leading "-" or "..".
|
||||
# Usage: _updt_valid_branch <name>
|
||||
_updt_valid_branch()
|
||||
{
|
||||
[[ "$1" =~ ^[A-Za-z0-9][A-Za-z0-9._/-]*$ && "$1" != *..* ]]
|
||||
}
|
||||
|
||||
if ! _updt_valid_branch "${UPDT_DEFAULT_BRANCH:-master}"; then
|
||||
disp W "Invalid UPDT_DEFAULT_BRANCH '${UPDT_DEFAULT_BRANCH}', using master."
|
||||
@@ -58,24 +55,6 @@ export UPDT_DEFAULT_BRANCH="${UPDT_DEFAULT_BRANCH:-master}"
|
||||
export UPDT_URL="$BASE_URL/raw/branch/$UPDT_DEFAULT_BRANCH"
|
||||
export ARCH_URL="$BASE_URL/archive/$UPDT_DEFAULT_BRANCH.tar.gz"
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Tell whether the published version $2 is an update for the installed one $1.
|
||||
# Versions look like MAJOR.MINOR.PATCH[-REVISION[_STAGE_N]]. The base version
|
||||
# (before the first "-" or "_") decides, compared in version order; with the same
|
||||
# base, any difference (a new revision, a release candidate becoming final) is
|
||||
# an update. Returns 0 when it is, 1 otherwise (equal, or the installed version
|
||||
# is the more recent one, as on a development branch).
|
||||
# Usage: _updt_is_newer <installed> <published>
|
||||
_updt_is_newer()
|
||||
{
|
||||
local cur="$1" new="$2" cur_base new_base
|
||||
[[ "$cur" == "$new" ]] && return 1
|
||||
cur_base="${cur%%[-_]*}"
|
||||
new_base="${new%%[-_]*}"
|
||||
[[ "$cur_base" == "$new_base" ]] && return 0
|
||||
[[ "$(printf '%s\n%s\n' "$cur_base" "$new_base" | sort -V | tail -n 1)" == "$new_base" ]]
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Check whether a newer profile version is available
|
||||
# Usage: check_updates [-q]
|
||||
@@ -168,9 +147,6 @@ check_updates()
|
||||
return $result
|
||||
}
|
||||
export -f check_updates
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Apply the available profile upgrade
|
||||
# Usage: profile_upgrade [options]
|
||||
@@ -512,5 +488,4 @@ profile_upgrade()
|
||||
export -f profile_upgrade
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
# EOF
|
||||
|
||||
Reference in New Issue
Block a user