Skip to content

Commit 0bfd31c

Browse files
committed
channel option
1 parent 6660830 commit 0bfd31c

File tree

3 files changed

+78
-13
lines changed

3 files changed

+78
-13
lines changed

src/dart/_common.sh

+7-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@ apt_get_update() {
99

1010
# Checks if packages are installed and installs them if not
1111
check_packages() {
12-
if ! dpkg -s "$@" > /dev/null 2>&1; then
12+
if ! dpkg -s "$@" >/dev/null 2>&1; then
1313
apt_get_update
1414
apt-get -y install --no-install-recommends "$@"
1515
fi
1616
}
17+
18+
check_git() {
19+
if [ ! -x "$(command -v git)" ]; then
20+
check_packages git
21+
fi
22+
}

src/dart/devcontainer-feature.json

+9-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,16 @@
55
"version": "1.0.0",
66
"options": {
77
"version": {
8-
"description": "Dart version",
8+
"description": "Select version of Dart SDK",
99
"type": "string",
10-
"default": "latest"
10+
"default": "latest",
11+
"proposals": ["latest", "3"]
12+
},
13+
"channel": {
14+
"description": "Select build channel of Dart SDK",
15+
"type": "string",
16+
"default": "stable",
17+
"enum": ["stable", "beta", "dev", "main"]
1118
}
1219
},
1320
"containerEnv": {

src/dart/install.sh

+62-10
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,93 @@
11
#!/usr/bin/env bash
22

33
VERSION=${VERSION:-"latest"}
4+
CHANNEL=${CHANNEL:-"stable"}
45

56
DART_SDK="/usr/lib/dart"
67

78
set -e
89
source _common.sh
910

1011
if [ "$(id -u)" -ne 0 ]; then
11-
echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
12-
exit 1
12+
echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
13+
exit 1
1314
fi
1415

1516
architecture="$(dpkg --print-architecture)"
1617
if [ "${architecture}" != "amd64" ] && [ "${architecture}" != "arm64" ]; then
17-
echo "(!) Architecture $architecture unsupported"
18-
exit 1
18+
echo "(!) Architecture $architecture unsupported"
19+
exit 1
1920
fi
2021

2122
# Clean up
2223
rm -rf /var/lib/apt/lists/*
2324

25+
find_version_from_git_tags() {
26+
local variable_name=$1
27+
local requested_version=${!variable_name}
28+
if [ "${requested_version}" = "none" ]; then return; fi
29+
local repository=$2
30+
local prefix=${3:-"tags/v"}
31+
local separator=${4:-"."}
32+
local last_part_optional=${5:-"false"}
33+
if [ "$(echo "${requested_version}" | grep -o "." | wc -l)" != "2" ]; then
34+
local escaped_separator=${separator//./\\.}
35+
local last_part
36+
if [ "${last_part_optional}" != "false" ]; then
37+
last_part="(${escaped_separator}[0-9]+)*.*${last_part_optional}"
38+
else
39+
last_part="${escaped_separator}[0-9]+"
40+
fi
41+
local regex="${prefix}\\K[0-9]+${escaped_separator}[0-9]+${last_part}$"
42+
local version_list
43+
check_git
44+
check_packages ca-certificates
45+
version_list="$(git ls-remote --tags "${repository}" | grep -oP "${regex}" | tr -d ' ' | tr "${separator}" "." | sort -rV)"
46+
if [ "${requested_version}" = "latest" ] || [ "${requested_version}" = "current" ] || [ "${requested_version}" = "lts" ]; then
47+
declare -g "${variable_name}"="$(echo "${version_list}" | head -n 1)"
48+
else
49+
set +e
50+
declare -g "${variable_name}"="$(echo "${version_list}" | grep -E -m 1 "^${requested_version//./\\.}([\\.\\s]|$)")"
51+
set -e
52+
fi
53+
fi
54+
if [ -z "${!variable_name}" ] || ! echo "${version_list}" | grep "^${!variable_name//./\\.}$" >/dev/null 2>&1; then
55+
echo -e "Invalid ${variable_name} value: ${requested_version}\nValid values:\n${version_list}" >&2
56+
exit 1
57+
fi
58+
echo "${variable_name}=${!variable_name}"
59+
}
60+
2461
export DEBIAN_FRONTEND=noninteractive
2562

2663
check_packages curl ca-certificates unzip
2764

2865
case "$architecture" in
2966
amd64)
30-
SDK_ARCH="x64"
31-
;;
67+
SDK_ARCH="x64"
68+
;;
3269
arm64)
33-
SDK_ARCH="arm64"
34-
;;
70+
SDK_ARCH="arm64"
71+
;;
3572
esac
3673

37-
if [ "${VERSION}" = "latest" ]; then
38-
URL="https://storage.googleapis.com/dart-archive/channels/be/raw/latest/sdk/dartsdk-linux-${SDK_ARCH}-release.zip"
74+
if [ "${CHANNEL}" = "main" ]; then
75+
URL="https://storage.googleapis.com/dart-archive/channels/be/raw/latest/sdk/dartsdk-linux-${SDK_ARCH}-release.zip"
76+
else
77+
if [ "${CHANNEL}" = "stable" ]; then
78+
LAST_PART="false"
79+
elif [ "${CHANNEL}" = "beta" ]; then
80+
LAST_PART="beta"
81+
elif [ "${CHANNEL}" = "dev" ]; then
82+
LAST_PART="dev"
83+
else
84+
echo "(!) Channel ${CHANNEL} unsupported"
85+
exit 1
86+
fi
87+
# Soft version matching
88+
find_version_from_git_tags VERSION "https://github.com/dart-lang/sdk" "tags/v" "." "${LAST_PART}"
89+
90+
URL="https://storage.googleapis.com/dart-archive/channels/${CHANNEL}/release/${VERSION}/sdk/dartsdk-linux-${SDK_ARCH}-release.zip"
3991
fi
4092

4193
echo "Downloading Dart..."

0 commit comments

Comments
 (0)