From: AJ ONeal Date: Sun, 14 Jun 2020 06:20:53 +0000 (-0600) Subject: update flutter install X-Git-Url: https://git.josue.xyz/?a=commitdiff_plain;h=5a7fab00cfcff62659f2e50cf7bee859142795b7;p=webi-installers%2F.git update flutter install --- diff --git a/flutter/install.bash b/flutter/install.bash index 446e1e4..8be47b0 100644 --- a/flutter/install.bash +++ b/flutter/install.bash @@ -18,50 +18,86 @@ set -u # Install flutter # ################### -common_flutter_home="${HOME}/.local/opt/flutter" -new_flutter_home="${HOME}/.local/opt/flutter-v${WEBI_VERSION}" -new_flutter="${HOME}/.local/opt/flutter-v${WEBI_VERSION}/bin/flutter" +# The command name may be different from the package name +# (i.e. golang => go, rustlang => cargo, ripgrep => rg) +# Note: $HOME may contain special characters and should alway be quoted +pkg_cmd_name="flutter" +#pkg_cmd_name_formatted="flutter $WEBI_VERSION" -# Test for existing version -set +e -cur_flutter="$(command -v flutter)" -set -e -if [ -n "$cur_flutter" ]; then - cur_ver=$(flutter --version | head -n 1 | cut -d' ' -f2) - if [ "$cur_ver" == "$(echo $WEBI_VERSION)" ]; then - echo "flutter v$WEBI_VERSION already installed at $cur_flutter" - exit 0 - elif [ "$cur_flutter" != "$new_flutter" ]; then - echo "WARN: possible conflict with flutter v$WEBI_VERSION at $cur_flutter" - fi -fi +# Some of these directories may be the same +pkg_common_opt="$HOME/.local/opt/flutter" +pkg_common_bin="$HOME/.local/opt/flutter/bin" +pkg_common_cmd="$HOME/.local/opt/flutter/bin/flutter" +pkg_new_opt="$HOME/.local/opt/flutter-v$WEBI_VERSION" +pkg_new_bin="$HOME/.local/opt/flutter-v$WEBI_VERSION/bin" +pkg_new_cmd="$HOME/.local/opt/flutter-v$WEBI_VERSION/bin/flutter" +pkg_current_cmd="" -webi_download +# The version info should be reduced to a sortable version, without any leading characters +# (i.e. v12.8.0 => 12.8.0, go1.14 => 1.14, 1.12.13+hotfix => 1.12.13+hotfix) +pkg_get_current_version() { + echo "$(flutter --version 2>/dev/null | head -n 1 | cut -d' ' -f2)" +} -webi_extract +# Any version-related directories should be unlinked and relinked to the correct version +# (for example: 'go' is special and needs both $HOME/go and $HOME/.local/opt/go) +# (others like 'rg', 'hugo', and 'caddy' are single files that just get replaced) +pkg_switch_version() { + rm -rf "$pkg_common_opt" + ln -s "$pkg_new_opt" "$pkg_common_opt" +} + +# Different packages represent the version in different ways +# ex: node v12.8.0 (leading 'v') +# ex: go1.14 (no space, nor trailing '.0's) +# ex: flutter 1.17.2 (plain) +pkg_format_cmd_version() { + my_version=$1 + echo "$pkg_cmd_name $my_version" +} -pushd "${WEBI_TMP}" 2>&1 >/dev/null - echo Installing flutter v${WEBI_VERSION} as "$new_flutter" +pkg_install() { + pushd "$WEBI_TMP" 2>&1 >/dev/null # simpler for single-binary commands #mv ./example*/bin/example "$HOME/.local/bin" # best for packages and toolchains - rm -rf "$new_flutter_home" if [ -n "$(command -v rsync 2>/dev/null | grep rsync)" ]; then - rsync -Krl ./flutter*/ "$new_flutter_home/" 2>/dev/null + rsync -Krl ./flutter*/ "$pkg_new_opt/" 2>/dev/null else - cp -Hr ./flutter*/* "$new_flutter_home/" 2>/dev/null - cp -Hr ./flutter*/.* "$new_flutter_home/" 2>/dev/null + cp -Hr ./flutter*/* "$pkg_new_opt/" 2>/dev/null + cp -Hr ./flutter*/.* "$pkg_new_opt/" 2>/dev/null fi rm -rf ./flutter* -popd 2>&1 >/dev/null + popd 2>&1 >/dev/null +} -################### -# Update PATH # -################### +pkg_post_install() { + webi_path_add "$pkg_common_bin" +} + +# +# The webi_* functions are defined in webi/template.bash at https://github.com/webinstall/packages +# + +# for packages that can have multiple versions +webi_check +# for packages that can be downloaded via links in ./releases.js +webi_download +# for single files or packaged directories (compressed or uncompressed) +# supported formats: .xz, .tar.*, and .zip +webi_extract + +echo "Installing '$pkg_cmd_name' v$WEBI_VERSION as $pkg_new_cmd" + +# for installing the tool +pkg_install +# for updating paths and installing companion tools +pkg_post_install +# for re-linking to a previously installed version +pkg_switch_version + +echo "Installed '$pkg_cmd_name' v$WEBI_VERSION as $pkg_new_cmd" -# TODO get better output from pathman / output the path to add as return to webi bootstrap -webi_path_add "$new_flutter_home/bin" -echo "Installed 'flutter'" echo "" diff --git a/webi/template.bash b/webi/template.bash index 9b90b66..a3d9e7e 100644 --- a/webi/template.bash +++ b/webi/template.bash @@ -43,6 +43,34 @@ export WEBI_CURL="$(command -v curl)" export WEBI_WGET="$(command -v wget)" set -e +webi_check() { + # Test for existing version + set +e + pkg_current_cmd="$(command -v "$pkg_cmd_name")" + set -e + my_current_version="" + if [ -n "$pkg_current_cmd" ]; then + pkg_current_version="$(pkg_get_current_version)" + # remove trailing '.0's for golang's sake + my_current_version="$(echo $pkg_current_version | sed 's:\.0::g')" + my_new_version="$(echo $WEBI_VERSION | sed 's:\.0::g')" + my_canonical_name="$(pkg_format_cmd_version "$WEBI_VERSION")" + if [ "$my_new_version" == "$my_current_version" ]; then + echo "$my_canonical_name already installed at $pkg_current_cmd" + exit 0 + else + if [ "$pkg_current_cmd" != "$pkg_common_cmd" ]; then + echo "WARN: possible conflict between $my_canonical_name and $pkg_current_version at $pkg_current_cmd" + fi + if [ -x "$pkg_new_cmd" ]; then + pkg_switch_version + echo "switched to $my_canonical_name at $pkg_new_opt" + exit 0 + fi + fi + fi +} + webi_download() { if [ -n "${1:-}" ]; then my_url="$1"