#!/bin/sh
# test we are root
if [ "$(id -u)" != "0" ]; then
   echo "run as root now exitting"
   exit 1
fi

# build dep of sane

export CFLAGS="-march=armv8-a+crc -mtune=cortex-a72 -Os -pipe" 
export CXXFLAGS="-march=armv8-a+crc -mtune=cortex-a72 -Os -pipe \
-fno-exceptions -fno-rtti"

P=net-snmp
V=5.9
SRC=$P-$V 
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc squashfs-tools zsync wget libtool-dev openssl-dev pcre-dev libnl-dev "   
    for Z in $LIST
    do 
    su -c "tce-load -i $Z" $USER
done

LOOP=/tmp/tcloop/libtool/usr/local/share/libtool/build-aux

cd /tmp
su -c "/usr/local/bin/wget -nc --no-check-certificate \
https://sourceforge.net/projects/$P/files/$P/$V/$SRC.tar.gz   "  $USER
mkdir $P
tar xvf $SRC*gz
cd $SRC
cp $LOOP/config.sub .
cp $LOOP/config.guess .

# disabling snmp v2c causes make error for sane magicolor.c 

./configure --prefix=/usr/local --with-default-snmp-version=3 --enable-ipv6 \
--with-sys-contact="root@localhost" --with-sys-location="Unknown" \
--with-logfile="/var/log/snmpd.log" --with-persistent-directory="/var/net-snmp" \
--without-rpm --disable-manuals --disable-snmpv1 --disable-debugging 

# ERROR FOR (tce-load -i perl5) (configure) --with-perl-modules 
# checking for Perl cc... configure: error: Could not determine the compiler that was used 
# to build /usr/local/bin/perl. Either set the environment variable PERLPROG to a 
# different perl binary or use --without-perl-modules to build without Perl

# configure takes 3M
# configure-summary file contents
# SNMP Versions Supported:    2c 3
# Building for:               linux
# Net-SNMP Version:           5.9
# Network transport support:  Callback Unix Alias TCP UDP TCPIPv6 UDPIPv6 IPv4Base SocketBase TCPBase UDPIPv4Base UDPBase IPBase IPv6Base
# SNMPv3 Security Modules:     usm
# Agent MIB code:            default_modules =>  snmpv3mibs mibII ucd_snmp notification notification-log-mib target agent_mibs \
#                                                agentx disman/event disman/schedule utilities host
# MYSQL Trap Logging:         unavailable
# Embedded Perl support:      disabled
# SNMP Perl modules:          disabled
# SNMP Python modules:        disabled
# Crypto support from:        crypto
# Authentication support:     MD5 SHA1 SHA224 SHA256 SHA384 SHA512
#  Encryption support:         DES AES AES128 AES192 AES192C AES256 AES256C
#  Local DNSSEC validation:    disabled
make NETSNMP_DONT_CHECK_VERSION=1 # takes 6M 40s # install-strip fails
make install DESTDIR=/tmp/$P      # takes 40 secs
cd /tmp

# dev
#####
mkdir -p $P-dev/usr/local/lib/
mv $P/usr/local/include $P-dev/usr/local/
mv $P/usr/local/lib/pkgconfig $P-dev/usr/local/lib/
mv $P/usr/local/lib/*a $P-dev/usr/local/lib/
chmod 644 $P-dev/usr/local/lib/*a 

# main
#######
mkdir -p $P/usr/local/share/doc/$P
cp $SRC/COPYING $P/usr/local/share/doc/$P

mkdir -p /var/$P

strip --strip-unneeded $P/usr/local/bin/*
strip --strip-unneeded $P/usr/local/sbin/*
strip --strip-unneeded $P/usr/local/lib/*so

# TCZ them
###########
LIST="$P $P-dev"
for Z in $LIST
do
	mksquashfs $Z $Z.tcz
	md5sum $Z.tcz > $Z.tcz.md5.txt
	cd $Z
	find usr -not -type d > /tmp/$Z.tcz.list
        sed 's|usr|/usr|g' -i /tmp/$Z.tcz.list
	cd /tmp
        zsyncmake $Z.tcz
done

ls -hal

echo 'Title:          net-snmp-dev.tcz  
Description:    dev files
Version:        5.9
Author:         https://github.com/net-snmp/net-snmp 
                at bottom of page contributors
Original-site:  http://net-snmp-project.org/
Copying-policy: accompanied
Size:           1.1M		
Extension_by:   aus9
Tags:           network scan 
Comments:       Dev files
 
Change-log:     2020/11/08 original v 5.9 on 12x 
Current:        2020/11/08  '> $P-dev.tcz.info

echo 'Title:          net-snmp.tcz  
Description:    Simple Network Management Protocol
Version:        5.9
Author:         https://github.com/net-snmp/net-snmp
                at bottom of page contributors
Original-site:  http://net-snmp-project.org/
Copying-policy: accompanied
Size:           1.3M		
Extension_by:   aus9
Tags:           network scan
Comments:       protocol for monitoring the health and 
                welfare of network equipment. Net-SNMP is 
                a suite of applications used to implement 
                this protocol

                No support built for perl or python modules
                supports v 2c and 3
 
Change-log:     2020/11/08 original v 5.9 on 12x 
Current:        2020/11/08  '> $P.tcz.info

# python3.8-dev.tcz  python3.8-setuptools.tcz glib2-python.tcz libxml2-python.tcz glib2-dev.tcz

echo 'net-snmp.tcz
libtool-dev.tcz 
openssl-dev.tcz 
pcre-dev.tcz 
libnl-dev.tcz  ' > $P-dev.tcz.dep
echo 'openssl.tcz
libnl.tcz' > $P.tcz.dep

