• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#*******************************************************************************
2# Copyright (c) 2005, 2006 IBM Corporation and others.
3# All rights reserved. This program and the accompanying materials
4# are made available under the terms of the Eclipse Public License v1.0
5# which accompanies this distribution, and is available at
6# http://www.eclipse.org/legal/epl-v10.html
7#
8# Contributors:
9#     IBM Corporation - initial API and implementation
10#*******************************************************************************
11#!/bin/sh
12
13# simple sample script to fire an email from the local machine to some user to
14# notify them of a change to the watched feed
15
16# Requirements:
17# tested on Debian (Kubuntu), using
18# exim 3.36-16
19# mailx 1:8.1.2-0.20040524cvs-4
20
21debug=0;
22feedURL="";
23xpath="";
24newvalue="";
25oldvalue="";
26
27while [ "$#" -gt 0 ]; do
28	case $1 in
29		'-debug')
30			debug=$2;
31			shift 1
32			;;
33		'-feedURL')
34			feedURL=$2;
35			shift 1
36			;;
37		'-xpath')
38			xpath=$2;
39			shift 1
40			;;
41		'-oldvalue')
42			oldvalue=$2;
43			shift 1
44			;;
45		'-newvalue')
46			newvalue=$2;
47			shift 1
48			;;
49	esac
50	shift 1
51done
52
53if [ $debug -gt 0 ]; then
54  echo "[sendEmailAlert] Started `date +%H:%M:%S`. Executing with the following options:"
55  echo "-debug $debug";
56  echo "-feedURL $feedURL";
57  echo "-xpath $xpath";
58  echo "-oldvalue $oldvalue";
59  echo "-newvalue $newvalue";
60fi
61
62tmpfile="/tmp/sendEmailAlert.sh.tmp";
63echo "" > $tmpfile;
64
65# compose message
66echo "Eclipse RSS Feed has been updated." >> $tmpfile;
67echo "" >> $tmpfile;
68echo "Here's what happened:" >> $tmpfile;
69echo "" >> $tmpfile;
70
71if [ "x$xpath" != "x" ]; then    echo "Changed Node: "$xpath >> $tmpfile; fi
72if [ "x$oldvalue" != "x" ]; then echo "Old Value:    "$oldvalue >> $tmpfile; fi
73if [ "x$newvalue" != "x" ]; then echo "New Value:    "$newvalue >> $tmpfile; fi
74if [ "x$feedURL" != "x" ]; then  echo "Feed URL:     "$feedURL >> $tmpfile; fi
75
76echo "" >> $tmpfile;
77
78#assemble mail info
79toAddress="codeslave@ca.ibm.com";
80fromAddress="Eclipse Build Team <NOSUCHADDRESS@eclipse.org>";
81subject="Eclipse RSS Feed Updated!";
82MAIL="/usr/bin/mail";
83
84if [ $debug -gt 0 ]; then
85    echo "Sending the following email using "$MAIL":";
86    echo "--";
87    echo "Subject: "$subject;
88    echo "To: "$toAddress
89    echo "From: "$fromAddress
90    echo "--";
91    cat $tmpfile;
92    echo "--";
93fi
94
95# send message
96cat $tmpfile | $MAIL -s "$subject" -a "From: $fromAddress" $toAddress;
97
98# cleanup
99rm -fr $tmpfile;
100
101if [ $debug -gt 0 ]; then
102    echo "Done.";
103fi
104