From fcd558f6ea1f2e095f71af22bd86cb58ea64a16f Mon Sep 17 00:00:00 2001 From: David Newhall II Date: Wed, 3 Jul 2019 22:04:29 -0700 Subject: [PATCH] add install script --- integrations/inputunifi/scripts/install.sh | 92 ++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100755 integrations/inputunifi/scripts/install.sh diff --git a/integrations/inputunifi/scripts/install.sh b/integrations/inputunifi/scripts/install.sh new file mode 100755 index 00000000..9bf9bfe5 --- /dev/null +++ b/integrations/inputunifi/scripts/install.sh @@ -0,0 +1,92 @@ +#!/bin/bash + +# This is a quick and drity script to install the latest Linux package. +# +# Use it like this: (sudo is optional) +# === +# curl https://raw.githubusercontent.com/davidnewhall/unifi-poller/master/scripts/install.sh | sudo bash +# === +# If you're on redhat, this installs the latest rpm. If you're on Debian, it installs the latest deb package. +# + +REPO=davidnewhall/unifi-poller +LATEST=https://api.github.com/repos/${REPO}/releases/latest +ARCH=$(uname -m) + +# $ARCH is passed into egrep to find the right file. +if [ "$ARCH" = "x86_64" ]; then + ARCH="$ARCH|amd64" +elif [ "$ARCH" = "amd64" ]; then + ARCH="$ARCH|x86_64" +elif [[ $ARCH == *arm* ]]; then + ARCH="arm" +else + echo "Unknown Architecture. Submit a pull request to fix this, please." + echo ==> $ARCH + exit 1 +fi + +if [ "$1" == "deb" ] || [ "$1" == "rpm" ]; then + FILE=$1 +else + # If you have both, rpm wins. + rpm --version > /dev/null 2>&1 + if [ "$?" = "0" ]; then + FILE=rpm + else + dpkg --version > /dev/null 2>&1 + if [ "$?" = "0" ]; then + FILE=deb + fi + fi +fi + +if [ "$FILE" = "" ]; then + echo "No dpkg or rpm package managers found!" + exit 1 +fi + +# curl or wget? +curl --version > /dev/null 2>&1 +if [ "$?" = "0" ]; then + CMD="curl -L" +else + wget --version > /dev/null 2>&1 + if [ "$?" = "0" ]; then + CMD="wget -O-" + fi +fi + +if [ "$CMD" = "" ]; then + echo "Need curl or wget - could not find either!" + exit 1 +fi + +# Grab latest release file from github. +URL=$($CMD ${LATEST} | egrep "browser_download_url.*\.(${ARCH}).${FILE}\"" | cut -d\" -f 4) + +if [ "$?" != "0" ] || [ "$URL" = "" ]; then + echo "Error locating latest release at ${LATEST}" + exit 1 +fi + +INSTALLER="rpm -Uvh" +if [ "$FILE" = "deb" ]; then + INSTALLER="dpkg -i" +fi + +FILE=$(basename ${URL}) +echo "Downloading: ${URL} to /tmp/${FILE}" +$CMD ${URL} > /tmp/${FILE} + +# Install it. +if [ "$(id -u)" = "0" ]; then + echo "===================================" + echo "Downloaded. Installing the package!" + echo "Running: ${INSTALLER} /tmp/${FILE}" + $INSTALLER /tmp/${FILE} +else + echo "================================" + echo "Downloaded. Install the package:" + echo "sudo $INSTALLER /tmp/${FILE}" +fi