Skip to content

Commit a7640cf

Browse files
erikwilsonibuildthecloud
authored andcommitted
Download latest release for install script
Check for latest release of k3s or pass a desired version as an argument. Adds curl as a requirement and early exits if not available. Fixes silent abort when wget is not available and `which` returns non-zero exit code.
1 parent af9ea1d commit a7640cf

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

Diff for: install.sh

+18-13
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#!/bin/sh
22
set -e
33

4-
VERSION=v0.1.0
5-
64
info()
75
{
86
echo "[INFO] " "$@"
@@ -14,6 +12,18 @@ fatal()
1412
exit 1
1513
}
1614

15+
if [ -z `which curl || true` ]; then
16+
fatal "Can not find curl for downloading files"
17+
fi
18+
19+
if [ -n "$1" ]; then
20+
VERSION=$1
21+
else
22+
info "Finding latest release"
23+
VERSION=`curl -w "%{url_effective}" -I -L -s -S https://github.com/rancher/k3s/releases/latest -o /dev/null | sed -e 's|.*/||'`
24+
fi
25+
info "Using $VERSION as release"
26+
1727
ARCH=`uname -m`
1828

1929
case $ARCH in
@@ -87,19 +97,14 @@ EOF
8797
$SUDO chown root:root $TMPUNINSTALL
8898
$SUDO mv -f $TMPUNINSTALL /usr/local/bin/k3s-uninstall.sh
8999

90-
CURL=`which curl`
91-
92-
if [ -n "$CURL" ]; then
93-
TMPHASH=`mktemp -t k3s-install.XXXXXXXXXX`
94-
TMPBIN=`mktemp -t k3s-install.XXXXXXXXXX`
100+
TMPHASH=`mktemp -t k3s-install.XXXXXXXXXX`
101+
TMPBIN=`mktemp -t k3s-install.XXXXXXXXXX`
95102

96-
info Downloading $HASHURL
97-
$CURL -o $TMPHASH -sfL $HASHURL
98-
99-
info Downloading $BINURL
100-
$CURL -o $TMPBIN -sfL $BINURL
101-
fi
103+
info Downloading $HASHURL
104+
curl -o $TMPHASH -sfL $HASHURL
102105

106+
info Downloading $BINURL
107+
curl -o $TMPBIN -sfL $BINURL
103108

104109
info Verifying download
105110
EXPECTED=`grep k3s $TMPHASH | awk '{print $1}'`

0 commit comments

Comments
 (0)