forked from DanHam/packer-virt-sysprep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sysprep-op-mail-spool.sh
50 lines (43 loc) · 1.05 KB
/
sysprep-op-mail-spool.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env bash
#
# Remove mail from the local mail spool
set -o errexit
mta_list=(
"exim"
"postfix"
"sendmail"
)
mail_spool_locations=(
"/var/spool/mail/*"
"/var/mail/*"
)
# Best effort attempt to stop any MTA service
for mta in ${mta_list[@]}
do
# Systemd
if command -v systemctl &>/dev/null ; then
mta_service="$(systemctl list-units --type service | grep ${mta} | \
cut -d' ' -f1)"
if [ "x${mta_service}" != "x" ]; then
if systemctl is-active ${mta_service} &>/dev/null; then
systemctl stop ${mta_service}
fi
fi
# Sys-v-init
else
mta_service="$(find /etc/init.d/ -iname "*${mta}*")"
if [ "x${mta_service}" != "x" ]; then
if ${mta_service} status | grep running &>/dev/null; then
${mta_service} stop
fi
fi
fi
done
# Include hidden files in globs
shopt -s nullglob dotglob
# Remove any mail
for mail_spool in ${mail_spool_locations[@]}
do
rm -rf ${mail_spool}
done
exit 0