1 #!/usr/bin/env nix-shell
2 #!nix-shell -i bash -p curl jq
6 # so if the script fails, debug logs are on stderr
8 >&2 echo "DART_UPDATER: $@"
11 # fetch the latest version number from upstream
12 NEW_VER_DETAILS
=$
(curl
-sL https
://storage.googleapis.com
/dart-archive
/channels
/stable
/release
/latest
/VERSION
)
13 NEW_VER
=$
(jq
-r '.version' <<< "$NEW_VER_DETAILS")
15 MY_PATH
=$
(dirname $
(realpath
"$0"))
18 log
"file to write is $SRC_FILE"
20 PRELUDE
="let version = \"$NEW_VER\"; in
22 versionUsed = version;"
23 echo "$PRELUDE" > "$SRC_FILE"
26 # Fetches the source, then writes the fetcher and hash into the sources file.
28 # - $1: VARIABLE NAME of (table of nix platform -> dart platform mappings) ("DARWIN_PLATFORMS"|"LIN_PLATFORMS")
29 # - $2: Dart-OS ("macos"|"linux")
30 write_for_platform
() {
31 BASE_OF_ALL_URLS
='https://storage.googleapis.com/dart-archive/channels/stable/release'
32 BASE_URL_WRITTEN
="$BASE_OF_ALL_URLS/\${version}/sdk"
33 BASE_URL_FETCHED
="$BASE_OF_ALL_URLS/$NEW_VER/sdk"
36 declare -n TABLE
=$TABLE_NAME
38 for platform
in "${!TABLE[@]}"; do
39 DART_PLATFORM
="${TABLE[$platform]}"
40 log
"trying for dartplatform $DART_PLATFORM (platform $platform) (OS $2)"
42 URL_POSTFIX
="dartsdk-$2-$DART_PLATFORM-release.zip"
43 URL
="$BASE_URL_FETCHED/$URL_POSTFIX"
44 log
"URL for $DART_PLATFORM: $URL"
46 HASH
=$
(nix-prefetch-url
"$URL" --type sha256
)
47 log
"hash for platform $platform: $HASH"
49 FETCHER
=" \"\${version}-$platform\" = fetchurl {
50 url = \"$BASE_URL_WRITTEN/$URL_POSTFIX\";
54 echo "$FETCHER" >> $SRC_FILE
60 # Map nix platforms -> Dart platforms
64 declare -A DARWIN_PLATFORMS
=(["aarch64-darwin"]="$AARCH64"
65 ["x86_64-darwin"]="$X8664")
67 declare -A LIN_PLATFORMS
=( ["x86_64-linux"]="$X8664"
68 ["i686-linux"]="$I686"
69 ["aarch64-linux"]="$AARCH64")
71 write_for_platform
"DARWIN_PLATFORMS" "macos"
72 write_for_platform
"LIN_PLATFORMS" "linux"
76 log
"moving tempfile to target directory"
77 mv "$SRC_FILE" "$MY_PATH/sources.nix"