0ad1f2906665d21976f144b420c4597581f568ac
[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_src, pkg_src_bin, pkg_src_cmd
20 #       pkg_dst, pkg_dst_bin, pkg_dst_cmd
21 #
22 # Their defaults are defined in webi/template.bash at https://github.com/webinstall/packages
23
24 pkg_cmd_name="flutter"
25
26 pkg_get_current_version() {
27     # 'flutter --version' outputs a lot of information:
28     #       Flutter 1.19.0-4.1.pre • channel beta • https://github.com/flutter/flutter.git
29     #       Framework • revision f994b76974 (4 days ago) • 2020-06-09 15:53:13 -0700
30     #       Engine • revision 9a28c3bcf4
31     #       Tools • Dart 2.9.0 (build 2.9.0-14.1.beta)
32     # This trims it down to just the version number:
33     #       1.19.0-4.1.pre
34     echo "$(flutter --version 2>/dev/null | head -n 1 | cut -d' ' -f2)"
35 }
36
37 pkg_link_src_dst() {
38     # 'pkg_dst' will default to $HOME/.local/opt/flutter
39     # 'pkg_src' will be the installed version, such as to $HOME/.local/opt/flutter-v1.17.3
40     rm -rf "$pkg_dst"
41     ln -s "$pkg_src" "$pkg_dst"
42 }
43
44 pkg_pre_install() {
45     # web_* are defined in webi/template.bash at https://github.com/webinstall/packages
46
47     # multiple versions may be installed
48     # if one already matches, it will simply be re-linked
49     webi_check
50
51     # the download is quite large - hopefully you have wget installed
52     # will go to ~/Downloads by default
53     webi_download
54
55     # Multiple formats are supported: .xz, .tar.*, and .zip
56     # will be extracted to $WEBI_TMP
57     webi_extract
58 }
59
60 pkg_install() {
61     pushd "$WEBI_TMP" 2>&1 >/dev/null
62
63         # remove the versioned folder, just in case it's there with junk
64         rm -rf "$pkg_src"
65
66         # rename the entire extracted folder to the new location
67         # (this will be "$HOME/.local/opt/flutter-v$WEBI_VERSION" by default)
68         mv ./flutter* "$pkg_src"
69
70     popd 2>&1 >/dev/null
71 }
72
73 pkg_post_install() {
74     pkg_link_src_dst
75
76     # web_path_add is defined in webi/template.bash at https://github.com/webinstall/packages
77     # Adds "$HOME/.local/opt/flutter" to PATH
78     webi_path_add "$pkg_dst_bin"
79 }