The README for scripts has an incorrect use of the `set`. Where it says to use: set -oue pipefail it should be: set -euo pipefail since `pipefail` is an option consumed by `set -o`. More information: https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html
39 lines
534 B
Bash
39 lines
534 B
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
NAME=$1
|
|
FORMAT=$2
|
|
URL=$3
|
|
DEST=$4
|
|
|
|
mkdir -p "$DEST"
|
|
|
|
DOWNLOAD=$(ls "$DEST" | wc -l)
|
|
FILE="$NAME.$FORMAT"
|
|
|
|
if [[ $DOWNLOAD -eq 0 ]] && [[ -n $NAME ]]; then
|
|
|
|
echo "Downloading $FILE"
|
|
|
|
curl -o "$FILE" -OL "$URL"
|
|
|
|
if [[ -f "$FILE" ]]; then
|
|
|
|
case $FORMAT in
|
|
|
|
tar.xz) tar xvJf "$FILE" -C "$DEST" ;;
|
|
zip) unzip "$FILE" -d "$DEST" ;;
|
|
|
|
esac
|
|
|
|
rm -rf "$FILE"
|
|
|
|
echo "$FILE downloaded"
|
|
|
|
else
|
|
|
|
echo "Unable to download $FILE"
|
|
|
|
fi
|
|
|
|
fi
|