{
DESTINATION="${PREFIX:-/usr/local/bin}/bake"
RELEASE="v${VERSION:-0.8.0}"
FILENAME=''
if uname -a | grep -qi 'x86_64.*GNU/Linux'; then
echo 'x86_64 GNU/Linux detected.'
FILENAME=bake-x86_64-unknown-linux-gnu
fi
if uname -a | grep -qi 'Darwin.*x86_64'; then
echo 'macOS detected.'
FILENAME=bake-x86_64-apple-darwin
fi
if [ -z "$FILENAME" ]; then
echo 'Unfortunately, there is no pre-built binary for this platform.' 1>&2
exit 1
fi
TEMPFILE=$(mktemp /tmp/bake.XXXXXXXX)
if ! curl "https://github.com/stepchowfun/bake/releases/download/$RELEASE/$FILENAME" -o "$TEMPFILE" -LSf; then
echo 'There was an error downloading the binary.' 1>&2
rm "$TEMPFILE"
exit 1
fi
if ! chmod a+rx "$TEMPFILE"; then
echo 'There was an error setting the permissions for the binary.' 1>&2
rm "$TEMPFILE"
exit 1
fi
mv "$TEMPFILE" "$DESTINATION" 2> /dev/null || sudo mv "$TEMPFILE" "$DESTINATION" < /dev/tty
echo 'Bake is now installed.'
}