| 1 | #!/bin/ksh |
| 2 | # |
| 3 | # automatic build (configure/make/package) script |
| 4 | # for NET-SNMP on Solaris |
| 5 | # |
| 6 | # 2004/11 Rewrite to strictly build the package [email protected] |
| 7 | # 2002/11 [email protected] |
| 8 | |
| 9 | |
| 10 | # If you define DEBUG, the script will be verbose, and we won't remove temporary files |
| 11 | |
| 12 | #DEBUG=Y |
| 13 | if [ ! -z $DEBUG ]; then |
| 14 | set -x # be verbose |
| 15 | fi |
| 16 | |
| 17 | # TMP is where we are temporarily installing the package to |
| 18 | TMP=`pwd`/pkgroot |
| 19 | |
| 20 | # PKG is the internal and external name for the package |
| 21 | PKG=OSSnet-snmp |
| 22 | |
| 23 | #PREFIX is the top level architecture dependent directory. |
| 24 | # This should be normally determined by configure |
| 25 | #prefix=/opt/${PKG} |
| 26 | prefix=/usr/local |
| 27 | |
| 28 | # VARDIR is the persistent dir from configure |
| 29 | VARDIR=/var/net-snmp |
| 30 | |
| 31 | expandedprefix=${TMP}/${prefix} |
| 32 | |
| 33 | PERL=${PERL:=`which perl`} |
| 34 | MAKE=${MAKE:=`which make`} |
| 35 | |
| 36 | if [ -d ${TMP} ]; then |
| 37 | rm -rf ${TMP}; |
| 38 | fi |
| 39 | |
| 40 | # install to temporary package build root |
| 41 | cd ../.. |
| 42 | |
| 43 | $MAKE install prefix=${expandedprefix} exec_prefix=${expandedprefix} || exit 1 |
| 44 | |
| 45 | # We now have the main software installed, copy over the auxillary files |
| 46 | cd - |
| 47 | |
| 48 | awk /^___snmpd-init.d/,/___EOF/ $0 | grep -v ^___ | sed "s,@prefix@,$prefix,g" >|snmpd-init.d |
| 49 | |
| 50 | # create persistent directory if it does not exist |
| 51 | [ -d $TMP/$VARDIR ] || install -d -m 0755 $TMP/$VARDIR |
| 52 | |
| 53 | # postinstall |
| 54 | LD_LIBRARY_PATH=$TMP$prefix/lib:$LD_LIBRARY_PATH $TMP/$prefix/bin/snmptranslate\ |
| 55 | -M$TMP/$prefix/share/snmp/mibs -m SNMPv2-SMI .1 >&- || exit $? # create MIB index |
| 56 | |
| 57 | # package |
| 58 | version=`../../net-snmp-config --version` |
| 59 | os=`uname -s` |
| 60 | rel=`uname -r` |
| 61 | class=snmp |
| 62 | owner=$LOGNAME |
| 63 | groups | awk '{print $1}' | read group |
| 64 | cat <<== >|pkginfo |
| 65 | PKG="${PKG}" |
| 66 | NAME="net-snmp-$version" |
| 67 | ARCH="`uname -p`" |
| 68 | VERSION="$version, $os $rel, `date +%Y.%m.%d.%H.%M.%S`" |
| 69 | CATEGORY="OpenSource" |
| 70 | DESC="The NET-SNMP Tools and Library" |
| 71 | VENDOR="http://net-snmp.sourceforge.net" |
| 72 | CLASSES="$class" |
| 73 | BASEDIR="$prefix" |
| 74 | == |
| 75 | . ./pkginfo |
| 76 | |
| 77 | echo 'checking dependencies' |
| 78 | unset LD_LIBRARY_PATH # binaries and libraries should have RPATH now |
| 79 | ./elfdepend.sh $TMP | grep -v "P *$PKG " >|depend # ignore own package |
| 80 | |
| 81 | echo 'creating prototype file' |
| 82 | cat <<== >|prototype |
| 83 | i pkginfo |
| 84 | i copyright=../../COPYING |
| 85 | #i preinstall=./preinstall-postremove |
| 86 | #i postinstall=./preinstall-postremove |
| 87 | i depend |
| 88 | # set default mode, owner and group |
| 89 | ! default 0775 root sys |
| 90 | d snmp /etc 0755 root sys |
| 91 | d snmp /etc/init.d 0755 root sys |
| 92 | f snmp /etc/init.d/snmpd=./snmpd-init.d 0755 root sys |
| 93 | #l snmp /etc/rc2.d/S76snmpd=/etc/init.d/snmpd # not yet |
| 94 | == |
| 95 | |
| 96 | pkgproto -c snmp $TMP=/ |\ |
| 97 | egrep -v '^d .* / |^d .* /var |^d .* /opt |^ .*perllocal.pod=' |\ |
| 98 | sed -e "s/ $owner $group\$//" >> prototype || exit $? |
| 99 | # and ignore top level directories (must pre-exist) |
| 100 | |
| 101 | echo 'creating package' |
| 102 | pkgmk -od . || exit $? |
| 103 | pkgtrans . $PKG-$version-$ARCH-$os$rel.pkg $PKG || exit $? |
| 104 | |
| 105 | # We should really do some cleanup here |
| 106 | if [ -z $DEBUG ]; then |
| 107 | rm -rf snmpd-init.d $PKG $TMP pkginfo prototype depend |
| 108 | fi |
| 109 | |
| 110 | echo "build was successfull" |
| 111 | exit 0 |
| 112 | |
| 113 | # /etc/init/snmpd |
| 114 | # This is packaged inside of buildpackage-solaris because we need to substitute |
| 115 | # in the actual server name. |
| 116 | |
| 117 | ___snmpd-init.d___ |
| 118 | #! /bin/sh |
| 119 | # |
| 120 | # start/stop the NET-SNMP master agent (snmpd) |
| 121 | # |
| 122 | # Location: /etc/init.d/snmpd |
| 123 | # /etc/rc3.d/S??snmpd |
| 124 | # |
| 125 | name="NET-SNMP agent" |
| 126 | daemon=@prefix@/sbin/snmpd |
| 127 | |
| 128 | case "$1" in |
| 129 | start) |
| 130 | [ ! -x $daemon ] && echo "ERROR: cannot start $name ($daemon)" && exit 1 |
| 131 | echo "Starting $name ... \c" |
| 132 | PGREP=`which pgrep` |
| 133 | if [ -z $PGREP ]; then |
| 134 | pid=`pgrep -fx $daemon` |
| 135 | else |
| 136 | pid=`ps -ef | grep $daemon | grep -v grep | awk '{print $2}'` |
| 137 | fi |
| 138 | |
| 139 | [ ! -z "$pid" ] && echo "already running with pid $pid." && exit 0 |
| 140 | $daemon && echo "done." |
| 141 | ;; |
| 142 | stop) |
| 143 | echo "Stopping $name ... \c" |
| 144 | PGREP=`which pgrep` |
| 145 | if [ -z $PGREP ]; then |
| 146 | pid=`pgrep -fx $daemon` |
| 147 | else |
| 148 | pid=`ps -ef | grep $daemon | grep -v grep | awk '{print $2}'` |
| 149 | fi |
| 150 | [ ! -z "$pid" ] && (kill $pid && echo "done" ) || echo "not running" |
| 151 | |
| 152 | ;; |
| 153 | status) |
| 154 | echo "$name is \c" |
| 155 | PGREP=`which pgrep` |
| 156 | if [ -z $PGREP ]; then |
| 157 | pid=`pgrep -fx $daemon` |
| 158 | else |
| 159 | pid=`ps -ef | grep $daemon | grep -v grep | awk '{print $2}'` |
| 160 | fi |
| 161 | [ -z "$pid" ] && echo "not running" || echo "running with pid $pid" |
| 162 | ;; |
| 163 | restart) |
| 164 | $0 stop && $0 start |
| 165 | ;; |
| 166 | reload) |
| 167 | echo "Re-initializing $name ...\c" |
| 168 | PGREP=`which pgrep` |
| 169 | if [ -z $PGREP ]; then |
| 170 | pid=`pgrep -fx $daemon` |
| 171 | else |
| 172 | pid=`ps -ef | grep $daemon | grep -v grep | awk '{print $2}'` |
| 173 | fi |
| 174 | [ ! -z "$pid" ] && (kill -HUP $pid && echo "done" ) || echo "not running" |
| 175 | ;; |
| 176 | *) |
| 177 | echo "Usage: $0 { start | stop | status | restart | reload }" |
| 178 | ;; |
| 179 | esac |
| 180 | |
| 181 | exit 0 |
| 182 | ___EOF___ |