File: group_calendaring.sh

package info (click to toggle)
pcal 4.11.0-4
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,604 kB
  • sloc: ansic: 6,747; csh: 245; makefile: 140; sh: 126; perl: 117
file content (122 lines) | stat: -rw-r--r-- 4,275 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/bin/bash

# Simple script to generate personal, group calendars
#
# Copyright Kristofer Bergstrom 2007
#
# Released under the terms of the GNU GPL.
#
#
# Usage: 
# Run from the command line, the script prompts the user to:
#   Display calendar? <y/N>
#   Print calendar? <y/N>
#   Send significant other calendar? <y/N>
#   Upload new group calendar? <y/N>
#     (if yes) Email group? <y/N>
#
#
# Future features -- anyone want to help?
#   Support for 1/1/07 type date entries in .calendar
#   Improve ease of adoption, adaptation for others
#
# 
# Before using:
#   The script references the following external programs,
#   not installed by default on most systems:
#      pcal, gv, ps2pdf, mutt
#   
#   Read through the whole script!  There are lots of references
#      to my system that need to be changed.   
#   You must at least adjust the following references below to match 
#   your system:
#      replace "/home/<username>/.calendar" with your .calendar location
#      Signif. other section
#         personalize echo message
#         change signif. other's email address
#      upload section
#         change scp line to send the file to your server
#         personalize the group email echo line
#         change email addresses to be your group members' addresses
#         change test line email address to be your email address
#         

myMonth=$(date +%m)
myYear=$(date +%Y)
myPdfGenerated=0
myGroupEmailed=0

cd /tmp/
cp /home/<username>/.calendar /tmp/.calendar.tmp

pcal -E -f /tmp/.calendar.tmp -o /tmp/cal.ps $myMonth $myYear 12

grep ON /tmp/.calendar.tmp > /tmp/grpCal.tmp
pcal -E -f /tmp/grpCal.tmp -o /tmp/grpCal.ps $myMonth $myYear 12
pcal -E -H -f /tmp/grpCal.tmp -o /tmp/grpCal.html $myMonth $myYear 12
ed -s /tmp/grpCal.html <<< $'6a\nGroup calendar, updated '"$(date)"$'\n.\nw'


echo -e "Personal calendar generated... \nGroup calendar generated... \n12-months, beginning" $myMonth $myYear


# Display calendar with ghostview
read -n 1 -p "Display calendar? <y/N> "
if [ "$REPLY" = "y" ]; then
   gv /tmp/cal.ps
fi
echo ""


# Print calendar
read -n 1 -p "Print calendar? <y/N> "
if [ "$REPLY" = "y" ]; then
   lp /tmp/cal.ps
fi
echo ""


# Send calendar to signif. other
read -n 1 -p "Send calendar to signif. other? <y/N> "
if [ "$REPLY" = "y" ]; then
   ps2pdf /tmp/cal.ps
   echo -e "This message is generated automatically...\n\nAttached is my newest calendar.\n\n   Kris" | mutt -a /tmp/cal.pdf -s "<Your name>'s newest calendar" signif@other.com 
   myPdfGenerated=1
fi
echo ""


# Upload calendar to server and email group members
read -n 1 -p "Upload new group calendar? <y/N> "
if [ "$REPLY" = "y" ]; then
    scp /tmp/grpCal.html user@server://var/www/<your location>grpCal.html
    echo ""
    read -n 1 -p "Email group? <y/N> "   
    if [ "$REPLY" = "y" ]; then 
        myGroupEmailed=1
        ps2pdf /tmp/grpCal.ps
        # build email text
        touch /tmp/myEmailContents.txt
        echo -e "This message automatically generated...\n\nThe group calendar has been updated.\nEvents have been added, changed, or deleted on the following dates.\n\n" >> /tmp/myEmailContents.txt
        diff /home/<username>/grpCal.prev /tmp/grpCal.tmp | grep '[0-9][0-9]/[0-9][0-9]/[0-9][0-9]' | cut -c 3-10 | awk -F/ '{print "20"$3"/"$2"/"$1}' | sort | uniq >> /tmp/myEmailContents.txt # Comparison of old group calendar with newly-generated group calendar
        echo -e "\n\nPlease see <yourwebsite>/grpCal.html for the updated version, or the attached PDF.\n\n\nPS - Any new personal dates I should know about?" >> /tmp/myEmailContents.txt
        # send email
#       mutt -a /tmp/grpCal.pdf -s "Group calendar update" group@member1.com group@member2.com group@member3.com < /tmp/myEmailContents.txt
        mutt -a /tmp/grpCal.pdf -s "Group calendar update - TEST" your@email.com < /tmp/myEmailContents.txt # testing version
    fi
    mv /tmp/grpCal.tmp /home/<username>/grpCal.prev
fi
echo ""


# move the most recent calendar to safe keeping, remove all
# remaining temporary files
rm /tmp/.calendar.tmp /tmp/cal.ps /tmp/grpCal.html /tmp/myEmailContents.txt
if [ $myPdfGenerated = 1 ]; then
    rm /tmp/grpCal.pdf
fi
if [ $myGroupEmailed = 1 ]; then
    rm /tmp/myEmailContents.txt
fi
echo "Returning to dir: " 
cd -