#!/bin/sh # Shell script to sync Emacs-wiki and Palm MemoDB # Author: Richard Klinda (TMDA) # Last modified: Monday, March 14, 2005 # URL: http://ignotus.linuxforum.hu/WikiSync.html # !!! Make sure that all the wiki files' last line is a NEWLINE! ## ---(:excerpt-beg save-buffer-defadvice :name 403de639)--- ## ---(:excerpt-source "../.xemacs/init.el")--- #(defadvice save-buffer (before newline-for-wiki-files last activate) # "Make sure that the last line of emacs-wiki files is NEWLINE." # (when (and (eq major-mode 'emacs-wiki-mode) # (buffer-modified-p)) # (save-excursion # (goto-char (point-max)) # (unless (looking-at "^$") # (insert "\n"))))) ## ---(:excerpt-end save-buffer-defadvice :name 403de639)--- # set these three variables: STATUSDIR=~/.wikisync WIKIDIR=~/.Wiki CATEGORY_ON_PALM="Wiki" # do you want automagic diffs? AUTODIFF=1 # ############################################################### code ### function my_md5sum () { echo "`cat $1 | /usr/bin/md5sum | cut -f 1 -d ' '`" } function md5_cache () { echo "`cat $STATUSDIR/md5sums | grep \ $1\$ | cut -d ' ' -f 1`" } currentdir=`pwd` if [ ! -e $STATUSDIR ] then mkdir $STATUSDIR fi cd $STATUSDIR if [ -e lastsynctime ] then lastsynctime=`cat lastsynctime` fi if [ -e memos ] then rm -rf memos fi mkdir memos mkdir memos/$CATEGORY_ON_PALM echo I\'ll download the memos from your palm now, press Sync on your echo Palm, then press RET here! read cd memos memos -c "$CATEGORY_ON_PALM" -s . palmnum=`find . | wc -l` pcnum=`find $WIKIDIR | wc -l` cd $CATEGORY_ON_PALM for i in *; do # cut the first line cat $i | tail -$[ `wc -l < $i` - 1 ] > $i.tmp && mv $i.tmp $i md5sum_pc="" md5sum_palm=`my_md5sum $i` # if the file exists on the PC too if [ -e $WIKIDIR/$i ] then md5sum_pc=`my_md5sum $WIKIDIR/$i` if [ ! "$md5sum_pc" = "$md5sum_palm" ] then # the file is changed, now we have to find out which changed or # maybe both changed? md5sum_old=`md5_cache $i` if [ "$md5sum_old" = "$md5sum_pc" ] then echo ... $i changed on Palm, copying to PC cp $i $WIKIDIR/ elif [ "$md5sum_old" = "$md5sum_palm" ] then echo ... $i changed on PC \(will be copied to Palm\) else echo ... WOOPS $i CHANGED on Palm and PC too, changes on the echo Palm will be lost! conflict="yes" if [ $AUTODIFF = "1" ] then echo _____ diff $WIKIDIR/$i $i _____ diff -u $WIKIDIR/$i $i fi fi fi else # the file doesn't exist on the PC # There are two possibilities: # - the user deleted the file on the PC; # - the user created a new Wiki entry on the Palm. if [ -z `md5_cache $i` ] then echo ... $i is a new Wiki file on Palm, copying to PC cp $i $WIKIDIR/ else echo ... $i is obsolete entry on Palm \(will be deleted\) fi; fi; done echo Now writing back the memos to the Palm, press Sync on echo "your palm, then press RET here!" if [ "$conflict" = "yes" ] then echo echo "!!! You have one or more wiki files changed on both the PC and" echo " the Palm, changes on the Palm will be lost, but now you can" echo " take a look at your Palm wiki files in $STATUSDIR/$CATEGORY_ON_PALM" echo " and edit your PC files to have the information. Don't forget" echo " to save then press RET here." fi if [ ! "$palmnum" = "$pcnum" ] then echo echo "Different number of Wiki files:" echo " Palm: $palmnum memo entries" echo " PC: $pcnum memo entries" echo "It's probably ok, but sometimes pilot-xfer does weird things..." echo "Press RET to continue." fi read cd $WIKIDIR md5sum * > $STATUSDIR/md5sums date +%s > $STATUSDIR/lastsynctime install-memo -c $CATEGORY_ON_PALM -rt * cd $currentdir # Script ends here.