]> granicus.if.org Git - icinga2/blob - tools/icinga2-enable-feature.cmake
Remove debug output in icinga2-enable-feature.
[icinga2] / tools / icinga2-enable-feature.cmake
1 #!/bin/sh
2 ICINGA2CONFDIR=@CMAKE_INSTALL_FULL_SYSCONFDIR@/icinga2
3
4 TOOL=$(basename -- $0)
5
6 if [ "$TOOL" != "icinga2-enable-feature" -a "$TOOL" != "icinga2-disable-feature" ]; then
7         echo "Invalid tool name ($TOOL). Should be 'icinga2-enable-feature' or 'icinga2-disable-feature'."
8         exit 1
9 fi
10
11 if [ -z "$1" ]; then
12         echo "Syntax: $TOOL <features separated with whitespaces>"
13         echo "  Example: $TOOL checker notification mainlog"
14
15         if [ "$TOOL" = "icinga2-enable-feature" ]; then
16                 echo "Enables the specified feature(s)."
17         else
18                 echo "Disables the specified feature(s)."
19         fi
20
21         echo
22         echo -n "Available features: "
23
24         for file in $ICINGA2CONFDIR/features-available/*.conf; do
25                 echo -n "$(basename -- $file .conf) "
26         done
27
28         echo
29         echo -n "Enabled features: "
30
31         for file in $ICINGA2CONFDIR/features-enabled/*.conf; do
32                 echo -n "$(basename -- $file .conf) "
33         done
34
35         echo
36
37         exit 1
38 fi
39
40 FEATURES=$1
41
42 for FEATURES
43 do
44         SKIP=""
45         # Define array var
46         # Based http://blog.isonoe.net/post/2010/09/24/Pseudo-arrays-for-POSIX-shell
47         eval "set -- $FEATURES"
48         for FEATURE
49         do
50                 SKIP="NOTOK"
51                 if [ ! -e $ICINGA2CONFDIR/features-available/$FEATURE.conf ]; then
52                         echo "Feature '$FEATURE' does not exist."
53                         exit 1
54                 fi
55
56                 if [ "$TOOL" = "icinga2-enable-feature" ]; then
57                         if [ -e $ICINGA2CONFDIR/features-enabled/$FEATURE.conf ]; then
58                                 echo "The feature '$FEATURE' is already enabled."
59                                 SKIP="OK"
60                         fi
61                         if [ "$SKIP" != "OK" ]; then
62                                 if ! ln -s ../features-available/$FEATURE.conf $ICINGA2CONFDIR/features-enabled/; then
63                                 echo "Enabling '$FEATURE' failed. Check permissions for $ICINGA2CONFDIR/features-enabled/"
64                                         exit 1
65                                 else
66                                         echo "Module '$FEATURE' was enabled."
67                                         RELOAD="YES"
68                                 fi
69                         fi
70                 elif [ "$TOOL" = "icinga2-disable-feature" ]; then
71                         if [ ! -e $ICINGA2CONFDIR/features-enabled/$FEATURE.conf ]; then
72                                 echo "The feature '$FEATURE' is already disabled."
73                                 SKIP="OK"
74                         fi
75
76                         if [ "$SKIP" != "OK" ]; then
77                                 if ! rm -f $ICINGA2CONFDIR/features-enabled/$FEATURE.conf; then
78                                 echo "Disabling '$FEATURE' failed. Check permissions for $ICINGA2CONFDIR/features-enabled/$FEATURE.conf"
79                                         exit 1
80                                 else
81                                         echo "Feature '$FEATURE' was disabled."
82                                         RELOAD="YES"
83                                 fi
84                         fi
85                 fi
86         done
87 done
88 if [ "$RELOAD" = "YES" ]; then
89         echo "Make sure to restart Icinga 2 for these changes to take effect."
90 fi
91 exit 0