Skip to content
Snippets Groups Projects
Commit f703a959 authored by Bob Mottram's avatar Bob Mottram
Browse files

Only copy stig tests script if it changes

parent 9cf93881
No related branches found
No related tags found
No related merge requests found
......@@ -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"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment