Only copy stig tests script if it changes

This commit is contained in:
Bob Mottram 2017-08-05 20:41:21 +01:00
parent 9cf9388131
commit f703a95971
1 changed files with 24 additions and 12 deletions

View File

@ -78,18 +78,30 @@ function randomize_cron {
}
function schedule_stig_tests {
echo '#!/bin/bash' > /etc/cron.daily/stig_tests
echo "ADMIN_EMAIL_ADDRESS=${MY_USERNAME}@\${HOSTNAME}" >> /etc/cron.daily/stig_tests
echo "pkill ${PROJECT_NAME}-tests" >> /etc/cron.daily/stig_tests
echo 'rm -rf /tmp/*' >> /etc/cron.daily/stig_tests
echo "${PROJECT_NAME}-tests --stig yes > /tmp/daily-stig-tests" >> /etc/cron.daily/stig_tests
echo 'if [ ! "$?" = "0" ]; then' >> /etc/cron.daily/stig_tests
echo " echo \"\$(cat /tmp/daily-stig-tests)\" | mail -s \"${PROJECT_NAME} STIG test failures\" \$ADMIN_EMAIL_ADDRESS" >> /etc/cron.daily/stig_tests
echo 'fi' >> /etc/cron.daily/stig_tests
echo 'if [ -f /tmp/daily-stig-tests ]; then' >> /etc/cron.daily/stig_tests
echo ' rm /tmp/daily-stig-tests' >> /etc/cron.daily/stig_tests
echo 'fi' >> /etc/cron.daily/stig_tests
chmod +x /etc/cron.daily/stig_tests
stig_tests_script=/tmp/stig_tests_script
echo '#!/bin/bash' > $stig_tests_script
echo "ADMIN_EMAIL_ADDRESS=${MY_USERNAME}@\${HOSTNAME}" >> $stig_tests_script
echo "pkill ${PROJECT_NAME}-tests" >> $stig_tests_script
echo 'rm -rf /tmp/*' >> $stig_tests_script
echo "${PROJECT_NAME}-tests --stig yes > /tmp/daily-stig-tests" >> $stig_tests_script
echo 'if [ ! "$?" = "0" ]; then' >> $stig_tests_script
echo " echo \"\$(cat /tmp/daily-stig-tests)\" | mail -s \"${PROJECT_NAME} STIG test failures\" \$ADMIN_EMAIL_ADDRESS" >> $stig_tests_script
echo 'fi' >> $stig_tests_script
echo 'if [ -f /tmp/daily-stig-tests ]; then' >> $stig_tests_script
echo ' rm /tmp/daily-stig-tests' >> $stig_tests_script
echo 'fi' >> $stig_tests_script
chmod +x $stig_tests_script
if [ ! -f /etc/cron.daily/stig_tests ]; then
cp $stig_tests_script /etc/cron.daily/stig_tests
else
HASH1=$(sha256sum $stig_tests_script | awk -F ' ' '{print $1}')
HASH2=$(sha256sum /etc/cron.daily/stig_tests | awk -F ' ' '{print $1}')
if [[ "$HASH1" != "$HASH2" ]]; then
cp $stig_tests_script /etc/cron.daily/stig_tests
fi
fi
rm $stig_tests_script
}
# NOTE: deliberately there is no "exit 0"