Skip to content

Commit

Permalink
Refactor to relocate utility functions
Browse files Browse the repository at this point in the history
  • Loading branch information
joshbode committed Apr 1, 2024
1 parent 005d955 commit 1445d7e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
15 changes: 5 additions & 10 deletions bin/install
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ if ((ERRORS)); then
exit 1
fi

later_version() {
printf '%s\n' "$@" | sort -Vr | head -n1
}

install_sops() {
local install_type=$1
if [[ "${install_type}" != "version" ]]; then
Expand All @@ -37,8 +33,8 @@ install_sops() {

local version=$2

# Note that we're adding back the 'v' tag prefix only for versions >= 3.5.0
if [[ ${version} == $(later_version "${version}" 3.5.0) ]]; then
# add the 'v' tag prefix for versions >= 3.5.0
if min_version "${version}" 3.5.0; then
version="v${version}"
fi

Expand Down Expand Up @@ -79,12 +75,11 @@ get_cpu() {

get_download_url() {
local version="$1"
local platform
platform=$(get_arch)
local url

local url="${DOWNLOAD_PATH}/${version}/sops-${version}.${platform}"
url="${DOWNLOAD_PATH}/${version}/sops-${version}.$(get_arch)"

if [[ ${version} == $(later_version "${version}" v3.7.2) ]]; then
if min_version "${version}" v3.7.2; then
url="${url}.$(get_cpu)"
fi

Expand Down
5 changes: 0 additions & 5 deletions bin/list-all
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ if [[ -n ${GITHUB_API_TOKEN-} ]]; then
set -- "$@" -H "Authorization: token ${GITHUB_API_TOKEN}"
fi

function sort_versions() {
sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z\1/; s/$/.z/; G; s/\n/ /' |
LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | awk '{print $2}'
}

# stripping off the 'v' prefix as it causes issues with 'mise install foo latest'
curl -qsSL "$@" "${RELEASES_PATH}" |
grep -o '"tag_name": "v\?[0-9][^"]\+"' |
Expand Down
10 changes: 10 additions & 0 deletions utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ echoerr() {
printf 'mise-sops: %s\n' "$1" >&2
}

sort_versions() {
sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z\1/; s/$/.z/; G; s/\n/ /' |
LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | awk '{print $2}'
}

min_version() {
version=$1
[[ ${version} == $(printf '%s\n' "$@" | sort_versions | tail -n1) ]]
}

sops_bin() {
"${MISE_INSTALL_PATH}/bin/sops" "$@"
}
Expand Down

0 comments on commit 1445d7e

Please sign in to comment.