#!/bin/sh
#############cp segatex_alert(Widget) to bin path############
if [ -r /usr/sbin/segatex_alert ]
then
        rm /usr/sbin/segatex_alert
        cp ./src/alert/segatex_alert /usr/sbin
        echo Copied ./src/alert/segatex_alert to /usr/sbin !
else
        cp ./src/alert/segatex_alert /usr/sbin
        echo Copied ./src/alert/segatex_alert to /usr/sbin !
fi
#############cp etc_shadow_check to bin path############
if [ -r /usr/sbin/etc_shadow_check ]
then
        rm /usr/sbin/etc_shadow_check
        cp ./src/alert_check/etc_shadow_check /usr/sbin
        echo Copied ./src/alert_check/etc_shadow_check to /usr/sbin !
else
        cp ./src/alert_check/etc_shadow_check /usr/sbin
        echo Copied ./src/alert_check/etc_shadow_check to /usr/sbin !
fi
#############init script################################
if [ -r /etc/rc.d/init.d/etc_shadow_check_script ]
then
	rm /etc/rc.d/init.d/etc_shadow_check_script
	cp ./etc_shadow_check_script /etc/rc.d/init.d
        echo Copied ./etc_shadow_check_script to /etc/rc.d/init.d !
else
	cp ./etc_shadow_check_script /etc/rc.d/init.d
        echo Copied ./etc_shadow_check_script to /etc/rc.d/init.d !
fi
chmod +x /etc/rc.d/init.d/etc_shadow_check_script
echo chmod +x /etc/rc.d/init.d/etc_shadow_check_script !

##################etc_shadow_check_script auto starter##############################
if [ -r /etc/xdg/autostart/etc_shadow_check_script_auto.desktop ]
then
        rm /etc/xdg/autostart/etc_shadow_check_script_auto.desktop
        cp ./etc_shadow_check_script_auto.desktop /etc/xdg/autostart/etc_shadow_check_script_auto.desktop
        echo Copied ./etc_shadow_check_script_auto.desktop to /etc/xdg/autostart/etc_shadow_check_script_auto.desktop!
else
        cp ./etc_shadow_check_script_auto.desktop /etc/xdg/autostart/etc_shadow_check_script_auto.desktop
        echo Copied ./etc_shadow_check_script_auto.desktop to /etc/xdg/autostart/etc_shadow_check_script_auto.desktop!
fi
##################end etc_shadow_check_script auto starter##############################
##########################################################################################################
#############cp search to /root/segatex path############
if [ -r /root/segatex/search ]
then
        rm /root/segatex/search
        cp ./src/search/search /root/segatex
        echo Copied ./src/search/search to /root/segatex !
else
        cp ./src/search/search /root/segatex
        echo Copied ./src/search/search to /root/segatex !
fi
##########################################################################################################
#############cp segatex_alert_audit(Widget) to /root/segatex path############
if [ -r /usr/sbin/segatex_alert_audit ]
then
        rm /usr/sbin/segatex_alert_audit
        cp ./src/alert_audit/segatex_alert_audit /usr/sbin
        echo Copied ./src/alert_audit/segatex_alert_audit to /usr/sbin !
else
        cp ./src/alert_audit/segatex_alert_audit /usr/sbin
        echo Copied ./src/alert_audit/segatex_alert_audit to /usr/sbin !
fi
#############cp audit_check to /root/segatex path############
if [ -r /root/segatex/audit_check ]
then
        rm /root/segatex/audit_check
        cp ./src/alert_check_audit/audit_check /root/segatex
        echo Copied ./src/alert_check_audit/audit_check to /root/segatex !
else
        cp ./src/alert_check_audit/audit_check /root/segatex
        echo Copied ./src/alert_check_audit/audit_check to /root/segatex !
fi
#############init script################################
#############cp audit_check2 to /root/segatex path############
if [ -r /usr/sbin/audit_check2 ]
then
        rm /usr/sbin/audit_check2
        cp ./src/alert_check_audit2/audit_check2 /usr/sbin
        echo Copied ./src/alert_check_audit2/audit_check2 to /usr/sbin !
else
        cp ./src/alert_check_audit2/audit_check2 /usr/sbin
        echo Copied ./src/alert_check_audit2/audit_check2 to /usr/sbin !
fi
#############init script################################
if [ -r /etc/rc.d/init.d/audit_check_script ]
then
	rm /etc/rc.d/init.d/audit_check_script
	cp ./audit_check_script /etc/rc.d/init.d
        echo Copied ./audit_check_script to /etc/rc.d/init.d !
else
	cp ./audit_check_script /etc/rc.d/init.d
        echo Copied ./audit_check_script to /etc/rc.d/init.d !
fi
chmod +x /etc/rc.d/init.d/audit_check_script
echo chmod +x /etc/rc.d/init.d/audit_check_script !

##################audit_check_script auto starter##############################
if [ -r /etc/xdg/autostart/audit_check_script_auto.desktop ]
then
        rm /etc/xdg/autostart/audit_check_script_auto.desktop
        cp ./audit_check_script_auto.desktop /etc/xdg/autostart/audit_check_script_auto.desktop
        echo Copied ./audit_check_script_auto.desktop to /etc/xdg/autostart/audit_check_script_auto.desktop!
else
        cp ./audit_check_script_auto.desktop /etc/xdg/autostart/audit_check_script_auto.desktop
        echo Copied ./audit_check_script_auto.desktop to /etc/xdg/autostart/audit_check_script_auto.desktop!
fi
##################end audit_check_script auto starter##############################
find /etc/rc.d/rc.local -type f -exec grep "/root/segatex/audit_check &" {} /dev/null \; > checkfile

if [ `wc -c checkfile | awk '{print $1}'` -eq 0 ]
then
	echo "/root/segatex/audit_check &" >> /etc/rc.d/rc.local
	echo audit_check_program will start as a daemon from next boot !
else
	echo audit_check_program already in your system !
fi
##################end audit_check_script auto starter##############################
cp ./auditcheck2.* /root/segatex
echo copied ./auditcheck2.* to /root/segatex ! 

echo Please wait, now removing auditcheck2 ! 
semodule -r auditcheck2

echo Please wait, now installing auditcheck2.pp ! 
semodule -i /root/segatex/auditcheck2.pp

echo Installed auditcheck2.pp ! 

###these did not work well...
#############daemonize###################
#/sbin/chkconfig --add etc_shadow_check_script
#echo etc_shadow_check_script will start as a daemon from next boot !
#/sbin/chkconfig --add audit_check_script
#echo audit_check_script will start as a daemon from next boot !
##############it does not work, so...################
#echo "/etc/rc.d/init.d/etc_shadow_check_script start" >> /etc/rc.d/rc.local
#echo started /etc/rc.d/init.d/etc_shadow_check_script !
#echo etc_shadow_check_script will start as a daemon from next boot !
##############it does not work, so...################
#echo "/etc/rc.d/init.d/audit_check_script start" >> /etc/rc.d/rc.local
#echo started /etc/rc.d/init.d/audit_check_script !
#echo audit_check_script will start as a daemon from next boot !

restorecon -R -v /root/segatex
restorecon -R -v /var/log
