Commit 37e43eb9 authored by Seblu's avatar Seblu
Browse files

Allow customizable and multiple mail destination

As a consequency, this patch also add a config file for mailboot.
parent 86ed4219
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ bin_SCRIPTS = mailboot
noinst_SCRIPTS = PKGBUILD
dist_doc_DATA = README.rst COPYRIGHT LICENSE AUTHORS
systemdunit_DATA = mailboot.service
dist_sysconf_DATA = mailboot.conf

mailboot: mailboot.in
	$(do_substitution) < $(srcdir)/$< > $@
@@ -34,6 +35,7 @@ PKGBUILD: PKGBUILD.in

do_substitution = $(SED) \
	-e 's,[@]bindir[@],$(bindir),g' \
	-e 's,[@]sysconfdir[@],$(sysconfdir),g' \
	-e 's,[@]VERSION[@],$(VERSION),g'

check: mailboot
+2 −1
Original line number Diff line number Diff line
@@ -8,12 +8,13 @@ arch=('any')
url='https://github.com/seblu/mailboot'
license=('GPL')
depends=('bash' 'systemd' 'sed')
backup=('etc/mailboot.conf')
source=("$pkgname-$pkgver.tar.xz")
md5sums=('SKIP')

build() {
  cd $pkgname-$pkgver
  ./configure --prefix=/usr
  ./configure --prefix=/usr --sysconfdir=/etc
  make
}

mailboot.conf

0 → 100644
+7 −0
Original line number Diff line number Diff line
## config file for mailboot

## Specify mail destinations. Directly given to sendmail.
## Can be a local user or a mail@localhost.com
## It's a bash array. You can specify more than one email address
## default is: targets=('root')
#targets=('root' 'root@localhost.42')
+13 −5
Original line number Diff line number Diff line
@@ -17,11 +17,17 @@

VERSION=@VERSION@

# default settings
targets=('root')

# source config file if exists
[[ -r @sysconfdir@/mailboot.conf ]] && source @sysconfdir@/mailboot.conf

usage() {
    echo "usage: ${0##*/} [options]" >&2
    echo 'options:' >&2
    echo "   -s: send the mail" >&2
    echo "   -p: print the mail to stdout" >&2
    echo "   -s: send mail" >&2
    echo "   -p: print mail to stdout" >&2
    echo "   -h: this help" >&2
    echo "   -v: print mailboot version" >&2
    exit ${1:-1}
@@ -34,7 +40,10 @@ print_version() {
print_mail() {
    source /etc/os-release

    echo "To: \"$(getent passwd root|cut -f5 -d:)\" <root>"
    printf 'To: '
    for target in "${targets[@]}";do
        printf "\"$target\" "
    done | sed -e 's/ $/\n/' -e 's/ /, /g'
    echo "Subject: [MAILBOOT] $(hostname -f)"
    echo
    echo "Operating system is $NAME"
@@ -49,9 +58,8 @@ print_mail() {
    last -5 -FRwx|head -n 5
}


send_mail() {
    print_mail | sed 's/$/\r/' | sendmail root
    print_mail | sed 's/$/\r/' | sendmail "${targets[@]}"
}

while getopts 'psvh' opt; do