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