summaryrefslogtreecommitdiff
path: root/pim/rc/fetch
diff options
context:
space:
mode:
authorCalvin Morrison <calvin@pobox.com>2026-08-22 13:16:49 -0400
committerCalvin Morrison <calvin@pobox.com>2026-08-22 13:16:49 -0400
commit8a3d2c99bff60cb775ebc42516c0c3912d54ba3d (patch)
treefd136a3b7927146763cdc11e6be07c71f92bb92c /pim/rc/fetch
parent9aacce8b3b54060d0037eca897856d7273e6e5e8 (diff)
pim: personal information management, starting with a calendar
A calendar as a file tree, and tools that only know the tree: events/date/yyyy/mm/dd/hhmm-summary as lived events/uuid/<uid>/ as stored ctl query alarm changed lib/cal owns all of that. A backend supplies events and, where its protocol allows, takes changes back -- six methods. cmd/icalfs is the first: it reads .ics files from a directory and nothing else, because fetching is rc/fetch's job and hget already exists. That keeps net/http out of the binary and makes a subscribed calendar and a local one the same thing. The tools are rc on purpose. If the tree needs a compiled program to be useful, the tree is the wrong shape. Three things were added to the tree because the rc port needed them: a path from an occurrence to its event, epoch seconds beside RFC3339, and a numeric slot for all-day events so test(1) can compare it. ctl reports caps, so a tool can say "read only" instead of trying and failing. A published .ics is read only: nowhere to PUT, and no METHOD:REQUEST to reply to. CalDAV would be read write rsvp schedule, and that is the next backend. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Diffstat (limited to 'pim/rc/fetch')
-rwxr-xr-xpim/rc/fetch56
1 files changed, 56 insertions, 0 deletions
diff --git a/pim/rc/fetch b/pim/rc/fetch
new file mode 100755
index 0000000..2208cc7
--- /dev/null
+++ b/pim/rc/fetch
@@ -0,0 +1,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