Skip to content

Commit

Permalink
fix: In setup action check if sudo is available
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterSchafer committed Jul 8, 2024
1 parent a1346e4 commit daff165
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions setup/setup_snyk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ echo "Installing the $1 version of Snyk on $2"

VERSION=$1
BASE_URL="https://static.snyk.io/cli"
SUDO_CMD="sudo"

case "$2" in
Linux)
Expand All @@ -50,13 +51,20 @@ esac
echo eval snyk-${PREFIX} \$@
} > snyk

if ! command -v "$SUDO_CMD" &> /dev/null; then
echo "$SUDO_CMD is NOT installed. Trying without sudo, expecting privileges to write to '/usr/local/bin'."
SUDO_CMD=""
else
echo "$SUDO_CMD is installed."
fi

chmod +x snyk
sudo mv snyk /usr/local/bin
${SUDO_CMD} mv snyk /usr/local/bin

curl --compressed --retry 2 --output snyk-${PREFIX} "$BASE_URL/$VERSION/snyk-${PREFIX}"
curl --compressed --retry 2 --output snyk-${PREFIX}.sha256 "$BASE_URL/$VERSION/snyk-${PREFIX}.sha256"

sha256sum -c snyk-${PREFIX}.sha256
chmod +x snyk-${PREFIX}
sudo mv snyk-${PREFIX} /usr/local/bin
${SUDO_CMD} mv snyk-${PREFIX} /usr/local/bin
rm -rf snyk*

0 comments on commit daff165

Please sign in to comment.