Skip to content

Commit

Permalink
Download latest release for install script
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
erikwilson committed Mar 1, 2019
1 parent af9ea1d commit abbad07
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#!/bin/sh
set -e

<<<<<<< HEAD
VERSION=v0.1.0

=======
>>>>>>> Download latest release for install script
info()
{
echo "[INFO] " "$@"
Expand All @@ -14,6 +17,18 @@ fatal()
exit 1
}

if [ -z `which curl || true` ]; then
fatal "Can not find curl for downloading files"
fi

if [ -n "$1" ]; then
VERSION=$1
else
info "Finding latest release"
VERSION=`curl -w "%{url_effective}" -I -L -s -S https://github.com/rancher/k3s/releases/latest -o /dev/null | sed -e 's|.*/||'`
fi
info "Using $VERSION as release"

ARCH=`uname -m`

case $ARCH in
Expand Down Expand Up @@ -87,19 +102,22 @@ EOF
$SUDO chown root:root $TMPUNINSTALL
$SUDO mv -f $TMPUNINSTALL /usr/local/bin/k3s-uninstall.sh

<<<<<<< HEAD
CURL=`which curl`

if [ -n "$CURL" ]; then
TMPHASH=`mktemp -t k3s-install.XXXXXXXXXX`
TMPBIN=`mktemp -t k3s-install.XXXXXXXXXX`
=======
TMPHASH=`mktemp -t k3s-install.XXXXXXXXXX`
TMPBIN=`mktemp -t k3s-install.XXXXXXXXXX`
>>>>>>> Download latest release for install script

info Downloading $HASHURL
$CURL -o $TMPHASH -sfL $HASHURL

info Downloading $BINURL
$CURL -o $TMPBIN -sfL $BINURL
fi
info Downloading $HASHURL
curl -o $TMPHASH -sfL $HASHURL

info Downloading $BINURL
curl -o $TMPBIN -sfL $BINURL

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

0 comments on commit abbad07

Please sign in to comment.