From 3cd06768b5487261ddde819aad6428a3183ffbbf Mon Sep 17 00:00:00 2001 From: Mark Schouten Date: Mon, 17 Aug 2015 16:48:22 +0200 Subject: [PATCH] Place all plugins in a repo-dir and add mk_enplug to enable plugins --- Makefile | 4 +++- mk_enplug | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100755 mk_enplug diff --git a/Makefile b/Makefile index 00e019e..f8c18c6 100644 --- a/Makefile +++ b/Makefile @@ -2,10 +2,12 @@ PREFIX=${CURDIR}/debian/librenms-agent install: mkdir -p $(PREFIX)/usr/lib/check_mk_agent/plugins + mkdir -p $(PREFIX)/usr/lib/check_mk_agent/repo mkdir -p $(PREFIX)/usr/lib/check_mk_agent/local - cp -r agent-local/* $(PREFIX)/usr/lib/check_mk_agent/plugins/ + cp -r agent-local/* $(PREFIX)/usr/lib/check_mk_agent/repo/ mkdir -p $(PREFIX)/usr/bin install -m 0750 check_mk_agent $(PREFIX)/usr/bin/check_mk_agent + install -m 0750 mk_enplug $(PREFIX)/usr/bin/mk_enplug mkdir -p $(PREFIX)/etc/xinetd.d install -m 0644 check_mk_xinetd $(PREFIX)/etc/xinetd.d/check_mk diff --git a/mk_enplug b/mk_enplug new file mode 100755 index 0000000..06c5752 --- /dev/null +++ b/mk_enplug @@ -0,0 +1,48 @@ +#!/bin/bash + +plugdir=/usr/lib/check_mk_agent/plugins +repodir=/usr/lib/check_mk_agent/repo + +findscripts() { + find ${repodir} -type f | sed -e "s#$repodir/##g" +} + +script_enabled() { + s=$1 + + if [ -L ${plugdir}/${s} ]; then + echo "yes" + else + echo "no" + fi +} + +enable_script() { + s=$1 + + ln -s ${repodir}/${s} ${plugdir}/${s} + echo "Enabled $s" +} + +scripts=$(findscripts) + +if [ ! -z "$1" ]; then + s=$1 +else + echo "Which plugin do you want to enable?" + echo ${scripts} + read s +fi + +echo "Enabling $s" + +if [ ! -z "$s" ]; then + if [ ! -r ${repodir}/${s} ]; then + echo "Plugin $s does not exist!" + exit 1 + fi + + if [ `script_enabled $s` != "yes" ]; then + enable_script $s + fi +fi