1#!/usr/bin/env bash 2# Copyright 2016 The Chromium Authors. All rights reserved. 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6 7# ---------------------------------- NOTE ---------------------------------- # 8# 9# Please keep the logic in this file consistent with the logic in the 10# `update_dart_sdk.ps1` script in the same directory to ensure that Flutter 11# continues to work across all platforms! 12# 13# -------------------------------------------------------------------------- # 14 15set -e 16 17FLUTTER_ROOT="$(dirname "$(dirname "$(dirname "${BASH_SOURCE[0]}")")")" 18 19DART_SDK_PATH="$FLUTTER_ROOT/bin/cache/dart-sdk" 20DART_SDK_PATH_OLD="$DART_SDK_PATH.old" 21ENGINE_STAMP="$FLUTTER_ROOT/bin/cache/engine-dart-sdk.stamp" 22ENGINE_VERSION=`cat "$FLUTTER_ROOT/bin/internal/engine.version"` 23 24if [ ! -f "$ENGINE_STAMP" ] || [ "$ENGINE_VERSION" != `cat "$ENGINE_STAMP"` ]; then 25 command -v curl > /dev/null 2>&1 || { 26 echo 27 echo 'Missing "curl" tool. Unable to download Dart SDK.' 28 case "$(uname -s)" in 29 Darwin) 30 echo 'Consider running "brew install curl".' 31 ;; 32 Linux) 33 echo 'Consider running "sudo apt-get install curl".' 34 ;; 35 *) 36 echo "Please install curl." 37 ;; 38 esac 39 echo 40 exit 1 41 } 42 echo "Downloading Dart SDK from Flutter engine $ENGINE_VERSION..." 43 44 case "$(uname -s)" in 45 Darwin) 46 DART_ZIP_NAME="dart-sdk-darwin-x64.zip" 47 IS_USER_EXECUTABLE="-perm +100" 48 ;; 49 Linux) 50 DART_ZIP_NAME="dart-sdk-linux-x64.zip" 51 IS_USER_EXECUTABLE="-perm /u+x" 52 ;; 53 *) 54 echo "Unknown operating system. Cannot install Dart SDK." 55 exit 1 56 ;; 57 esac 58 59 DART_SDK_BASE_URL="${FLUTTER_STORAGE_BASE_URL:-https://storage.googleapis.com}" 60 DART_SDK_URL="$DART_SDK_BASE_URL/flutter_infra/flutter/$ENGINE_VERSION/$DART_ZIP_NAME" 61 62 # if the sdk path exists, copy it to a temporary location 63 if [ -d "$DART_SDK_PATH" ]; then 64 rm -rf "$DART_SDK_PATH_OLD" 65 mv "$DART_SDK_PATH" "$DART_SDK_PATH_OLD" 66 fi 67 68 # install the new sdk 69 rm -rf -- "$DART_SDK_PATH" 70 mkdir -m 755 -p -- "$DART_SDK_PATH" 71 DART_SDK_ZIP="$FLUTTER_ROOT/bin/cache/$DART_ZIP_NAME" 72 73 curl --continue-at - --location --output "$DART_SDK_ZIP" "$DART_SDK_URL" 2>&1 || { 74 echo 75 echo "Failed to retrieve the Dart SDK from: $DART_SDK_URL" 76 echo "If you're located in China, please see this page:" 77 echo " https://flutter.dev/community/china" 78 echo 79 rm -f -- "$DART_SDK_ZIP" 80 exit 1 81 } 82 unzip -o -q "$DART_SDK_ZIP" -d "$FLUTTER_ROOT/bin/cache" || { 83 echo 84 echo "It appears that the downloaded file is corrupt; please try again." 85 echo "If this problem persists, please report the problem at:" 86 echo " https://github.com/flutter/flutter/issues/new?template=ACTIVATION.md" 87 echo 88 rm -f -- "$DART_SDK_ZIP" 89 exit 1 90 } 91 rm -f -- "$DART_SDK_ZIP" 92 find "$DART_SDK_PATH" -type d -exec chmod 755 {} \; 93 find "$DART_SDK_PATH" -type f $IS_USER_EXECUTABLE -exec chmod a+x,a+r {} \; 94 echo "$ENGINE_VERSION" > "$ENGINE_STAMP" 95 96 # delete any temporary sdk path 97 if [ -d "$DART_SDK_PATH_OLD" ]; then 98 rm -rf "$DART_SDK_PATH_OLD" 99 fi 100fi 101