Added a license, added argument parsing so the program is more
[infodrom/calendar] / mail-calendar
1 #! /bin/sh
2
3 #   mail-calendar - send information about historical dates
4 #   Copyright (c) 2002,3  Martin Schulze <joey@infodrom.org>
5 #
6 #   This program is free software; you can redistribute it and/or modify
7 #   it under the terms of the GNU General Public License as published by
8 #   the Free Software Foundation; either version 2 of the License, or
9 #   (at your option) any later version.
10 #
11 #   This program is distributed in the hope that it will be useful,
12 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 #   GNU General Public License for more details.
15 #
16 #   You should have received a copy of the GNU General Public License
17 #   along with this program; if not, write to the Free Software
18 #   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
19
20 opt_subject="Calendar for"
21 opt_dateform="%B %d"
22 opt_to=$LOGNAME
23 opt_advance=0
24
25 usage()
26 {
27     echo "mail-calendar [-h|--help] [-l|--lang locale] [-t|--to addr] [-a|--advance]"
28 }
29
30 # Parse arguments
31 while [ $# -gt 0 ]
32 do
33     case $1 in
34     -h|--help)
35         usage
36         exit
37         ;;
38     -l|--lang)
39         if [ $# -gt 1 ]
40         then
41             opt_lang=$2
42             shift
43         fi
44         ;;
45     -t|--to)
46         if [ $# -gt 1 ]
47         then
48             opt_to=$2
49             shift
50         fi
51         ;;
52     -a|--advance)
53         if [ $# -gt 1 ]
54         then
55             opt_advance=$2
56             shift
57         fi
58         ;;
59     esac
60     shift
61 done
62
63 # Add support for non-english languages/locales
64 case $opt_lang in
65 de_DE)
66         opt_subject="Kalender für den"
67         opt_dateform="%d. %B"
68 esac
69
70 secs=$[ $opt_advance * 86400 ]
71
72 c_date=`date -d now+${secs}seconds +%d.%m`
73 s_date=`LANG=$opt_lang date -d now+${secs}seconds "+$opt_dateform"`
74
75 (
76     echo "Subject: $opt_subject $s_date"
77     echo "To: $opt_to"
78     echo
79     calendar -l 0 -w 0 -t $c_date
80 ) | /usr/sbin/sendmail "$opt_to"