Skip to content

Commit 65f8d18

Browse files
authored
feat(install.sh): add support for --mainline (default) and --stable (coder#12858)
Fixes coder#12461
1 parent 426e9f2 commit 65f8d18

File tree

1 file changed

+57
-20
lines changed

1 file changed

+57
-20
lines changed

install.sh

Lines changed: 57 additions & 20 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.
@@ -88,16 +91,25 @@ The installer will cache all downloaded assets into ~/.cache/coder
8891
EOF
8992
}
9093

91-
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-
# https://gist.github.com/lukechilds/a83e1d7127b78fef38c2914c4ececc3c#gistcomment-2758860
96-
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"
94+
echo_latest_stable_version() {
95+
# https://gist.github.com/lukechilds/a83e1d7127b78fef38c2914c4ececc3c#gistcomment-2758860
96+
version="$(curl -fsSLI -o /dev/null -w "%{url_effective}" https://github.com/coder/coder/releases/latest)"
97+
version="${version#https://github.com/coder/coder/releases/tag/v}"
98+
echo "${version}"
99+
}
100+
101+
echo_latest_mainline_version() {
102+
# Fetch the releases from the GitHub API, sort by version number,
103+
# and take the first result. Note that we're sorting by space-
104+
# separated numbers and without utilizing the sort -V flag for the
105+
# best compatibility.
106+
curl -fsSL https://api.github.com/repos/coder/coder/releases |
107+
awk -F'"' '/"tag_name"/ {print $4}' |
108+
tr -d v |
109+
tr . ' ' |
110+
sort -k1,1nr -k2,2nr -k3,3nr |
111+
head -n1 |
112+
tr ' ' .
101113
}
102114

103115
echo_standalone_postinstall() {
@@ -106,9 +118,18 @@ echo_standalone_postinstall() {
106118
return
107119
fi
108120

121+
channel=mainline
122+
advisory="To install our stable release (v${STABLE_VERSION}), use the --stable flag. "
123+
if [ "${MAINLINE}" = 0 ]; then
124+
channel=stable
125+
advisory=""
126+
fi
127+
109128
cath <<EOF
110129
111-
Coder has been installed to
130+
Coder ${channel} release v${VERSION} installed. ${advisory}See our releases documentation or GitHub for more information on versioning.
131+
132+
The Coder binary has been placed in the following location:
112133
113134
$STANDALONE_INSTALL_PREFIX/bin/$STANDALONE_BINARY_NAME
114135
@@ -218,12 +239,13 @@ There is another binary in your PATH that conflicts with the binary we've instal
218239
219240
This is likely because of an existing installation of Coder. See our documentation for suggestions on how to resolve this.
220241
221-
https://coder.com/docs/v2/latest/install/install.sh#path-conflicts
242+
https://coder.com/docs/v2/latest/install/install.sh#path-conflicts
222243
223244
EOF
224245
}
225246

226247
main() {
248+
MAINLINE=1
227249
TERRAFORM_VERSION="1.6.6"
228250

229251
if [ "${TRACE-}" ]; then
@@ -236,7 +258,6 @@ main() {
236258
OPTIONAL \
237259
ALL_FLAGS \
238260
RSH_ARGS \
239-
EDGE \
240261
RSH \
241262
WITH_TERRAFORM \
242263
CAP_NET_ADMIN
@@ -282,8 +303,12 @@ main() {
282303
--version=*)
283304
VERSION="$(parse_arg "$@")"
284305
;;
285-
--edge)
286-
EDGE=1
306+
# Support edge for backward compatibility.
307+
--mainline | --edge)
308+
MAINLINE=1
309+
;;
310+
--stable)
311+
MAINLINE=0
287312
;;
288313
--rsh)
289314
RSH="$(parse_arg "$@")"
@@ -364,7 +389,12 @@ main() {
364389
TERRAFORM_INSTALL_PREFIX=${TERRAFORM_INSTALL_PREFIX:-/usr/local}
365390
STANDALONE_INSTALL_PREFIX=${STANDALONE_INSTALL_PREFIX:-/usr/local}
366391
STANDALONE_BINARY_NAME=${STANDALONE_BINARY_NAME:-coder}
367-
VERSION=${VERSION:-$(echo_latest_version)}
392+
STABLE_VERSION=$(echo_latest_stable_version)
393+
if [ "${MAINLINE}" = 0 ]; then
394+
VERSION=${STABLE_VERSION}
395+
else
396+
VERSION=$(echo_latest_mainline_version)
397+
fi
368398

369399
distro_name
370400

@@ -378,6 +408,13 @@ main() {
378408
with_terraform
379409
fi
380410

411+
# If the version is the same as the stable version, we're installing
412+
# the stable version.
413+
if [ "${MAINLINE}" != 0 ] && [ "${VERSION}" = "${STABLE_VERSION}" ]; then
414+
echoh "The latest mainline version has been promoted to stable, selecting stable."
415+
MAINLINE=0
416+
fi
417+
381418
# Standalone installs by pulling pre-built releases from GitHub.
382419
if [ "$METHOD" = standalone ]; then
383420
if has_standalone; then

0 commit comments

Comments
 (0)