update for latest API
[webi-installers/.git] / flutter / flutter.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 ###################
18 # Install flutter #
19 ###################
20
21 new_flutter_home="${HOME}/.local/opt/flutter-v${WEBI_VERSION}"
22 new_flutter="${HOME}/.local/opt/flutter-v${WEBI_VERSION}/bin/flutter"
23
24 # Test for existing version 
25 set +e
26 cur_flutter="$(command -v flutter)"
27 set -e
28 if [ -n "$cur_flutter" ]; then
29   cur_ver=$(flutter --version | head -n 1 | cut -d' ' -f2)
30   if [ "$cur_ver" == "$(echo $WEBI_VERSION)" ]; then
31     echo "flutter v$WEBI_VERSION already installed at $cur_flutter"
32     exit 0
33   elif [ "$cur_flutter" != "$new_flutter" ]; then
34     echo "WARN: possible conflict with flutter v$WEBI_VERSION at $cur_flutter"
35   fi
36 fi
37
38 webi_download
39
40 webi_extract
41
42 pushd "${WEBI_TMP}" 2>&1 >/dev/null
43         echo Installing flutter v${WEBI_VERSION} as "$new_flutter" 
44
45         # simpler for single-binary commands
46         #mv ./example*/bin/example "$HOME/.local/bin"
47
48         # best for packages and toolchains
49         rm -rf "$new_flutter_home"
50         if [ -n "$(command -v rsync 2>/dev/null | grep rsync)" ]; then
51           rsync -Krl ./flutter*/ "$new_flutter_home/" 2>/dev/null
52         else
53           cp -Hr ./flutter*/* "$new_flutter_home/" 2>/dev/null
54           cp -Hr ./flutter*/.* "$new_flutter_home/" 2>/dev/null
55         fi
56 popd 2>&1 >/dev/null
57
58 ###################
59 #   Update PATH   #
60 ###################
61
62 # TODO get better output from pathman / output the path to add as return to webi bootstrap
63 webi_path_add "$new_flutter_home/bin"
64 echo "Installed 'flutter'"
65 echo ""