X-Git-Url: https://git.josue.xyz/?a=blobdiff_plain;f=flutter%2Finstall.bash;h=8be47b08b20296f8ef66e209bb87554f1fb8133b;hb=5a7fab00cfcff62659f2e50cf7bee859142795b7;hp=446e1e45021a7d20876fc5b5bd61e3aa5405e0b6;hpb=525a3b3c1113670c0a0e06cca8a86647fe5ef958;p=webi-installers%2F.git 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 ""