msmtp: clean up msmtpq

- replace relative bin paths with absolute filenames in the nix store
- make the log and queue paths configurable
- log to the journal on linux

+128 -13
+32 -13
pkgs/applications/networking/msmtp/default.nix
··· 1 - { stdenv, fetchurl, openssl, pkgconfig, gnutls, gsasl, libidn, Security }: 1 + { stdenv, lib, fetchurl, autoreconfHook, pkgconfig 2 + , openssl, netcat, gnutls, gsasl, libidn, Security, systemd }: 2 3 3 - stdenv.mkDerivation rec { 4 - version = "1.6.6"; 4 + let 5 + tester = "n"; # {x| |p|P|n|s} 6 + journal = if stdenv.isLinux then "y" else "n"; 7 + 8 + in stdenv.mkDerivation rec { 5 9 name = "msmtp-${version}"; 10 + version = "1.6.6"; 6 11 7 12 src = fetchurl { 8 13 url = "mirror://sourceforge/msmtp/${name}.tar.xz"; 9 14 sha256 = "0ppvww0sb09bnsrpqnvlrn8vx231r24xn2iiwpy020mxc8gxn5fs"; 10 15 }; 11 16 12 - buildInputs = [ openssl pkgconfig gnutls gsasl libidn ] 17 + patches = [ 18 + ./paths.patch 19 + ]; 20 + 21 + buildInputs = [ openssl gnutls gsasl libidn ] 13 22 ++ stdenv.lib.optional stdenv.isDarwin Security; 23 + nativeBuildInputs = [ autoreconfHook pkgconfig ]; 14 24 15 25 configureFlags = 16 26 stdenv.lib.optional stdenv.isDarwin [ "--with-macosx-keyring" ]; 17 27 18 28 postInstall = '' 19 - cp scripts/msmtpq/msmtp-queue scripts/msmtpq/msmtpq $prefix/bin/ 20 - chmod +x $prefix/bin/msmtp-queue $prefix/bin/msmtpq 29 + substitute scripts/msmtpq/msmtpq $out/bin/msmtpq \ 30 + --replace @msmtp@ $out/bin/msmtp \ 31 + --replace @nc@ ${netcat}/bin/nc \ 32 + --replace @journal@ ${journal} \ 33 + ${lib.optionalString (journal == "y") "--replace @systemdcat@ ${systemd}/bin/systemd-cat" } \ 34 + --replace @test@ ${tester} 35 + 36 + substitute scripts/msmtpq/msmtp-queue $out/bin/msmtp-queue \ 37 + --replace @msmtpq@ $out/bin/msmtpq 38 + 39 + chmod +x $out/bin/* 21 40 ''; 22 41 23 - meta = { 24 - description = "Simple and easy to use SMTP client with excellent sendmail compatibility"; 25 - homepage = "http://msmtp.sourceforge.net/"; 26 - license = stdenv.lib.licenses.gpl3; 27 - maintainers = [ stdenv.lib.maintainers.garbas ]; 28 - platforms = stdenv.lib.platforms.unix; 29 - }; 42 + meta = with stdenv.lib; { 43 + description = "Simple and easy to use SMTP client with excellent sendmail compatibility"; 44 + homepage = "http://msmtp.sourceforge.net/"; 45 + license = licenses.gpl3; 46 + maintainers = with maintainers; [ garbas peterhoeg ]; 47 + platforms = platforms.unix; 48 + }; 30 49 }
+96
pkgs/applications/networking/msmtp/paths.patch
··· 1 + diff --git a/scripts/msmtpq/msmtp-queue b/scripts/msmtpq/msmtp-queue 2 + index 1dc220d..d834241 100755 3 + --- a/scripts/msmtpq/msmtp-queue 4 + +++ b/scripts/msmtpq/msmtp-queue 5 + @@ -27,4 +27,4 @@ 6 + ## change the below line to be 7 + ## exec /path/to/msmtpq --q-mgmt 8 + 9 + -exec msmtpq --q-mgmt "$1" 10 + +exec @msmtpq@ --q-mgmt "$1" 11 + diff --git a/scripts/msmtpq/msmtpq b/scripts/msmtpq/msmtpq 12 + index bdb4fb8..1363a67 100755 13 + --- a/scripts/msmtpq/msmtpq 14 + +++ b/scripts/msmtpq/msmtpq 15 + @@ -59,7 +59,7 @@ err() { dsp '' "$@" '' ; exit 1 ; } 16 + ## enter the location of the msmtp executable (no quotes !!) 17 + ## e.g. ( MSMTP=/path/to/msmtp ) 18 + ## and uncomment the test for its existence 19 + -MSMTP=msmtp 20 + +MSMTP=@msmtp@ 21 + #[ -x "$MSMTP" ] || \ 22 + # log -e 1 "msmtpq : can't find the msmtp executable [ $MSMTP ]" # if not found - complain ; quit 23 + ## 24 + @@ -70,9 +70,8 @@ MSMTP=msmtp 25 + ## ( chmod 0700 msmtp.queue ) 26 + ## 27 + ## the queue dir - modify this to reflect where you'd like it to be (no quotes !!) 28 + -Q=~/.msmtp.queue 29 + -[ -d "$Q" ] || \ 30 + - err '' "msmtpq : can't find msmtp queue directory [ $Q ]" '' # if not present - complain ; quit 31 + +Q=${MSMTP_QUEUE:-~/.msmtp.queue} 32 + +test -d "$Q" || mkdir -p "$Q" 33 + ## 34 + ## set the queue log file var to the location of the msmtp queue log file 35 + ## where it is or where you'd like it to be 36 + @@ -84,7 +83,10 @@ Q=~/.msmtp.queue 37 + ## (doing so would be inadvisable under most conditions, however) 38 + ## 39 + ## the queue log file - modify (or comment out) to taste (but no quotes !!) 40 + -LOG=~/log/msmtp.queue.log 41 + +LOG=${MSMTP_LOG:-~/log/msmtp.queue.log} 42 + +test -d "$(dirname $LOG)" || mkdir -p "$(dirname $LOG)" 43 + + 44 + +JOURNAL=@journal@ 45 + ## ====================================================================================== 46 + 47 + ## msmtpq can use the following environment variables : 48 + @@ -108,7 +110,7 @@ LOG=~/log/msmtp.queue.log 49 + ## 50 + #EMAIL_CONN_NOTEST=y # deprecated ; use below var 51 + #EMAIL_CONN_TEST={x| |p|P|n|s} # see settings above for EMAIL_CONN_TEST 52 + -EMAIL_CONN_TEST=n 53 + +EMAIL_CONN_TEST=@test@ 54 + #EMAIL_QUEUE_QUIET=t 55 + ## ====================================================================================== 56 + 57 + @@ -138,6 +140,7 @@ on_exit() { # unlock the queue on exit if the lock was 58 + ## display msg to user, as well 59 + ## 60 + log() { 61 + + local NAME=msmtpq 62 + local ARG RC PFX="$('date' +'%Y %d %b %H:%M:%S')" 63 + # time stamp prefix - "2008 13 Mar 03:59:45 " 64 + if [ "$1" = '-e' ] ; then # there's an error exit code 65 + @@ -154,10 +157,19 @@ log() { 66 + done 67 + fi 68 + 69 + + if [ "$JOURNAL" == "y" ] ; then 70 + + for ARG ; do 71 + + [ -n "$ARG" ] && \ 72 + + echo "$PFX : $ARG" | @systemdcat@ -t $NAME -p info 73 + + done 74 + + fi 75 + + 76 + if [ -n "$RC" ] ; then # an error ; leave w/error return 77 + [ -n "$LKD" ] && lock_queue -u # unlock here (if locked) 78 + [ -n "$LOG" ] && \ 79 + echo " exit code = $RC" >> "$LOG" # logging ok ; send exit code to log 80 + + [ "$JOURNAL" == "y" ] && \ 81 + + echo "exit code= $RC" | @systemdcat@ -t $NAME -p emerg 82 + exit $RC # exit w/return code 83 + fi 84 + } 85 + @@ -207,10 +219,7 @@ connect_test() { 86 + ping -qnc1 -w4 8.8.8.8 >/dev/null 2>&1 || return 1 87 + 88 + elif [ "$EMAIL_CONN_TEST" = 'n' ] ; then # use netcat (nc) test 89 + - # must, of course, have netcat (nc) installed 90 + - which nc >/dev/null 2>&1 || \ 91 + - log -e 1 "msmtpq : can't find netcat executable [ nc ]" # if not found - complain ; quit 92 + - 'nc' -vz www.debian.org 80 >/dev/null 2>&1 || return 1 93 + + @nc@ -vz www.debian.org 80 >/dev/null 2>&1 || return 1 94 + 95 + elif [ "$EMAIL_CONN_TEST" = 's' ] ; then # use sh sockets test 96 + # note that this does not work on debian systems