aboutsummaryrefslogtreecommitdiff
path: root/network/nagios/nagios.SlackBuild
blob: 66834c497e05f1d1e9818f6fbf58d644a397d3fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#!/bin/bash

# Slackware build script for nagios

# Copyright 2009-2013 Niels Horn, Rio de Janeiro, RJ, Brazil
# Copyright 2014, 2015, 2016, 2017  Mario Preksavec, Zagreb, Croatia
# All rights reserved.
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

cd $(dirname $0) ; CWD=$(pwd)

PRGNAM=nagios
VERSION=${VERSION:-4.3.4}
BUILD=${BUILD:-1}
TAG=${TAG:-_SBo}
PKGTYPE=${PKGTYPE:-tgz}

if [ -z "$ARCH" ]; then
  case "$( uname -m )" in
    i?86) ARCH=i586 ;;
    arm*) ARCH=arm ;;
       *) ARCH=$( uname -m ) ;;
  esac
fi

DOCROOT=${DOCROOT:-/var/www/htdocs}

# To create valid symlinks, we need a relative path from DOCROOT
RELPATH=""
for i in $(echo $DOCROOT | tr "/" " "); do
  RELPATH="${RELPATH}../"
done

# If the variable PRINT_PACKAGE_NAME is set, then this script will report what
# the name of the created package would be, and then exit. This information
# could be useful to other scripts.
if [ ! -z "${PRINT_PACKAGE_NAME}" ]; then
  echo "$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE"
  exit 0
fi

TMP=${TMP:-/tmp/SBo}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}

if [ "$ARCH" = "i586" ]; then
  SLKCFLAGS="-O2 -march=i586 -mtune=i686"
  LIBDIRSUFFIX=""
elif [ "$ARCH" = "i686" ]; then
  SLKCFLAGS="-O2 -march=i686 -mtune=i686"
  LIBDIRSUFFIX=""
elif [ "$ARCH" = "x86_64" ]; then
  SLKCFLAGS="-O2 -fPIC"
  LIBDIRSUFFIX="64"
else
  SLKCFLAGS="-O2"
  LIBDIRSUFFIX=""
fi

USERNAME=${USERNAME:-nagios}
GROUPNAME=${GROUPNAME:-nagios}
USERID=${USERID:-213}
GROUPID=${GROUPID:-213}
HOMEDIR=${HOMEDIR:-/var/nagios}
SHELLNAME=${SHELLNAME:-/bin/bash}

GETUSER=$(getent passwd $USERNAME)
GETGROUP=$(getent group $GROUPNAME)

set -e

if [ -z "$GETUSER" -o -z "$GETGROUP" ]; then
  printf "\n  You must have a \"$PRGNAM\" user and a group to run this script\n\n"
  [ -z "$GETGROUP" ] && printf "  # groupadd -g $GROUPID $GROUPNAME\n"
  [ -z "$GETUSER" ] && printf "  # useradd -u $USERID -d $HOMEDIR -s $SHELLNAME -g $GROUPNAME $USERNAME\n"
  printf "\n"
  exit 1
fi

if [[ ! $GETUSER =~ ^$USERNAME:[^:]+:$USERID:$GROUPID:[^:]*:$HOMEDIR:$SHELLNAME$ ]]; then
  printf "\n  You must update the \"$PRGNAM\" user to run this script\n\n"
  [[ $GETUSER =~ ^[^:]+:[^:]+:[^:]+:[^:]+:[^:]*:([^:]+):([^:]+)$ ]]
  [ "${BASH_REMATCH[1]}" != "$HOMEDIR" ] && printf "  # usermod -d $HOMEDIR $USERNAME\n"
  [ "${BASH_REMATCH[2]}" != "$SHELLNAME" ] && printf "  # usermod -s $SHELLNAME $USERNAME\n"
  printf "\n"
  exit 1
fi

rm -rf $PKG
mkdir -p $TMP $PKG $OUTPUT
cd $TMP
rm -rf $PRGNAM
tar xvf $CWD/$PRGNAM-$VERSION.tar.gz
cd $PRGNAM-$VERSION
chown -R root:root .
find -L . \
 \( -perm 777 -o -perm 775 -o -perm 750 -o -perm 711 -o -perm 555 \
  -o -perm 511 \) -exec chmod 755 {} \; -o \
 \( -perm 666 -o -perm 664 -o -perm 640 -o -perm 600 -o -perm 444 \
  -o -perm 440 -o -perm 400 \) -exec chmod 644 {} \;

CFLAGS="$SLKCFLAGS -w -Wl,--allow-multiple-definition" \
  ./configure \
  --prefix=/usr \
  --sbindir=/usr/sbin/$PRGNAM \
  --datadir=$DOCROOT/$PRGNAM \
  --libdir=/usr/lib${LIBDIRSUFFIX} \
  --libexecdir=/usr/libexec/$PRGNAM \
  --sysconfdir=/etc/$PRGNAM \
  --localstatedir=/var/$PRGNAM \
  --mandir=/usr/man \
  --build=$ARCH-slackware-linux \
  --with-httpd-conf=/etc/httpd/extra \
  --with-checkresult-dir=/var/spool/$PRGNAM \
  --with-init-dir=/etc/rc.d \
  --with-lockfile=/var/run/nagios/nagios.lock

make all

export DESTDIR=$PKG
echo "*** make install ***"
make install
echo "*** make install-init ***"
make install-init
echo "*** make install-commandmode ***"
make install-commandmode
echo "*** make install-config ***"
make install-config
# Need to create the $PKG/etc/httpd/extra directory (this is a bug in Makefile.in)
mkdir -p $PKG/etc/httpd/extra
echo "*** make install-webconf ***"
make install-webconf
# Following upstream, the "exfoliation" theme is now the default...
echo "*** make install-exfoliation ***"
make install-exfoliation
# ...but, if you prefer the "classic" theme, uncomment the next two lines, as they
#    will overwrite the new theme:
#echo "*** make install-classicui ***"
#make install-classicui

find $PKG | xargs file | grep -e "executable" -e "shared object" | grep ELF \
  | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null || true

# Use monitoring-plugins instead of nagios-plugins
sed -i 's#\($USER1$=/usr/libexec/\)nagios#\1monitoring-plugins#' \
  $PKG/etc/nagios/resource.cfg

# Change configuration files to .new
find $PKG/etc/$PRGNAM/ -name *.cfg | while read cfg ; do mv $cfg $cfg.new ; done
mv $PKG/etc/httpd/extra/nagios.conf $PKG/etc/httpd/extra/nagios.conf.new
# cfg files may contain passwords, so we don't want 'others' to read them
chmod -R g-w,o-rx $PKG/etc/$PRGNAM

# Create directory for lock-file
mkdir -p $PKG/var/run/nagios

# Change init script and leave it -x
mv $PKG/etc/rc.d/$PRGNAM $PKG/etc/rc.d/rc.$PRGNAM.new
chmod -x $PKG/etc/rc.d/rc.$PRGNAM.new

# Move documentation to right location
mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
cp -a \
  Changelog INSTALLING LEGAL LICENSE README THANKS UPGRADING contrib \
    $PKG/usr/doc/$PRGNAM-$VERSION
mv $PKG/$DOCROOT/$PRGNAM/docs $PKG/usr/doc/$PRGNAM-$VERSION/html
find $PKG/usr/doc/$PRGNAM-$VERSION -type f -exec chmod 644 {} \;
cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild
cat $CWD/README.SLACKWARE > $PKG/usr/doc/$PRGNAM-$VERSION/README.SLACKWARE

# Fixup some ownership and permission issues
chown root:root $PKG/usr/sbin
chown -R root:nagios $PKG/usr/sbin/$PRGNAM
chmod -R 0754 $PKG/usr/sbin/$PRGNAM
chown root:root $PKG/usr/bin
chmod 0755 $PKG/usr/bin
chown root:nagios $PKG/usr/bin/*
chmod 0754 $PKG/usr/bin/*
chown nagios:nagios $PKG/var/run/$PRGNAM
chmod 0775 $PKG/var/run/$PRGNAM

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cat $CWD/doinst.sh > $PKG/install/doinst.sh

cd $PKG
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE