add install script
This commit is contained in:
parent
2b1c274c2b
commit
fcd558f6ea
|
|
@ -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
|
||||
Loading…
Reference in New Issue