From: AJ ONeal Date: Mon, 15 Nov 2021 11:22:51 +0000 (+0000) Subject: refactor(webi): finally remove use of pkg_get_current_version X-Git-Url: https://git.josue.xyz/?p=webi-installers%2F.git;a=commitdiff_plain;h=2d68b08174ff6d37b5b3f42e51d5e9802d96e2a0 refactor(webi): finally remove use of pkg_get_current_version --- diff --git a/_example/install.sh b/_example/install.sh index 07e9694..cebf7a4 100644 --- a/_example/install.sh +++ b/_example/install.sh @@ -27,13 +27,15 @@ function __init_foobar() { mv ./foobar-*/foo "$pkg_src_cmd" } - # pkg_get_current_version is recommended, but (soon) not required + # pkg_get_current_version is recommended, but not required pkg_get_current_version() { # 'foo --version' has output in this format: # foobar 0.99.9 (rev abcdef0123) # This trims it down to just the version number: # 0.99.9 - echo $(foo --version 2> /dev/null | head -n 1 | cut -d ' ' -f 2) + foo --version 2> /dev/null | + head -n 1 | + cut -d ' ' -f 2 } } diff --git a/_webi/template.sh b/_webi/template.sh index 07f4761..eeed377 100644 --- a/_webi/template.sh +++ b/_webi/template.sh @@ -69,9 +69,9 @@ function __bootstrap_webi() { fi if [ -n "$(command -v pkg_format_cmd_version)" ]; then - my_versioned_name="$(pkg_format_cmd_version "$WEBI_VERSION")" + my_versioned_name="'$(pkg_format_cmd_version "$WEBI_VERSION")'" else - my_versioned_name="'$pkg_cmd_name' v$WEBI_VERSION" + my_versioned_name="'$pkg_cmd_name v$WEBI_VERSION'" fi echo "$my_versioned_name" @@ -107,32 +107,31 @@ function __bootstrap_webi() { my_current_cmd="$(command -v "$pkg_cmd_name")" set -e if [ -n "$my_current_cmd" ]; then - # TODO get version from symlink? - pkg_current_version="" - if [ -n "$(command -v pkg_get_current_version)" ]; then - pkg_current_version="$( - pkg_get_current_version 2> /dev/null | - head -n 1 - )" - fi - # remove trailing '.0's for golang's sake - my_current_version="$(echo "$pkg_current_version" | sed 's:\.0::g')" - my_src_version="$(echo "$WEBI_VERSION" | sed 's:\.0::g')" my_canonical_name="$(_webi_canonical_name)" - if [ "$my_src_version" == "$my_current_version" ]; then - echo "$my_canonical_name already installed at $my_current_cmd" - exit 0 - else - if [ "$my_current_cmd" != "$pkg_dst_cmd" ]; then - echo >&2 "WARN: possible conflict between $my_canonical_name and $pkg_current_version at $my_current_cmd" - fi - if [ -x "$pkg_src_cmd" ]; then - # shellcheck disable=2119 - # this function takes no args - webi_link - echo "switched to $my_canonical_name at $pkg_src" - exit 0 + if [ "$my_current_cmd" != "$pkg_dst_cmd" ]; then + echo >&2 "WARN: possible PATH conflict between $my_canonical_name and currently installed version" + echo >&2 " ${pkg_dst_cmd} (new)" + echo >&2 " ${my_current_cmd} (existing)" + #my_current_version=false + fi + # 'readlink' can't read links in paths on macOS 🤦 + # but that's okay, 'cmp -s' is good enough for us + if cmp -s "${pkg_src_cmd}" "${my_current_cmd}"; then + echo "${my_canonical_name} already installed:" + echo -n " ${pkg_dst}" + if [[ ${pkg_src_cmd} != "${my_current_cmd}" ]]; then + echo -n " => ${pkg_src}" fi + echo "" + exit 0 + fi + if [ -x "$pkg_src_cmd" ]; then + # shellcheck disable=2119 + # this function takes no args + webi_link + echo "switched to $my_canonical_name:" + echo " ${pkg_dst} => ${pkg_src}" + exit 0 fi fi export PATH="$my_path" @@ -340,7 +339,20 @@ function __bootstrap_webi() { ## # run everything with defaults or overrides as needed - if [ -n "$(command -v pkg_get_current_version)" ]; then + if command -v pkg_install > /dev/null || + command -v pkg_link > /dev/null || + command -v pkg_post_install > /dev/null || + command -v pkg_done_message > /dev/null || + command -v pkg_format_cmd_version > /dev/null || + [[ -n ${WEBI_SINGLE:-} ]] || + [[ -n ${pkg_cmd_name:-} ]] || + [[ -n ${pkg_dst_cmd:-} ]] || + [[ -n ${pkg_dst_dir:-} ]] || + [[ -n ${pkg_dst:-} ]] || + [[ -n ${pkg_src_cmd:-} ]] || + [[ -n ${pkg_src_dir:-} ]] || + [[ -n ${pkg_src:-} ]]; then + pkg_cmd_name="${pkg_cmd_name:-$PKG_NAME}" if [ -n "$WEBI_SINGLE" ]; then