Skip to content

Commit e52c664

Browse files
rgee0alexellis
authored andcommitted
Add SHA checking to get.sh download script
SHA256 checksum files were recently added to the releases page. This change uses these in order to check the received binary. A new function has been introduced called checkHash which checks that shasum is available on the system and if it does goes on to test the newly received binary against the checksum calculated at build time. A subshell is invoked within this function as shasum needs to be called in the same dir aas the binary and this location can vary depending on the user context. Using a subshell means the directory switching is transparent to the user, who remains where they started regardless of the script outcome. Signed-off-by: Richard Gee <richard@technologee.co.uk>
1 parent d33cb5c commit e52c664

1 file changed

Lines changed: 23 additions & 5 deletions

File tree

get.sh

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@ hasCli() {
3030
fi
3131
}
3232

33+
checkHash(){
34+
if [ -x "$(command -v shasum)" ]; then
35+
36+
targetFileDir=${targetFile%/*}
37+
38+
(cd $targetFileDir && curl -sSL $url.sha256|shasum -c -s)
39+
40+
if [ "$?" != "0" ]; then
41+
rm $targetFile
42+
echo "Binary checksum didn't match. Exiting"
43+
exit 1
44+
fi
45+
fi
46+
}
3347

3448
getPackage() {
3549
uname=$(uname)
@@ -56,10 +70,10 @@ getPackage() {
5670
;;
5771
esac
5872

59-
targetFile="/tmp/faas-cli"
73+
targetFile="/tmp/faas-cli$suffix"
6074

6175
if [ "$userid" != "0" ]; then
62-
targetFile="$(pwd)/faas-cli"
76+
targetFile="$(pwd)/faas-cli$suffix"
6377
fi
6478

6579
if [ -e $targetFile ]; then
@@ -69,10 +83,12 @@ getPackage() {
6983
url=https://github.com/openfaas/faas-cli/releases/download/$version/faas-cli$suffix
7084
echo "Downloading package $url as $targetFile"
7185

72-
curl -sSL $url > $targetFile
86+
curl -sSL $url --output $targetFile
7387

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

90+
checkHash
91+
7692
chmod +x $targetFile
7793

7894
echo "Download complete."
@@ -85,7 +101,7 @@ getPackage() {
85101
echo "== following commands may need to be run manually =="
86102
echo "========================================================="
87103
echo
88-
echo " sudo cp faas-cli /usr/local/bin/"
104+
echo " sudo cp faas-cli$suffix /usr/local/bin/faas-cli"
89105
echo " sudo ln -sf /usr/local/bin/faas-cli /usr/local/bin/faas"
90106
echo
91107

@@ -94,7 +110,7 @@ getPackage() {
94110
echo
95111
echo "Running as root - Attemping to move faas-cli to /usr/local/bin"
96112

97-
mv $targetFile /usr/local/bin/
113+
mv $targetFile /usr/local/bin/faas-cli
98114

99115
if [ "$?" = "0" ]; then
100116
echo "New version of faas-cli installed to /usr/local/bin"
@@ -108,6 +124,8 @@ getPackage() {
108124
ln -s /usr/local/bin/faas-cli /usr/local/bin/faas
109125
echo "Creating alias 'faas' for 'faas-cli'."
110126
fi
127+
128+
faas-cli version
111129
fi
112130
fi
113131
}

0 commit comments

Comments
 (0)