#!/bin/sh
# Author Felix Wolfsteller, heavily based on work by
# (C) Vlatko Kosturjak. GPL v2
# OVNOCORE=yes $0
# OVOPT=yes $0
# SUDOCMD=sudo $0

OPENVASPREFIX=`date +%F`
OPENVASPATH="/opt/openvas-svn-$OPENVASPREFIX"

echo "o Installing OpenVAS to $OPENVASPATH"

# E.g. OpenVAS-Client configure needs to figure out the openvas-library version,
# therefore set path and ld_library_path
export LD_LIBRARY_PATH=$OPENVASPATH/lib:$LD_LIBRARY_PATH
export PATH=$OPENVASPATH/bin:$OPENVASPATH/sbin:$PATH

if [ -z "$OVNOCORE" ]; then
	for i in openvas-libraries openvas-scanner openvas-client
	do
		echo "o Installing OpenVAS module: $i"
		cd $i && ./configure --prefix=$OPENVASPATH && make && $SUDOCMD make install && cd ..
	done
else
	echo "o Skipping OpenVAS core modules"
fi

if [ -z "$OVOPT" ]; then
	echo "o Skipping OpenVAS optional modules: openvas-manager and gsa"
	echo "o If you want optional modules, set following enviroment var OVOPT=\"yes\""
else
	for i in openvas-manager gsa
	do
		echo "o Installing OpenVAS module: $i"
		cd $i && cmake -DCMAKE_INSTALL_PREFIX=$OPENVASPATH . && make && $SUDOCMD make install && cd ..
	done
fi
echo "o Finished installation of OpenVAS to $OPENVASPATH"

