#!/bin/sh # Make clean? ARGV=$1 # Checking argument if [ "X${ARGV}" = "X" ]; then echo "" echo "No argument. Available options are:" echo " $0 clean" echo " $0 all" echo " $0 test" echo " $0 build" echo " $0 libs" echo " $0 rootcheck" echo "" exit 1; fi # Increasing maximum number of agents if [ "X$1" = "Xsetmaxagents" ]; then echo -n "Specify maximum number of agents: "; read AGMAX echo "HEXTRA=-DMAX_AGENTS=$AGMAX" >> ./Config.OS echo "Maximum number of agents set to $AGMAX." exit 0; fi CJSONV="external/cJSON/" LUAV="external/lua/" LUA_PLAT="posix" # CPU information #CPU=`uname -p` MACH=`uname -m` OS=`uname` VERSION=`cat ./VERSION` MSG="" # Libraries. They need to be compiled before. LIBS="os_xml os_regex os_net os_crypto" # Shares sources SOURCES="shared config" # Binaries BINARIES="os_maild os_dbd os_csyslogd agentlessd os_execd analysisd logcollector remoted client-agent addagent util rootcheck syscheckd monitord os_auth" ROOTCHECKBIN="rootcheck" DIRECTORIES="" # Directories to make # Setting SunOS path if [ "X$OS" = "XSunOS" ]; then PATH=$PATH:/usr/ccs/bin:/usr/xpg4/bin:/opt/csw/gcc3/bin:/opt/csw/bin:/usr/sfw/bin export PATH fi # Cleaning Config.OS if [ "X${ARGV}" = "Xall" -o "X${ARGV}" = "Xtest" -o "X${ARGV}" = "Xrootcheck" -o "X${ARGV}" = "Xlibs" ]; then ls ./Config.OS >/dev/null 2>&1 if [ ! $? = 0 ]; then echo "" > Config.OS fi # Checking for OpenSSLconf.h if [ -e /usr/include/openssl/opensslconf.h ]; then echo "DEXTRA=-DUSE_OPENSSL" >> Config.OS echo "OPENSSLCMD=-lssl -lcrypto" >> Config.OS elif [ -e /usr/include/openssl/conf.h ]; then echo "DEXTRA=-DUSE_OPENSSL" >> Config.OS echo "OPENSSLCMD=-lssl -lcrypto" >> Config.OS fi # Checking for inotify if [ "X$OS" = "XLinux" ]; then if [ -e /usr/include/sys/inotify.h ]; then echo "EEXTRA=-DUSEINOTIFY" >> Config.OS elif [ -e /usr/include/linux/inotify.h ]; then echo "EEXTRA=-DUSEINOTIFY" >> Config.OS fi LUA_PLAT="posix" fi # Checking for libmagic if [ "X$SYSCHECK" = "Xyes" ]; then if [ -e /usr/include/linux/magic.h ]; then echo "MEXTRA=-DUSE_MAGIC" >> Config.OS echo "MAGICCMD=-lmagic" >> Config.OS elif [ -e /usr/include/magic.h ]; then echo "MEXTRA=-DUSE_MAGIC" >> Config.OS echo "MAGICCMD=-lmagic" >> Config.OS fi fi if [ "X$OS" = "XAIX" ]; then echo "EEXTRA=-DAIX -DHIGHFIRST" >> Config.OS PATH=$PATH:/usr/vac/bin export PATH elif [ "X$OS" = "XSunOS" ]; then # Set CPU optimization for Sun UltraSparc # by Eric Straavaldsen # Disabled by default. To enable it, just uncomment the following # lines and comment the EEXTRA below. #PROC=`isainfo -n` #if [ $PROC = sparcv9 ]; then # echo "EEXTRA=-lsocket -lnsl -lresolv -DSOLARIS -DHIGHFIRST -O3 -mcpu=ultrasparc">>Config.OS #fi echo "EEXTRA=-DSOLARIS -DHIGHFIRST">>Config.OS echo "IEXTRA=-lsocket -lnsl -lresolv" >> Config.OS LUA_PLAT="solaris" elif [ "X$OS" = "XHP-UX" ]; then echo "EEXTRA=-DHPUX -D_XOPEN_SOURCE_EXTENDED -DHIGHFIRST -D_REENTRANT" >> Config.OS elif [ "X$OS" = "XDarwin" ]; then echo "EEXTRA=-DDarwin -DHIGHFIRST" >> Config.OS LUA_PLAT="macosx" elif [ "X$OS" = "XFreeBSD" ]; then echo "EEXTRA=-DFreeBSD" >> Config.OS LUA_PLAT="freebsd" else echo 'int main() { short one = 1; char *cp = (char*)&one; if ( *cp == 0 ) return(1); else return(0); }' > isbigendian.c cc -o isbigendian isbigendian.c ./isbigendian if [ $? = 1 ]; then echo "INFO: Big endian set." echo "GEXTRA=-DHIGHFIRST" >> Config.OS else echo "INFO: Little endian set." fi fi if [ "X$OS" = "XFreeBSD" -o "X$OS" = "XDragonFly" ]; then echo "TEXTRA=-pthread" >> Config.OS else echo "TEXTRA=-lpthread" >> Config.OS fi fi # Cleaning if [ "X${ARGV}" = "Xclean" ]; then echo "" > ./Config.OS fi # Getting values for each action if [ "X${ARGV}" = "Xall" ]; then DIRECTORIES="${LIBS} ${SOURCES} ${BINARIES}" DOZLIB="x" DOCJSON="x" DO_LUA="x" elif [ "X${ARGV}" = "Xtest" ]; then DIRECTORIES="${LIBS} ${SOURCES}" DOZLIB="x" DOCJSON="x" DO_LUA="x" elif [ "X${ARGV}" = "Xlibs" ]; then DIRECTORIES="${LIBS} ${SOURCES}" DOZLIB="x" DOCJSON="x" DO_LUA="x" elif [ "X${ARGV}" = "Xrootcheck" ]; then DIRECTORIES="os_xml os_regex os_net ${SOURCES} ${ROOTCHECKBIN}" elif [ "X${ARGV}" = "Xbuild" ]; then DIRECTORIES="${BINARIES}" # Only binaries need to be built else DIRECTORIES="${LIBS} ${SOURCES} ${BINARIES}" fi if [ "X${DOZLIB}" = "Xx" ]; then # Build zlib here echo "" echo " *** Making zlib (by Jean-loup Gailly and Mark Adler) *** " cd external/; make zlib; if [ $? != 0 ]; then echo "" echo "Error Making zlib" exit 1; fi cd ../ echo "" fi if [ "X${DOCJSON}" = "Xx" ]; then # Build cJSON here echo "" echo " *** Making cJSON (by Dave Gamble) *** " cd ${CJSONV}; make ossec; if [ $? != 0 ]; then echo "" echo "Error Making cJSON" exit 1; fi cd ../../ echo "" fi if [ "X${DO_LUA}" = "Xx" ]; then # Build cJSON here echo "" echo " *** Making Lua 5.2 (by team at PUC-Rio in Brazi) *** " echo " Copyright © 1994–2014 Lua.org, PUC-Rio. " cd ${LUAV}; make ${LUA_PLAT}; if [ $? != 0 ]; then echo "" echo "Error Making cJSON" exit 1; fi cd ../../ echo "" fi if [ "X${ARGV}" = "Xclean" ]; then # Cleaning zlib cd external/; make clean; cd ../ cd ${CJSONV}; make clean; cd ../../ cd ${LUAV}; make clean; cd ../../ cd tests/; make clean; cd ../ fi # Make and run tests if intended if [ "X${ARGV}" = "Xtest" ]; then cd tests/ make exit $? fi # Checking if the bin directory is present if [ ! "X${ARGV}" = "Xrootcheck" ]; then ls ../bin >/dev/null 2>&1 if [ $? != 0 ]; then mkdir -p ../bin fi else echo "Compiling Rootcheck..." echo "" fi # Making each directory for i in ${DIRECTORIES}; do cd $i if [ $? != 0 ]; then echo "" echo "Error acessing directory $i" exit 1; fi if [ "X${ARGV}" = "Xclean" ]; then echo "Entering $i" make clean elif [ "X${ARGV}" = "Xbuild" ]; then make build if [ $? != 0 ]; then echo "" echo "Error Making the binaries" exit 1; fi elif [ "X${ARGV}" = "Xrootcheck" ]; then echo "Making $i" if [ $i = "rootcheck" ]; then make binary else make fi if [ $? != 0 ]; then echo "" echo "Error Making $i" exit 1; fi else echo "" echo "" echo " *** Making $i *** " echo "" make if [ $? != 0 ]; then echo "" echo "Error Making $i" exit 1; fi fi cd ../ done if [ "X${ARGV}" = "Xrootcheck" ]; then cp -pr ./rootcheck/ossec-rootcheck ../ cp -pr ./rootcheck/db ../ cp -pr ./rootcheck/rootcheck.conf ../ echo "" echo "Rootcheck compilation completed." echo "Just run './ossec-rootcheck' to execute it." echo "" fi exit 0; # EOF #