Skip to content

Commit f68b2b5

Browse files
committed
feat(install.sh): add support for --mainline (default) and --stable
1 parent ac8d1c6 commit f68b2b5

File tree

1 file changed

+32
-14
lines changed

1 file changed

+32
-14
lines changed

install.sh

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,21 @@ The remote host must have internet access.
2626
${not_curl_usage-}
2727
Usage:
2828
29-
$arg0 [--dry-run] [--version X.X.X] [--edge] [--method detect] \
29+
${arg0} [--dry-run] [--mainline | --stable | --version X.X.X] [--method detect] \
3030
[--prefix ~/.local] [--rsh ssh] [user@host]
3131
3232
--dry-run
3333
Echo the commands for the install process without running them.
3434
35+
--mainline
36+
Install the latest mainline version (default).
37+
38+
--stable
39+
Install the latest stable version instead of the latest mainline version.
40+
3541
--version X.X.X
3642
Install a specific version instead of the latest.
3743
38-
--edge
39-
Install the latest edge version instead of the latest stable version.
40-
4144
--method [detect | standalone]
4245
Choose the installation method. Defaults to detect.
4346
- detect detects the system package manager and tries to use it.
@@ -89,15 +92,26 @@ EOF
8992
}
9093

9194
echo_latest_version() {
92-
if [ "${EDGE-}" ]; then
93-
version="$(curl -fsSL https://api.github.com/repos/coder/coder/releases | awk 'match($0,/.*"html_url": "(.*\/releases\/tag\/.*)".*/)' | head -n 1 | awk -F '"' '{print $4}')"
94-
else
95+
if [ "${MAINLINE}" = 0 ]; then
9596
# https://gist.github.com/lukechilds/a83e1d7127b78fef38c2914c4ececc3c#gistcomment-2758860
9697
version="$(curl -fsSLI -o /dev/null -w "%{url_effective}" https://github.com/coder/coder/releases/latest)"
97-
fi
98-
version="${version#https://github.com/coder/coder/releases/tag/}"
99-
version="${version#v}"
100-
echo "$version"
98+
version="${version#https://github.com/coder/coder/releases/tag/v}"
99+
else
100+
# Fetch the releases from the GitHub API, sort by version number,
101+
# and take the first result. Note that we're sorting by space-
102+
# separated numbers and without utilizing the sort -V flag for the
103+
# best compatibility.
104+
version="$(
105+
curl -fsSL https://api.github.com/repos/coder/coder/releases \
106+
| awk -F'"' '/"tag_name"/ {print $4}' \
107+
| tr -d v \
108+
| tr . ' ' \
109+
| sort -k1,1nr -k2,2nr -k3,3nr \
110+
| head -n1 \
111+
| tr ' ' .
112+
)"
113+
fi
114+
echo "${version}"
101115
}
102116

103117
echo_standalone_postinstall() {
@@ -224,6 +238,7 @@ EOF
224238
}
225239

226240
main() {
241+
MAINLINE=1
227242
TERRAFORM_VERSION="1.6.6"
228243

229244
if [ "${TRACE-}" ]; then
@@ -236,7 +251,6 @@ main() {
236251
OPTIONAL \
237252
ALL_FLAGS \
238253
RSH_ARGS \
239-
EDGE \
240254
RSH \
241255
WITH_TERRAFORM \
242256
CAP_NET_ADMIN
@@ -282,8 +296,12 @@ main() {
282296
--version=*)
283297
VERSION="$(parse_arg "$@")"
284298
;;
285-
--edge)
286-
EDGE=1
299+
# Support edge for backwards compatibility.
300+
--mainline | --edge)
301+
MAINLINE=1
302+
;;
303+
--stable)
304+
MAINLINE=0
287305
;;
288306
--rsh)
289307
RSH="$(parse_arg "$@")"

0 commit comments

Comments
 (0)