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
Branches
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
## [Unreleased]
### Changed
- [core] raise error if mail isn't found in $PATH and reportemail = yes
### Fixed
- [build] make build reproducible regardless of usrmerge (DEBBUG-915222)
......
......@@ -613,6 +613,7 @@ else doit=0
fi
if [ $doit == 1 ]; then
if [ -x "$(which mail 2>/dev/null)" ]; then
debug "send report to $reportemail"
hostname=`hostname`
[ $warnings == 0 ] || subject="WARNING"
......@@ -636,6 +637,10 @@ if [ $doit == 1 ]; then
done
fi
} | mail -s "backupninja: $hostname $subject" $reportemail
else
error "Unable to locate mail executable, email report not sent!"
let "errors += 1"
fi
fi
if [ $actions_run != 0 ]; then
......
load common
teardown_backupninja() {
[ -x /usr/bin/mail.moved ] && mv /usr/bin/mail.moved /usr/bin/mail
}
create_test_action() {
echo '#!/bin/sh' > "${BATS_TMPDIR}/backup.d/test.sh"
echo "$1 $2" >> "${BATS_TMPDIR}/backup.d/test.sh"
......@@ -92,7 +96,7 @@ create_test_action() {
}
@test "reports: report is mailed when reportsuccess = yes" {
create_test_action
create_test_action info test_info
setconfig backupninja.conf reportsuccess yes
run backupninja --now -f "${BATS_TMPDIR}/backupninja.conf" --run "${BATS_TMPDIR}/backup.d/test.sh"
sleep 0.1
......@@ -109,7 +113,7 @@ create_test_action() {
}
@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"
setconfig backupninja.conf reportsuccess yes
setconfig backupninja.conf reportspace yes
......@@ -118,6 +122,15 @@ create_test_action() {
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" {
create_test_action info test_info
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