From 72ca8260c80d0be73d5dfb8826ebb4972a96fa6f Mon Sep 17 00:00:00 2001 From: Serge Guzik Date: Thu, 14 Feb 2019 19:42:45 +0200 Subject: [PATCH] chore: Add install script --- install | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100755 install diff --git a/install b/install new file mode 100755 index 0000000..4ebe1f7 --- /dev/null +++ b/install @@ -0,0 +1,72 @@ +#!/usr/bin/env bash + +# install location +LOCATION=/usr/local/bin + +# platform IDs +LIN=linux +MAC=macos +WIN=windows + +# returns this platform ID +function get_this_platform() { + local this_platform="$(uname -s)" + case $this_platform in + Linux*) echo $LIN ;; + Darwin*) echo $MAC ;; + *) + echo "Error: Unsupported platform $this_platform" >&2 + fail + ;; + esac +} + +# actually sets this platform +THIS_PLATFORM=$(get_this_platform) + +# fetches latest release download link for the platform +function get_latest_warp_link() { + local this_platform=$1 + echo $(curl -fsSL "https://api.github.com/repos/dgiagio/warp/releases" \ + | grep "browser_download_url" \ + | grep "$this_platform-x64.warp-packer" \ + | head -n 1 \ + | awk '{print $2}' \ + | sed -e 's/"//g' + ) + if [[ $? != 0 ]]; then + echo "Error: Failed to get information about releases" >&2 + exit 1 + fi +} + +# downloads and installs single binary +function install() { + local name=$1 + local link=$2 + local temp_location="/tmp/$name" + echo "Downloading $name..." + curl -fsSL -o "$temp_location" "$link" + if [[ $? != 0 ]]; then + echo "Error: Failed to download $name" >&2 + exit 1 + fi + echo "Installing $name..." + chmod 755 "$temp_location" && \ + sudo chown root:root "$temp_location" && \ + sudo mkdir -p "$LOCATION" && \ + sudo mv "$temp_location" "$LOCATION/$name" + if [[ $? != 0 ]]; then + echo "Error: Failed to install $name" >&2 + exit 1 + fi +} + +WARP4J_LINK="https://raw.githubusercontent.com/guziks/warp4j/master/warp4j" + +echo "Getting information about warp-packer releases..." +WARP_LINK=$(get_latest_warp_link $THIS_PLATFORM) + +install "warp-packer" "$WARP_LINK" && \ +install "warp4j" "$WARP4J_LINK" && \ +echo "Successfully installed"