Skip to content

Instantly share code, notes, and snippets.

@brycied00d
Last active February 11, 2016 19:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brycied00d/767582bb107fb41986a2 to your computer and use it in GitHub Desktop.
Save brycied00d/767582bb107fb41986a2 to your computer and use it in GitHub Desktop.
Quick script to update Monit wih the binary release, since Debian's packages lag so far behind.
#!/bin/sh
# Script for Debian, which lags majorly behind on Monit releases.
# This will download the given version and overwrite Debian's binary and man-page,
# install a symlink to monitrc (Debian's package expects it in /etc/monit/monitrc,
# while the distributed binary expects /etc/monitrc), and installs the distributed
# example configuration at /etc/monit/monitrc.pkgdist
#
# Bryce Chidester <bryce@cobryce.com>
# Run as root
if [ ! "x`id -u`" = "x0" ] ; then
echo "This script must be run as root."
exit 1
fi
if [ ! -f /etc/debian_version ] ; then
echo "This script was designed to work only on Debian."
exit 1
fi
# Require version and architecture(?)
MONIT_VERSION=$1
if [ "x$MONIT_VERSION" = "x" ] ; then
echo "You must specifiy a Monit version, eg 5.16"
exit 1
fi
MONIT_ARCH=$2
if [ "x$MONIT_ARCH" = "x" ] ; then
MONIT_ARCH=`uname -m`
fi
# Interpret user- or uname input as a Monit-recognized architecture
case "$MONIT_ARCH" in
*86) # i586, i686
MONIT_ARCH=x86
;;
*64)
MONIT_ARCH=x64
;;
*arm*) # Untested
MONIT_ARCH=arm
;;
*)
echo "Unsupported architecture '$MONIT_ARCH'"
exit 1
;;
esac
# Check that everything is in-place to be overwritten
if [ ! -f /usr/bin/monit -o ! -f /usr/share/man/man1/monit.1.gz ] ; then
echo "Uh oh, something isn't write. Either /usr/bin/monit or /usr/share/man/man1/monit.1.gz aren't already present on your system. Perhaps Monit isn't already installed? Refusing to go forwards."
exit 1
fi
TD=$(mktemp -d) && \
curl -s https://mmonit.com/monit/dist/binary/${MONIT_VERSION}/monit-${MONIT_VERSION}-linux-${MONIT_ARCH}.tar.gz | tar -xzv --strip-components 1 -C "$TD" && \
install -o root -g root -m 0755 "$TD"/bin/monit /usr/bin/monit && \
gzip -9 "$TD"/man/man1/monit.1 && \
install -o root -g root -m 0644 "$TD"/man/man1/monit.1.gz /usr/share/man/man1/monit.1.gz && \
install -o root -g root -m 0600 "$TD"/conf/monitrc /etc/monit/monitrc.pkgdist && \
ln -sf /etc/monit/monitrc /etc/monitrc && \
echo "Done. Please remove the temporary directory: rm -fr \"$TD\""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment