move more install logic to webi/template.bash
[webi-installers/.git] / flutter / install.bash
index 77a97c2af5377ddf077f6186f6f8a120fc325bc2..3223a99fd2b8a43943216d0207a148c76d25792f 100644 (file)
 set -e
 set -u
 
-###################
-# Install flutter #
-###################
+# NOTE: pkg_* variables can be defined here
+#       pkg_cmd_name
+#       pkg_new_opt, pkg_new_bin, pkg_new_cmd
+#       pkg_common_opt, pkg_common_bin, pkg_common_cmd
+#
+# Their defaults are defined in webi/template.bash at https://github.com/webinstall/packages
 
-new_flutter_home="${HOME}/.local/opt/flutter-v${WEBI_VERSION}"
-new_flutter="${HOME}/.local/opt/flutter-v${WEBI_VERSION}/bin/flutter"
+pkg_get_current_version() {
+    # 'flutter --version' outputs a lot of information:
+    #       Flutter 1.19.0-4.1.pre • channel beta • https://github.com/flutter/flutter.git
+    #       Framework • revision f994b76974 (4 days ago) • 2020-06-09 15:53:13 -0700
+    #       Engine • revision 9a28c3bcf4
+    #       Tools • Dart 2.9.0 (build 2.9.0-14.1.beta)
+    # This trims it down to just the version number:
+    #       1.19.0-4.1.pre
+    echo "$(flutter --version 2>/dev/null | head -n 1 | cut -d' ' -f2)"
+}
 
-# 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
+pkg_link_new_version() {
+    # 'pkg_common_opt' will default to $HOME/.local/opt/flutter
+    # 'pkg_new_opt' will be the installed version, such as to $HOME/.local/opt/flutter-v1.17.3
+    rm -rf "$pkg_common_opt"
+    ln -s "$pkg_new_opt" "$pkg_common_opt"
+}
+
+pkg_pre_install() {
+    # web_* are defined in webi/template.bash at https://github.com/webinstall/packages
+
+    # multiple versions may be installed
+    # if one already matches, it will simply be re-linked
+    webi_check
+
+    # the download is quite large - hopefully you have wget installed
+    # will go to ~/Downloads by default
+    webi_download
 
-webi_download
+    # Multiple formats are supported: .xz, .tar.*, and .zip
+    # will be extracted to $WEBI_TMP
+    webi_extract
+}
 
-webi_extract
+pkg_install() {
+    pushd "$WEBI_TMP" 2>&1 >/dev/null
 
-pushd "${WEBI_TMP}" 2>&1 >/dev/null
-        echo Installing flutter v${WEBI_VERSION} as "$new_flutter" 
+        # remove the versioned folder, just in case it's there with junk
+        rm -rf "$pkg_new_opt"
 
-        # simpler for single-binary commands
-        #mv ./example*/bin/example "$HOME/.local/bin"
+        # rename the entire extracted folder to the new location
+        # (this will be "$HOME/.local/opt/flutter-v$WEBI_VERSION" by default)
+        mv ./flutter* "$pkg_new_opt"
 
-        # 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
-        else
-          cp -Hr ./flutter*/* "$new_flutter_home/" 2>/dev/null
-          cp -Hr ./flutter*/.* "$new_flutter_home/" 2>/dev/null
-        fi
-popd 2>&1 >/dev/null
+    popd 2>&1 >/dev/null
+}
 
-###################
-#   Update PATH   #
-###################
+pkg_post_install() {
+    # web_path_add is defined in webi/template.bash at https://github.com/webinstall/packages
 
-# 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 ""
+    # Adds "$HOME/.local/opt/flutter-v$WEBI_VERSION" to PATH
+    webi_path_add "$pkg_common_bin"
+}