2021-09-02 09:48:48 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -o pipefail -o errexit -o nounset
|
|
|
|
|
2023-06-05 15:05:24 +00:00
|
|
|
# Validate necessary commands and given config file
|
|
|
|
for cmd in jq curl sha256sum; do
|
|
|
|
if ! command -v $cmd &> /dev/null; then
|
|
|
|
echo "$cmd could not be found, please install it."
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2022-07-15 19:43:07 +00:00
|
|
|
CONFIG="${1:-fluence.json}"
|
|
|
|
|
2023-06-05 15:05:24 +00:00
|
|
|
if [[ ! -f "$CONFIG" ]]; then
|
|
|
|
echo "Config file $CONFIG not found!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Detect system architecture
|
|
|
|
ARCHITECTURE=$(uname -m)
|
|
|
|
|
|
|
|
# Map common architecture names to the ones used in your JSON
|
|
|
|
case "$ARCHITECTURE" in
|
|
|
|
x86_64)
|
|
|
|
KEY="x86_64"
|
|
|
|
;;
|
|
|
|
aarch64)
|
|
|
|
KEY="aarch64"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Unsupported architecture: $ARCHITECTURE. Exiting..."
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# Fetch URL, SHA256, and version based on detected architecture
|
|
|
|
URL=$(jq -r ".${KEY}.url" $CONFIG)
|
|
|
|
SHA256=$(jq -r ".${KEY}.sha256" $CONFIG)
|
|
|
|
VERSION=$(jq -r ".${KEY}.version" $CONFIG)
|
|
|
|
|
2023-06-05 15:26:43 +00:00
|
|
|
echo "*** Downloading nox version $VERSION for $ARCHITECTURE ***"
|
2023-06-05 15:05:24 +00:00
|
|
|
|
|
|
|
ATTEMPTS=5
|
|
|
|
while ((ATTEMPTS)); do
|
2023-07-20 19:53:35 +00:00
|
|
|
curl -L $URL -o /usr/bin/nox && break
|
2023-06-05 15:05:24 +00:00
|
|
|
((ATTEMPTS--))
|
|
|
|
sleep 5
|
|
|
|
done
|
|
|
|
|
|
|
|
if ! ((ATTEMPTS)); then
|
|
|
|
echo "Failed to download $URL after 5 attempts. Exiting..."
|
2023-06-05 20:21:28 +00:00
|
|
|
cat "$CONFIG"
|
2023-06-05 15:05:24 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-06-05 15:26:43 +00:00
|
|
|
if ! echo "$SHA256 /usr/bin/nox" | sha256sum --check --status; then
|
2023-06-05 15:05:24 +00:00
|
|
|
echo "Incorrect SHA256 for the downloaded file. Exiting..."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-06-05 15:26:43 +00:00
|
|
|
chmod +x /usr/bin/nox
|
2023-06-05 15:05:24 +00:00
|
|
|
|
2023-06-05 15:26:43 +00:00
|
|
|
echo "*** Successfully installed nox version $VERSION for $ARCHITECTURE ***"
|