1#!/bin/sh 2# (c) 2004 Markus Gaugusch <markus at gaugusch dot at> 3# Script for syncing kaddressbook data with iPod 4 5# Usage: 6# 7# sync-kaddressbook.sh [-i <ipod mountpoint>] [-d <kaddressbook data file>] 8# ... [-e <encoding>] 9# 10# with the following defaults: 11 12IPOD_MOUNT=/mnt/ipod # mountpoint of ipod 13DATAFILE=~/.kde/share/apps/kabc/std.vcf # vcard file 14ENCODING=ISO-8859-15 # encoding used by ipod 15 16# Unless called with "-e none" this script requires "iconv" available 17# from http://www.gnu.org/software/libiconv/ 18 19# About the encoding used by the iPod (by Jorg Schuler): 20# 21# For some reason the encoding used for the contact files and 22# calenader files depends on the language you have set your iPod 23# to. If you set your iPod to German, iso-8859-15 (or -1?) is 24# expected. If you set it to Japanese, SHIFT-JIS is expected. You need 25# to reboot the iPod to have the change take effect, however. (I'm 26# using firmware version 1.3.) 27# 28# If you know of more encodings, please let me know, so they can be 29# added here: 30# 31# iPod language encoding expected 32# ---------------------------------------- 33# German ISO-8859-15 34# Japanese SHIFT-JIS 35 36 37# Changelog: 38# 39# 2004/06/27 (Jorg Schuler <jcsjcs at users dot sourceforge dot net>): 40# Changed to accept ipod-mountpath and encoding as command line 41# option 42# 43# Split into two files -- one for contacts, one for calendar. 44# 45# Placed under GPL in agreement with Markus Gaugusch. 46# 47# Added note about encoding used by the iPod. 48# 49# 2004/07/02 (Jorg Schuler <jcsjcs at users dot sourceforge dot net>): 50# Added Usage-line, added check for vcard file, rearranged source 51# 52# 2004/07/03 (Jorg Schuler <jcsjcs at users dot sourceforge dot net>): 53# Made "iconv" optional (call with "-e none") 54# 55# Removed "dos2unix" as my iPod (firmware 1.3) happily accepted 56# DOS-type vcards as well. Instead changed the "grep" pattern to 57# catch \cr\lf as well. 58 59 60# overwrite default settings with optional command line arguments 61while getopts i:d:e: option; do 62 case $option in 63 i) IPOD_MOUNT=$OPTARG;; 64 d) DATAFILE=$OPTARG;; 65 e) ENCODING=$OPTARG;; 66 \?) echo "Usage: `basename $0` [-i <ipod mountpoint>] [-d <kaddressbook data file>] [-e <encoding>]" 67 exit 1;; 68 esac 69done 70 71 72# set the RECODE command 73if [ $ENCODING = "none" ] || [ $ENCODING = "NONE" ]; then 74 RECODE="cat" # no conversion 75else 76 RECODE="iconv -f UTF-8 -t $ENCODING" 77fi 78 79 80# check if DATAFILE exists 81if [ ! -f $DATAFILE ]; then 82 echo "Error: $DATAFILE does not exist" 83 exit 1 84fi 85 86 87# remove all empty lines and recode if necessary 88echo -n "Syncing iPod ... [Contacts] " 89cat $DATAFILE | grep -v '^[[:space:]]$\|^$' | $RECODE > $IPOD_MOUNT/Contacts/`basename $DATAFILE` 90echo "done!" 91