Created
April 8, 2017 01:19
-
-
Save sungwoncho/cfd65605f6f4ff6e4b572926a3ef2c85 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -eu | |
not_supported() { | |
echo "OS not supported: ${UNAME}" | |
echo "Please compile manually from https://github.com/dnote-io/cli" | |
exit 1 | |
} | |
install() { | |
UNAME=$(uname) | |
if [ "$UNAME" != "Linux" -a "$UNAME" != "Darwin" -a "$UNAME" != "OpenBSD" ] ; then | |
not_supported | |
fi | |
if [ "$UNAME" = "Darwin" ]; then | |
OSX_ARCH=$(uname -m) | |
if [ "${OSX_ARCH}" = "x86_64" ]; then | |
PLATFORM="darwin_amd64" | |
else | |
not_supported | |
fi | |
elif [ "$UNAME" = "Linux" ]; then | |
LINUX_ARCH=$(uname -m) | |
if [ "${LINUX_ARCH}" = "x86_64" ]; then | |
PLATFORM="linux_amd64" | |
elif [ "${LINUX_ARCH}" = "i686" ]; then | |
PLATFORM="linux_386" | |
else | |
not_supported | |
fi | |
elif [ "$UNAME" = "OpenBSD" ]; then | |
OPENBSD_ARCH=$(uname -m) | |
if [ "${OPENBSD_ARCH}" = "x86_64" ]; then | |
PLATFORM="openbsd_amd64" | |
elif [ "${OPENBSD_ARCH}" = "i686" ]; then | |
PLATFORM="openbsd_386" | |
else | |
not_supported | |
fi | |
fi | |
LATEST=$(curl -s https://api.github.com/repos/dnote-io/cli/tags | grep -Eo '"name":.*[^\\]",' | head -n 1 | sed 's/[," ]//g' | cut -d ':' -f 2) | |
URL="https://github.com/dnote-io/cli/releases/download/$LATEST/dnote_$PLATFORM" | |
DEST=${DEST:-/usr/local/bin/dnote} | |
if [ -z $LATEST ]; then | |
echo "Error fetching latest version. Please try again." | |
exit 1 | |
fi | |
echo "Downloading Dnote binary from $URL to $DEST" | |
if curl -L --progress-bar $URL -o $DEST; then | |
chmod +x $DEST | |
echo "Successfully installed Dnote" | |
else | |
echo "Installation failed. You might need elevated permission." | |
fi | |
} | |
install | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment