3223a99fd2b8a43943216d0207a148c76d25792f
[webi-installers/.git] / flutter / install.bash
1 #!/bin/bash
2
3 # title: Flutter
4 # homepage: https://flutter.dev
5 # tagline: UI Toolkit for mobile, web, and desktop
6 # description: |
7 #   Flutter is Google’s UI toolkit for building beautiful, natively compiled applications for mobile, web, and desktop from a single codebase.
8 # examples: |
9 #
10 #   ```bash
11 #   flutter create my_app
12 #   ```
13
14 set -e
15 set -u
16
17 # NOTE: pkg_* variables can be defined here
18 #       pkg_cmd_name
19 #       pkg_new_opt, pkg_new_bin, pkg_new_cmd
20 #       pkg_common_opt, pkg_common_bin, pkg_common_cmd
21 #
22 # Their defaults are defined in webi/template.bash at https://github.com/webinstall/packages
23
24 pkg_get_current_version() {
25     # 'flutter --version' outputs a lot of information:
26     #       Flutter 1.19.0-4.1.pre • channel beta • https://github.com/flutter/flutter.git
27     #       Framework • revision f994b76974 (4 days ago) • 2020-06-09 15:53:13 -0700
28     #       Engine • revision 9a28c3bcf4
29     #       Tools • Dart 2.9.0 (build 2.9.0-14.1.beta)
30     # This trims it down to just the version number:
31     #       1.19.0-4.1.pre
32     echo "$(flutter --version 2>/dev/null | head -n 1 | cut -d' ' -f2)"
33 }
34
35 pkg_link_new_version() {
36     # 'pkg_common_opt' will default to $HOME/.local/opt/flutter
37     # 'pkg_new_opt' will be the installed version, such as to $HOME/.local/opt/flutter-v1.17.3
38     rm -rf "$pkg_common_opt"
39     ln -s "$pkg_new_opt" "$pkg_common_opt"
40 }
41
42 pkg_pre_install() {
43     # web_* are defined in webi/template.bash at https://github.com/webinstall/packages
44
45     # multiple versions may be installed
46     # if one already matches, it will simply be re-linked
47     webi_check
48
49     # the download is quite large - hopefully you have wget installed
50     # will go to ~/Downloads by default
51     webi_download
52
53     # Multiple formats are supported: .xz, .tar.*, and .zip
54     # will be extracted to $WEBI_TMP
55     webi_extract
56 }
57
58 pkg_install() {
59     pushd "$WEBI_TMP" 2>&1 >/dev/null
60
61         # remove the versioned folder, just in case it's there with junk
62         rm -rf "$pkg_new_opt"
63
64         # rename the entire extracted folder to the new location
65         # (this will be "$HOME/.local/opt/flutter-v$WEBI_VERSION" by default)
66         mv ./flutter* "$pkg_new_opt"
67
68     popd 2>&1 >/dev/null
69 }
70
71 pkg_post_install() {
72     # web_path_add is defined in webi/template.bash at https://github.com/webinstall/packages
73
74     # Adds "$HOME/.local/opt/flutter-v$WEBI_VERSION" to PATH
75     webi_path_add "$pkg_common_bin"
76 }