blob: 2208cc764601a915a94bf6a885582d2ecf0d1061 (
plain)
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
|
#!/bin/rc
# pim/fetch -- refresh a subscribed calendar from its url.
#
# pim/fetch $home/lib/cal/work.url $home/lib/cal/work.ics \
# /mnt/pim/calendars/work/ctl
#
# ical/fs does not fetch: a subscribed calendar is a file somebody else
# wrote. This is that somebody. It writes the file only when the content
# actually changed, then pokes ctl so the server reloads at once instead
# of waiting to notice.
#
# The url of a private calendar is a secret, so it is read from a file
# rather than passed as an argument where ps(1) would show it.
rfork e
if(! ~ $#* 2 && ! ~ $#* 3){
echo 'usage: fetch urlfile dest.ics [ctl]' >[1=2]
exit usage
}
urlfile=$1
dest=$2
ctl=$3
if(! test -r $urlfile){
echo 'pim/fetch: cannot read '^$urlfile >[1=2]
exit nourl
}
url=`{sed -n '/^#/d; /^$/d; s/["'']//g; p; q' $urlfile}
if(~ $#url 0){
echo 'pim/fetch: no url in '^$urlfile >[1=2]
exit nourl
}
tmp=$dest.new
if(! hget $"url > $tmp){
rm -f $tmp
echo 'pim/fetch: fetch failed' >[1=2]
exit fetch
}
if(! test -s $tmp){
rm -f $tmp
echo 'pim/fetch: empty response' >[1=2]
exit empty
}
# a fetch that changes nothing must not rebuild the tree or wake watchers
if(test -f $dest)
if(cmp -s $tmp $dest){
rm -f $tmp
exit 0
}
mv $tmp $dest
if(! ~ $#ctl 0)
if(test -f $ctl)
echo refresh >$ctl
exit 0
|