From: Joey Schulze Date: Fri, 2 May 2003 06:08:16 +0000 (+0000) Subject: Added a license, added argument parsing so the program is more X-Git-Url: https://git.infodrom.org/?p=infodrom%2Fcalendar;a=commitdiff_plain;h=32595d0a4f5dd2fdb131e3135b16d2e4666d2b4f Added a license, added argument parsing so the program is more flexible, rewrote the code mostly --- diff --git a/mail-calendar b/mail-calendar index ded9c49..91c6c3a 100755 --- a/mail-calendar +++ b/mail-calendar @@ -1,9 +1,80 @@ #! /bin/sh -( - echo "Subject: Kalender für den `LANG=de_DE date +"%d. %B"`" - echo "To: Martin Schulze " - echo - calendar -l 0 -w 0 -t `date +%d.%m` +# mail-calendar - send information about historical dates +# Copyright (c) 2002,3 Martin Schulze +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA + +opt_subject="Calendar for" +opt_dateform="%B %d" +opt_to=$LOGNAME +opt_advance=0 + +usage() +{ + echo "mail-calendar [-h|--help] [-l|--lang locale] [-t|--to addr] [-a|--advance]" +} + +# Parse arguments +while [ $# -gt 0 ] +do + case $1 in + -h|--help) + usage + exit + ;; + -l|--lang) + if [ $# -gt 1 ] + then + opt_lang=$2 + shift + fi + ;; + -t|--to) + if [ $# -gt 1 ] + then + opt_to=$2 + shift + fi + ;; + -a|--advance) + if [ $# -gt 1 ] + then + opt_advance=$2 + shift + fi + ;; + esac + shift +done -) | /usr/sbin/sendmail joey +# Add support for non-english languages/locales +case $opt_lang in +de_DE) + opt_subject="Kalender für den" + opt_dateform="%d. %B" +esac + +secs=$[ $opt_advance * 86400 ] + +c_date=`date -d now+${secs}seconds +%d.%m` +s_date=`LANG=$opt_lang date -d now+${secs}seconds "+$opt_dateform"` + +( + echo "Subject: $opt_subject $s_date" + echo "To: $opt_to" + echo + calendar -l 0 -w 0 -t $c_date +) | /usr/sbin/sendmail "$opt_to"