Skip to content
Permalink
Browse files

Make get.sh generic for cross repo sharing

Currently the get.sh scripts across a number of repos are roughly based off the faas-cli file with bespoke changes made depending upon the needs of the respective projects.

This change make the faas-cli script generic enough so that the common content can be used across all the repos without any changes.  The only changes required to tailor the file's operation to the respective repo are to be made in the repo specific content section.

Also adds a check for a git bash signature to enable downloading of the .exe variant when running on git bash on Windows.

Signed-off-by: Richard Gee <richard@technologee.co.uk>
  • Loading branch information...
rgee0 authored and alexellis committed Nov 1, 2019
1 parent a01f394 commit dea8d361be62bdf7a50f6a1f63a702548321a5cb
Showing with 61 additions and 13 deletions.
  1. +61 −13 get.sh
74 get.sh
@@ -1,20 +1,32 @@
#!/bin/bash
# This script was adapted from https://github.com/openfaas/cli.openfaas.com/blob/master/get.sh

# Copyright OpenFaaS Author(s) 2019
#########################
# Repo specific content #
#########################

export VERIFY_CHECKSUM=0
export ALIAS=""
export OWNER=alexellis
export REPO=k3sup
export SUCCESS_CMD="$REPO version"
export BINLOCATION="/usr/local/bin"

version=$(curl -sI https://github.com/$OWNER/$REPO/releases/latest | grep Location | awk -F"/" '{ printf "%s", $NF }' | tr -d '\r')
###############################
# Content common across repos #
###############################

version=$(curl -sI https://github.com/$OWNER/$REPO/releases/latest | grep Location | awk -F"/" '{ printf "%s", $NF }' | tr -d '\r')
if [ ! $version ]; then
echo "Failed while attempting to install $REPO. Please manually install:"
echo ""
echo "1. Open your web browser and go to https://github.com/$OWNER/$REPO/releases"
echo "2. Download the latest release for your platform. Call it '$REPO'."
echo "3. chmod +x ./$REPO"
echo "4. mv ./$REPO $BINLOCATION"
if [ -n "$ALIAS_NAME" ]; then
echo "5. ln -sf $BINLOCATION/$REPO /usr/local/bin/$ALIAS_NAME"
fi
exit 1
fi

@@ -27,12 +39,33 @@ hasCli() {
fi
}

checkHash(){

sha_cmd="sha256sum"

if [ ! -x "$(command -v $sha_cmd)" ]; then
sha_cmd="shasum -a 256"
fi

if [ -x "$(command -v $sha_cmd)" ]; then

targetFileDir=${targetFile%/*}

(cd $targetFileDir && curl -sSL $url.sha256|$sha_cmd -c >/dev/null)

if [ "$?" != "0" ]; then
rm $targetFile
echo "Binary checksum didn't match. Exiting"
exit 1
fi
fi
}

getPackage() {
uname=$(uname)
userid=$(id -u)

suffix=""

case $uname in
"Darwin")
suffix="-darwin"
@@ -46,7 +79,6 @@ getPackage() {
"Linux")
arch=$(uname -m)
echo $arch

case $arch in
"aarch64")
suffix="-arm64"
@@ -60,10 +92,10 @@ getPackage() {
;;
esac

targetFile="/tmp/$REPO"

targetFile="/tmp/$REPO$suffix"
if [ "$userid" != "0" ]; then
targetFile="$(pwd)/$REPO"
targetFile="$(pwd)/$REPO$suffix"
fi

if [ -e $targetFile ]; then
@@ -73,15 +105,19 @@ getPackage() {
url=https://github.com/$OWNER/$REPO/releases/download/$version/$REPO$suffix
echo "Downloading package $url as $targetFile"

curl -sSLf $url --output $targetFile
curl -sSL $url --output $targetFile

if [ "$?" = "0" ]; then

if [ "$VERIFY_CHECKSUM" = "1" ]; then
checkHash
fi

chmod +x $targetFile

echo "Download complete."

if [ ! -w "$BINLOCATION" ]; then
if [ ! -w "$BINLOCATION" ]; then

echo
echo "============================================================"
@@ -90,7 +126,12 @@ getPackage() {
echo " following commands may need to be run manually."
echo "============================================================"
echo
echo " sudo cp $REPO $BINLOCATION/$REPO"
echo " sudo cp $REPO$suffix $BINLOCATION/$REPO"

if [ -n "$ALIAS_NAME" ]; then
echo " sudo ln -sf $BINLOCATION/$REPO $BINLOCATION/$ALIAS_NAME"
fi

echo

else
@@ -112,7 +153,7 @@ getPackage() {
fi

mv $targetFile $BINLOCATION/$REPO

if [ "$?" = "0" ]; then
echo "New version of $REPO installed to $BINLOCATION"
fi
@@ -121,7 +162,14 @@ getPackage() {
rm $targetFile
fi

${SUCCESS_CMD}
if [ -n "$ALIAS_NAME" ]; then
if [ ! -L $BINLOCATION/$ALIAS_NAME ]; then
ln -s $BINLOCATION/$REPO $BINLOCATION/$ALIAS_NAME
echo "Creating alias '$ALIAS_NAME' for '$REPO'."
fi
fi

${SUCCESS_CMD}
fi
fi
}

0 comments on commit dea8d36

Please sign in to comment.
You can’t perform that action at this time.