#!/bin/bash
set -e
+usage () { cat <<END
+
+usage: ./notify senderfile recipientsfile 'message'
+
+recipientsfile: see test-recipients for an example
+see comments in via-* scripts for individual line formats
+
+senderinfo: file containing
+ email YOUREMAILADDRESS@EXAMPLE.COM
+ name YOUR NAME
+
+END
+}
case "$#.$1" in
-2.[^-]*) ;;
-*) echo >&2 "usage: ./notify recipientsfile 'message'"; exit 1;;
+3.[^-]*) ;;
+*) usage >&2; exit 1 ;;
esac
-rcpts="$1"
-msg="$2"
-
-exec <"$rcpts"
-line=0
-while read method data; do
- line=$(( $line+1 ))
- case "$method" in
- #*|'') continue ;;
- [^a-z]*) echo >&2 "huh ? $rcpts:$line: $method"; continue ;;
- log=log-$method-$line.txt
- exec >$log
- set +e
- printf >&2 "sms"
- ./"via-$method" $data 2>&1
- rc=$?
- set -e
- if [ $rc != 0 ]; then
- printf >&2 "-FAIL:%s\n" $log
- else
- printf >&2 " "
- fi
+senderinfo="$1"
+rcpts="$2"
+msg="$3"
+
+exec <"$senderinfo"
+while read settingname value; do
+ case "$settingname" in
+ #*|'') continue;;
+ *) vn=PIZZANOTIFY_$settingname
+ eval "$vn=\"\$value\""
+ export $vn
+ ;;
+ esac
done
-exec >&2
-echo >&2
+
+perl <"$rcpts" -wne '
+ use strict;
+ our @children;
+ our @passon;
+ BEGIN { @passon = @ARGV; @ARGV = (); }
+ s/^\s+//;
+ s/\s+$//;
+ next if m/^\#/;
+ next unless m/\S/;
+ die unless m/^([a-z]\w+)\s/;
+ my $method = $1;
+ my $child = fork;
+ defined $child or die $!;
+ if (!$child) {
+ exec "./onemethod", $method, @passon;
+ die $!;
+ }
+ push @children, $child;
+ END {
+ foreach my $child (@children) {
+ $!=$?=0;
+ my $got = waitpid $child, 0;
+ die $! unless $got==$child;
+ warn "$method [$child] $?" if $?;
+ }
+ }
+' "$rcpts" "$msg"
+
+echo