summaryrefslogtreecommitdiff
path: root/dist/net-snmp-solaris-build/buildpackage-solaris
blob: 31f4f0c0ee99fe4dbd01c3a683250d4125e315fd (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
#!/bin/ksh
#
# automatic build (configure/make/package) script 
# for NET-SNMP on Solaris
#
# 2004/11 Rewrite to strictly build the package jfrank@fastrieve.com
# 2002/11 Stefan.Radman@CTBTO.ORG


# If you define DEBUG, the script will be verbose, and we won't remove temporary files

#DEBUG=Y
if [ ! -z $DEBUG ]; then
   set -x # be verbose
fi

# TMP is where we are temporarily installing the package to
TMP=`pwd`/pkgroot

# PKG is the internal and external name for the package
PKG=OSSnet-snmp

#PREFIX is the top level architecture dependent directory.
# This should be normally determined by configure
#prefix=/opt/${PKG}
prefix=/usr/local

# VARDIR is the persistent dir from configure
VARDIR=/var/net-snmp

expandedprefix=${TMP}/${prefix}

PERL=${PERL:=`which perl`}
MAKE=${MAKE:=`which make`}

if [ -d ${TMP} ]; then
   rm -rf ${TMP};
fi

# install to temporary package build root
cd ../..

$MAKE install prefix=${expandedprefix} exec_prefix=${expandedprefix} || exit 1

# We now have the main software installed, copy over the auxillary files
cd -

awk /^___snmpd-init.d/,/___EOF/ $0 | grep -v ^___ | sed "s,@prefix@,$prefix,g" >|snmpd-init.d

# create persistent directory if it does not exist
[ -d $TMP/$VARDIR ] || install -d -m 0755 $TMP/$VARDIR 

# postinstall
LD_LIBRARY_PATH=$TMP$prefix/lib:$LD_LIBRARY_PATH $TMP/$prefix/bin/snmptranslate\
  -M$TMP/$prefix/share/snmp/mibs -m SNMPv2-SMI .1 >&- || exit $? # create MIB index

# package
version=`../../net-snmp-config --version`
os=`uname -s`
rel=`uname -r`
class=snmp
owner=$LOGNAME
groups | awk '{print $1}' | read group
cat <<== >|pkginfo
PKG="${PKG}"
NAME="net-snmp-$version"
ARCH="`uname -p`"
VERSION="$version, $os $rel, `date +%Y.%m.%d.%H.%M.%S`"
CATEGORY="OpenSource"
DESC="The NET-SNMP Tools and Library"
VENDOR="http://net-snmp.sourceforge.net"
CLASSES="$class"
BASEDIR="$prefix"
==
. ./pkginfo

echo 'checking dependencies'
unset LD_LIBRARY_PATH # binaries and libraries should have RPATH now
./elfdepend.sh $TMP | grep -v "P  *$PKG " >|depend # ignore own package

echo 'creating prototype file'
cat <<== >|prototype
i pkginfo
i copyright=../../COPYING
#i preinstall=./preinstall-postremove
#i postinstall=./preinstall-postremove
i depend
# set default mode, owner and group
! default 0775 root sys
d snmp /etc 0755 root sys
d snmp /etc/init.d 0755 root sys
f snmp /etc/init.d/snmpd=./snmpd-init.d 0755 root sys
#l snmp /etc/rc2.d/S76snmpd=/etc/init.d/snmpd # not yet
==

pkgproto -c snmp $TMP=/ |\
egrep -v '^d .* / |^d .* /var |^d .* /opt |^ .*perllocal.pod=' |\
sed -e "s/ $owner $group\$//" >> prototype || exit $?
# and ignore top level directories (must pre-exist)

echo 'creating package'
pkgmk -od . || exit $?
pkgtrans . $PKG-$version-$ARCH-$os$rel.pkg $PKG || exit $?

# We should really do some cleanup here
if [ -z $DEBUG ]; then
   rm -rf snmpd-init.d $PKG $TMP pkginfo prototype depend 
fi

echo "build was successfull"
exit 0

# /etc/init/snmpd
# This is packaged inside of buildpackage-solaris because we need to substitute
# in the actual server name.

___snmpd-init.d___
#! /bin/sh
#
# start/stop the NET-SNMP master agent (snmpd)
#
# Location:      /etc/init.d/snmpd
#                /etc/rc3.d/S??snmpd
#
name="NET-SNMP agent"
daemon=@prefix@/sbin/snmpd

case "$1" in
start)
        [ ! -x $daemon ] && echo "ERROR: cannot start $name ($daemon)" && exit 1
        echo "Starting $name ... \c"
        PGREP=`which pgrep`
        if [ -z $PGREP ]; then
           pid=`pgrep -fx $daemon`
        else
           pid=`ps -ef | grep $daemon | grep -v grep | awk '{print $2}'`
        fi

        [ ! -z "$pid" ] && echo "already running with pid $pid." && exit 0
        $daemon && echo "done."
        ;;
stop)
        echo "Stopping $name ... \c"
        PGREP=`which pgrep`
        if [ -z $PGREP ]; then
           pid=`pgrep -fx $daemon`
        else
           pid=`ps -ef | grep $daemon | grep -v grep | awk '{print $2}'`
        fi
        [ ! -z "$pid" ] && (kill $pid && echo "done" ) || echo "not running"

        ;;
status)
        echo "$name is \c"
        PGREP=`which pgrep`
        if [ -z $PGREP ]; then
           pid=`pgrep -fx $daemon`
        else
           pid=`ps -ef | grep $daemon | grep -v grep | awk '{print $2}'`
        fi
        [ -z "$pid" ] && echo "not running" || echo "running with pid $pid"
        ;;
restart)
        $0 stop && $0 start
        ;;
reload)
        echo "Re-initializing $name ...\c"
        PGREP=`which pgrep`
        if [ -z $PGREP ]; then
           pid=`pgrep -fx $daemon`
        else
           pid=`ps -ef | grep $daemon | grep -v grep | awk '{print $2}'`
        fi
        [ ! -z "$pid" ] && (kill -HUP $pid && echo "done" ) || echo "not running"
        ;;
*)
        echo "Usage: $0 { start | stop | status | restart | reload }"
        ;;
esac

exit 0
___EOF___