Quoted double quotes
[clearscm.git] / bin / updateCalendar.sh
1 #!/bin/bash
2
3 # Odd. Seems the following causes wget to use IPv6 instead of IPv4. Well
4 # recently we turned off IPv6 because we suspect this causes our WiFi 
5 # dropout problem. But then this hangs.
6 #wget -O /tmp/calendar.$$.ics 'https://www.google.com/calendar/ical/adefaria%40gmail.com/public/basic.ics' >> /tmp/updateCalendar.$$.log 2>&1
7 wget --no-check-certificate -O /tmp/calendar.$$.ics 'https://172.217.11.174/calendar/ical/adefaria%40gmail.com/public/basic.ics' >> /tmp/updateCalendar.$$.log 2>&1
8 wget -O /tmp/meetups.$$.ics 'http://www.meetup.com/events/ical/10426135/8dfdd0ffaaedecf720c5faf0cf3871b7ee5f5c1e/going' >> /tmp/updateCalendar.$$.log 2>&1
9
10 wget -4 -O /tmp/tripit.$$.ics 'http://www.tripit.com/feed/ical/private/06C4F90D-EFEFB9C5FDB17EC5FCB327DE31A54D96/tripit.ics' >> /tmp/updateCalendar.$$.log 2>&1
11
12 # Now let's combine the files. First strip off the END:CALENDAR from the main 
13 # file.
14 filesize=$(wc -l /tmp/calendar.$$.ics | cut -f1 -d' ')
15 let lines=filesize-1
16 head -n $lines /tmp/calendar.$$.ics > /tmp/calendar2.$$.ics
17 mv /tmp/calendar2.$$.ics /tmp/calendar.$$.ics
18
19 # Now extract the middle of the next calendar
20 # Note, if we have nothing RSVPed here for Meetup then the file should be skipped.
21 # We will get an .ics file but it'll be short - less than 27 lines
22 filesize=$(wc -l /tmp/meetups.$$.ics | cut -f1 -d' ')
23
24 if [ $filesize -gt 27 ]; then
25   let lines=filesize-27
26
27   # Get the top portion...
28   tail -n $lines /tmp/meetups.$$.ics > /tmp/meetups2.$$.ics
29
30   # Now strip off END:VCALENDAR
31   let lines=filesize-27-1
32
33   head -n $lines /tmp/meetups2.$$.ics >> /tmp/calendar.$$.ics
34
35   # Clean up meetups2
36   rm -f /tmp/meetups2.$$.ics
37 fi
38
39 # Now extract the middle of the next calendar
40 filesize=$(wc -l /tmp/tripit.$$.ics | cut -f1 -d' ')
41
42 if [ $filesize -gt 27 ]; then
43   let lines=filesize-27
44
45   # Get the top portion...
46   tail -n $lines /tmp/tripit.$$.ics > /tmp/tripit2.$$.ics
47
48   # Now strip off END:VCALENDAR
49   let lines=filesize-27-1
50
51   head -n $lines /tmp/tripit2.$$.ics >> /tmp/calendar.$$.ics
52
53   # Cleanup tripit2
54   rm -f /tmp/tripit2.$$.ics
55 fi
56
57 # Now add END:VCALENDAR to calendar.ics
58 echo "END:VCALENDAR" >> /tmp/calendar.$$.ics
59
60 # Move into place
61 mv /tmp/calendar.$$.ics ~/Documents/calendar.ics
62
63 # Get rid of stupid CRs
64 dos2unix -q ~/Documents/calendar.ics
65
66 # Restart rainlendar2
67 export DISPLAY=:1
68 killall rainlendar2
69 rainlendar2 > /tmp/rainlendar2.log 2>&1 &
70
71 # Cleanup
72 rm -rf                  \
73   /tmp/meetups.$$.ics   \
74   /tmp/tripit.$$.ics    \
75   /tmp/updateCalendar.$$.log