#!/bin/sh

# Determine OS platform - For now, should return either redhat or Ubuntu
UNAME=$(uname | tr "[:upper:]" "[:lower:]")
# If Linux, try to determine specific distribution
if [ "$UNAME" = "linux" ]; then
    # If available, use LSB to identify distribution
    if [ -f /etc/lsb-release -o -d /etc/lsb-release.d ]; then
        export DISTRO=$(lsb_release -i | cut -d: -f2 | sed s/'^\t'//)
    # Otherwise, use release info file
    else
        export DISTRO=$(ls -d /etc/[A-Za-z]*[_-][rv]e[lr]* | grep -v "lsb" | cut -d'/' -f3 | cut -d'-' -f1 | cut -d'_' -f1)
    fi
fi
# For everything else (or if above failed), just use generic identifier
[ "$DISTRO" = "" ] && export DISTRO=$UNAME
unset UNAME


CSERVER=
PW_ENFORCE=true
ENTERPRISE_CLIENT=standard
INSTALLDIR=/opt
QUERY=
VALUE=

ASK_PATH() {

PASS=NO

while [ "$PASS" = "NO" ]; do 

echo
echo "$QUERY [$VALUE]"

result=""
read result

if [ "$result" != "" ]; then
	VALUE=$result
fi	

if [ "${VALUE}" = "" ]; then
	echo
	echo "Please enter a value."
else
	PASS="YES"
fi

done

}

#____________________________  MAIN  ___________________________


QUERY='Enter hostname of the central server:'
VALUE=$CSERVER
ASK_PATH;
CSERVER=$VALUE

QUERY='Packet filter kernel module enabled?'
VALUE=$PW_ENFORCE
ASK_PATH;
PW_ENFORCE=$VALUE

QUERY='Specify agent run mode [standard/enterprise]:'
VALUE=$ENTERPRISE_CLIENT
ASK_PATH;
ENTERPRISE_CLIENT=$VALUE

echo
echo
echo "Summary of environment before Sigma Agent installation."
echo "CSERVER is $CSERVER"
echo "PW_ENFORCE is $PW_ENFORCE"
echo "ENTERPRISE_CLIENT is $ENTERPRISE_CLIENT"
echo
echo "Install location is $INSTALLDIR"
echo

export CSERVER PW_ENFORCE

if [ "$DISTRO" = "Ubuntu" ]; then
        dpkg -i ./sigmaagent_1.6.13~ubuntu2204_amd64.deb
else
        rpm -i ./SigmaAgent-ubuntu2204_1.6.13.x86_64.rpm
fi


[ ! "$?" = "0" ] && exit $?

if [ ${ENTERPRISE_CLIENT} != "standard" -a ${ENTERPRISE_CLIENT} != "Standard" -a ${ENTERPRISE_CLIENT} != "STANDARD" ]; then
	touch ${INSTALLDIR}/sigma/agent/conf/golden
fi

