#!/bin/sh

############check if segatex policy is alive#################
SEGATEX_IS_ALIVE=`semodule -l|grep segatex`

if [ "$SEGATEX_IS_ALIVE" != "" ]; then
	echo "Policy version- ""$SEGATEX_IS_ALIVE"" is alive !!"
	echo "setting segatex policy permissive."
	semanage permissive -a segatex_t
	echo "changing contex of /usr/share/segatex to usr_t."
	chcon -t usr_t /usr/share/segatex -R 
else
		/usr/bin/chcon -t usr_t /usr/share/segatex -R

fi

############delete segatex permissive policy#################
echo "Setting segatex policy alive !"	
#####################edited in segatex-7.765######################
SEGATEX_PERMISSIVE_IS_ALIVE=`semodule -l|grep segatex|grep permissive`
if [ "$SEGATEX_IS_ALIVE" != "" ]; then
	semanage permissive -d segatex_t
fi
#####################end edited in segatex-7.765######################
#####################added in segatex-7.769######################
cd /usr/share/segatex
#####################end added in segatex-7.769######################
############starting segatex policy#################
######################### auditcheck2 needs to be installed ##################
AUDITCHECK2_IS_ALIVE=`semodule -l|grep auditcheck2`
if [ "$AUDITCHECK2_IS_ALIVE" = "" ]; then
        echo "Trying installing auditcheck2 module anew!"
        semodule -i auditcheck2.pp
else
        echo "auditcheck2 module is installed. OK let's move on."
fi
############starting segatex policy#################
echo "Trying installing new segatex.pp!"
if [ "$SEGATEX_IS_ALIVE" != "" ]; then
echo "Removing present segatex module!"
        semodule -r segatex
fi
echo "Installing new segatex!"
        semodule -i segatex.pp
echo "Installed segatex module!"

############restorcon directory and files of segatex#################
restorecon -R -v /usr/share/segatex
echo restoreconed /usr/share/segatex
restorecon -R -v /usr/sbin
echo restoreconed /usr/sbin
restorecon -R -v /usr/bin
echo restoreconed /usr/bin
echo 
############echo messages#################
echo Installation Complete!
echo 
echo Exit and type "segatex" as a non-root user.
echo You can call "segatex" from anywhere.
echo You will find "segatex" in System-Tools.
echo 
