zotero/scripts/zoteroconf.sh
Dan Stillman 00c2b14d6c Adds rudimentary Zeroconf support to Zotero (a.k.a. "Z(ot)eroconf")
- Inspired by Dan Chudnov's Python/MODS-based Zeroconf demo at THATcamp
- Enabled by extensions.zotero.zeroconf.enabled (off by default)
- Currently supports only OS X (tested on Leopard, not sure about earlier versions)
- Uses Apple's dns-sd and mDNS command-client clients, but should be able to be extended to other clients, though a native library would be far superior
- Discovery is on-demand for now via Actions menu ("Search for Shared Libraries")
- Includes rudimentary web server (code copied from integration.js) that serves items as sync XML -- no authentication yet!
- Only supports top-level items
- Remote libraries show up in left pane (under remote computer name, for now)
- Items can be dragged into collections (but not the library yet, for some reason)
- On first run, might cause a long pause and the "This file was downloaded from the Internet" message on Leopard -- can't manage to get around the quarantine for the script file that we need to access stdout from Firefox
- Needs a lot of work, and without a real JS (or otherwise Mozilla-native) Zeroconf library we can't do proper discovery without intermittent polling
- But it works, at least for me

Also includes some data/sync-layer changes that I needed along the way (and that we'll need for shared collections of any type)
2008-06-03 05:26:30 +00:00

42 lines
1,022 B
Bash
Executable file

#!/bin/sh
if [ ! "$1" ]; then
echo "Action not specified"
exit 1
fi
if [ $1 = "find_instances" ]; then
dns-sd -B _zotero._tcp local. > /tmp/zoteroconf_instances &
elif [ $1 = "kill_find_instances" ]; then
PIDs=`ps x | grep "dns-sd -B" | grep _zotero._tcp | sed -E 's/ *([0-9]+).*/\1/' | xargs`
if [ "$PIDs" ]; then
kill $PIDs
fi
elif [ $1 = "get_info" ]; then
if [ ! "$2" ]; then
echo "Service name not specified"
exit 1
fi
if [ ! "$3" ]; then
echo "Temp file path not specified"
exit 1
fi
#dns-sd -L "$2" _zotero._tcp local. > $3 &
mDNS -L "$2" _zotero._tcp local. > $3 &
elif [ $1 = "kill_get_info" ]; then
#PIDs=`ps x | grep "dns-sd -L" | grep _zotero._tcp | sed -E 's/ *([0-9]+).*/\1/' | xargs`
PIDs=`ps x | grep "mDNS -L" | grep _zotero._tcp | sed -E 's/ *([0-9]+).*/\1/' | xargs`
if [ "$PIDs" ]; then
kill $PIDs
fi
elif [ $1 = "kill_service" ]; then
PIDs=`ps x | grep dns-sd | grep '_zotero._tcp' | sed -E 's/ *([0-9]+).*/\1/' | xargs`
if [ "$PIDs" ]; then
kill $PIDs
fi
fi