Skip to content
Snippets Groups Projects
Commit 76b457cc authored by Jérôme Charaoui's avatar Jérôme Charaoui
Browse files

raise error if mail isn't found in $PATH and reportemail = yes

parent 6937842e
No related branches found
No related tags found
No related merge requests found
...@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
### Changed
- [core] raise error if mail isn't found in $PATH and reportemail = yes
### Fixed ### Fixed
- [build] make build reproducible regardless of usrmerge (DEBBUG-915222) - [build] make build reproducible regardless of usrmerge (DEBBUG-915222)
......
...@@ -613,6 +613,7 @@ else doit=0 ...@@ -613,6 +613,7 @@ else doit=0
fi fi
if [ $doit == 1 ]; then if [ $doit == 1 ]; then
if [ -x "$(which mail 2>/dev/null)" ]; then
debug "send report to $reportemail" debug "send report to $reportemail"
hostname=`hostname` hostname=`hostname`
[ $warnings == 0 ] || subject="WARNING" [ $warnings == 0 ] || subject="WARNING"
...@@ -636,6 +637,10 @@ if [ $doit == 1 ]; then ...@@ -636,6 +637,10 @@ if [ $doit == 1 ]; then
done done
fi fi
} | mail -s "backupninja: $hostname $subject" $reportemail } | mail -s "backupninja: $hostname $subject" $reportemail
else
error "Unable to locate mail executable, email report not sent!"
let "errors += 1"
fi
fi fi
if [ $actions_run != 0 ]; then if [ $actions_run != 0 ]; then
......
load common load common
teardown_backupninja() {
[ -x /usr/bin/mail.moved ] && mv /usr/bin/mail.moved /usr/bin/mail
}
create_test_action() { create_test_action() {
echo '#!/bin/sh' > "${BATS_TMPDIR}/backup.d/test.sh" echo '#!/bin/sh' > "${BATS_TMPDIR}/backup.d/test.sh"
echo "$1 $2" >> "${BATS_TMPDIR}/backup.d/test.sh" echo "$1 $2" >> "${BATS_TMPDIR}/backup.d/test.sh"
...@@ -92,7 +96,7 @@ create_test_action() { ...@@ -92,7 +96,7 @@ create_test_action() {
} }
@test "reports: report is mailed when reportsuccess = yes" { @test "reports: report is mailed when reportsuccess = yes" {
create_test_action create_test_action info test_info
setconfig backupninja.conf reportsuccess yes setconfig backupninja.conf reportsuccess yes
run backupninja --now -f "${BATS_TMPDIR}/backupninja.conf" --run "${BATS_TMPDIR}/backup.d/test.sh" run backupninja --now -f "${BATS_TMPDIR}/backupninja.conf" --run "${BATS_TMPDIR}/backup.d/test.sh"
sleep 0.1 sleep 0.1
...@@ -109,7 +113,7 @@ create_test_action() { ...@@ -109,7 +113,7 @@ create_test_action() {
} }
@test "reports: success report contains disk space info" { @test "reports: success report contains disk space info" {
create_test_action create_test_action info test_info
echo "directory = /" >> "${BATS_TMPDIR}/backup.d/test.sh" echo "directory = /" >> "${BATS_TMPDIR}/backup.d/test.sh"
setconfig backupninja.conf reportsuccess yes setconfig backupninja.conf reportsuccess yes
setconfig backupninja.conf reportspace yes setconfig backupninja.conf reportspace yes
...@@ -118,6 +122,15 @@ create_test_action() { ...@@ -118,6 +122,15 @@ create_test_action() {
grep -q "/dev/sda1" /var/mail/vagrant grep -q "/dev/sda1" /var/mail/vagrant
} }
@test "reports: emits error if mail executable is not found" {
create_test_action info test_info
setconfig backupninja.conf reportsuccess yes
mv /usr/bin/mail /usr/bin/mail.moved
run backupninja --now -f "${BATS_TMPDIR}/backupninja.conf" --run "${BATS_TMPDIR}/backup.d/test.sh"
[ "$status" -eq 1 ]
false
}
@test "scheduling: runs when = 'everyday at 01' and time matches" { @test "scheduling: runs when = 'everyday at 01' and time matches" {
create_test_action info test_info create_test_action info test_info
setconfig backupninja.conf when 'everyday at 01' setconfig backupninja.conf when 'everyday at 01'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment