#!/bin/bash # # example ~/gcalsync/curlrc (use firebug to get the exact cookie/form # values): # # user-agent = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2) Gecko/20100125 Firefox/3.6" # referer = "https://www.google.com/calendar/hosted/domain.com/render" # cookie = "S=foo; secid=bar" # form = "filename=@items.ics" # form = "src=baz" # url = "https://www.google.com/calendar/hosted/domain.com/upload_event" # # example ~/.kde/Autostart/gcalsync-daemon: # #!/bin/sh # # gcalsync --daemon & if [ "$1" == "--daemon" ]; then while : do sleep 60 qdbus || break [ -d ~/.gcalsync ] && mkdir ~/.gcalsync bash -e $0 &> ~/.gcalsync/log done exit 0 fi if [ -e ~/.gcalsync/lastsync ]; then lastsync="$(cat ~/.gcalsync/lastsync)" else lastsync=0 fi now=$(date +%s) if [ $(($now-$lastsync)) -lt 86400 ]; then echo ":: already synced within a day ($(($now-$lastsync)) seconds ago), not syncing" exit 0 fi echo ":: contacting google.com..." count="$((ping -c 1 www.google.com 2>/dev/null || echo ', 0 received')| grep received|sed 's/.*, \(.*\) received.*/\1/')" if [ "$count" -eq 0 ]; then echo ":: google.com is not reachable, not syncing" exit 1 fi echo ":: searching for the phone..." if ! hcitool scan|grep -q $(grep ^port ~/.gammurc |sed 's/.*= //'); then echo ":: not found, not syncing" kdialog --title gcalsync --passivepopup "Phone not found, need to sync, but can't." 0 exit 1 fi echo ":: creating items.ics..." if [ ! -d ~/.gcalsync/git ]; then mkdir ~/.gcalsync/git cd ~/.gcalsync/git git init fi cd ~/.gcalsync/git (echo no; yes yes) |gammu --backup backup.gammu echo -e 'yes\nno' |gammu --backup items.ics echo dos2unix items.ics sed -i '/DTSTART/s/Z$//' items.ics sed -i '/DTEND/s/Z$//' items.ics sed -i '/ALARM/s/Z$//' items.ics unix2dos items.ics echo ":: uploading events..." git update-index -q --refresh if [ -z "$(git diff-index --name-only HEAD --)" ]; then kdialog --title gcalsync --passivepopup "Not synchronising, no changes." else git add items.ics backup.gammu git commit -m "$(date +%Y-%m-%d)" out=$(curl -s -k --config ~/.gcalsync/curlrc |elinks -dump|sed -n 's/imported/synchronised/;3p') kdialog --title gcalsync --passivepopup "$out" 0 fi echo $now > ~/.gcalsync/lastsync echo ":: done."