2014-05-27 07:27:12 +02:00
|
|
|
#!/bin/sh
|
2013-11-03 13:45:26 +01:00
|
|
|
ICINGA2CONFDIR=@CMAKE_INSTALL_FULL_SYSCONFDIR@/icinga2
|
2013-09-27 11:16:35 +02:00
|
|
|
|
|
|
|
TOOL=$(basename -- $0)
|
|
|
|
|
2013-10-18 22:11:40 +02:00
|
|
|
if [ "$TOOL" != "icinga2-enable-feature" -a "$TOOL" != "icinga2-disable-feature" ]; then
|
|
|
|
echo "Invalid tool name ($TOOL). Should be 'icinga2-enable-feature' or 'icinga2-disable-feature'."
|
2013-09-27 11:16:35 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$1" ]; then
|
2014-05-30 09:55:23 +02:00
|
|
|
echo "Syntax: $TOOL <features separated with whitespaces>"
|
|
|
|
echo " Example: $TOOL checker notification mainlog"
|
2013-09-27 11:16:35 +02:00
|
|
|
|
2013-10-18 22:11:40 +02:00
|
|
|
if [ "$TOOL" = "icinga2-enable-feature" ]; then
|
2014-05-29 15:24:13 +02:00
|
|
|
echo "Enables the specified feature(s)."
|
2013-09-27 11:16:35 +02:00
|
|
|
else
|
2014-05-29 15:24:13 +02:00
|
|
|
echo "Disables the specified feature(s)."
|
2013-09-27 11:16:35 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo
|
2013-09-27 13:56:11 +02:00
|
|
|
echo -n "Available features: "
|
2013-09-27 11:16:35 +02:00
|
|
|
|
2013-09-27 11:22:18 +02:00
|
|
|
for file in $ICINGA2CONFDIR/features-available/*.conf; do
|
2013-10-01 08:39:42 +02:00
|
|
|
echo -n "$(basename -- $file .conf) "
|
2013-09-27 11:16:35 +02:00
|
|
|
done
|
|
|
|
|
2013-12-12 15:46:17 +01:00
|
|
|
echo
|
|
|
|
echo -n "Enabled features: "
|
|
|
|
|
|
|
|
for file in $ICINGA2CONFDIR/features-enabled/*.conf; do
|
|
|
|
echo -n "$(basename -- $file .conf) "
|
|
|
|
done
|
|
|
|
|
2013-09-27 11:16:35 +02:00
|
|
|
echo
|
|
|
|
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2014-05-26 19:54:39 +02:00
|
|
|
FEATURES=$1
|
|
|
|
|
|
|
|
for FEATURES
|
|
|
|
do
|
|
|
|
SKIP=""
|
|
|
|
# Define array var
|
|
|
|
# Based http://blog.isonoe.net/post/2010/09/24/Pseudo-arrays-for-POSIX-shell
|
|
|
|
eval "set -- $FEATURES"
|
|
|
|
for FEATURE
|
|
|
|
do
|
|
|
|
SKIP="NOTOK"
|
|
|
|
if [ ! -e $ICINGA2CONFDIR/features-available/$FEATURE.conf ]; then
|
|
|
|
echo "Feature '$FEATURE' does not exist."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$TOOL" = "icinga2-enable-feature" ]; then
|
|
|
|
if [ -e $ICINGA2CONFDIR/features-enabled/$FEATURE.conf ]; then
|
|
|
|
echo "The feature '$FEATURE' is already enabled."
|
|
|
|
SKIP="OK"
|
|
|
|
fi
|
|
|
|
if [ "$SKIP" != "OK" ]; then
|
|
|
|
if ! ln -s ../features-available/$FEATURE.conf $ICINGA2CONFDIR/features-enabled/; then
|
|
|
|
echo "Enabling '$FEATURE' failed. Check permissions for $ICINGA2CONFDIR/features-enabled/"
|
|
|
|
exit 1
|
|
|
|
else
|
2014-06-15 22:10:15 +02:00
|
|
|
echo "Module '$FEATURE' has been enabled."
|
2014-05-26 19:54:39 +02:00
|
|
|
RELOAD="YES"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
elif [ "$TOOL" = "icinga2-disable-feature" ]; then
|
|
|
|
if [ ! -e $ICINGA2CONFDIR/features-enabled/$FEATURE.conf ]; then
|
|
|
|
echo "The feature '$FEATURE' is already disabled."
|
|
|
|
SKIP="OK"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$SKIP" != "OK" ]; then
|
|
|
|
if ! rm -f $ICINGA2CONFDIR/features-enabled/$FEATURE.conf; then
|
|
|
|
echo "Disabling '$FEATURE' failed. Check permissions for $ICINGA2CONFDIR/features-enabled/$FEATURE.conf"
|
|
|
|
exit 1
|
|
|
|
else
|
2014-06-15 22:10:15 +02:00
|
|
|
echo "Feature '$FEATURE' has been disabled."
|
2014-05-26 19:54:39 +02:00
|
|
|
RELOAD="YES"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
done
|
|
|
|
if [ "$RELOAD" = "YES" ]; then
|
|
|
|
echo "Make sure to restart Icinga 2 for these changes to take effect."
|
2013-09-27 11:16:35 +02:00
|
|
|
fi
|
|
|
|
exit 0
|