Enable iPhone2Mac.sh to deal with more than one backup directory
authorAlexander Barton <alex@barton.de>
Wed, 4 Aug 2010 20:07:41 +0000 (22:07 +0200)
committerAlexander Barton <alex@barton.de>
Wed, 4 Aug 2010 20:07:41 +0000 (22:07 +0200)
iPhone2Mac.sh

index 5ef17c0..0cf3ea4 100755 (executable)
@@ -13,8 +13,7 @@
 DEBUG=
 VERBOSE=1
 
-backup_d=""
-call_db=""
+umask 0077
 
 [ -n "$DEBUG" ] && VERBOSE=1
 
@@ -33,7 +32,36 @@ debug() {
        [ -n "$DEBUG" ] && verbose "$*"
 }
 
-umask 0077
+import_d() {
+       call_db=""
+       cd "$1" || abort "Can't change directory to \"$1\"!"
+       verbose "iPhone Backup directory is \"$1\"."
+       if [ -z "$call_db" ]; then
+               verbose "Locating SQLite call database(s) ..."
+               call_db=$(for f in `file * | fgrep SQLite | cut -d':' -f1`; do
+                       sqlite3 "$f" ".schema" | fgrep "CREATE TABLE call (" >/dev/null;
+                       [ $? -eq 0 ] && echo "$f"; done
+               )
+       fi
+       for f in $call_db; do
+               verbose "Found call database: \"$f\""
+       done
+
+       if [ -e "$CALL_LOG" ]; then
+               debug "Copying existing ASCII call log ..."
+               cp "$CALL_LOG" "$CALL_TMP" || abort "Can't copy old log file!"
+       fi
+       for f in $call_db; do
+               verbose "Dumping SQLite call databse \"$f\" ..."
+               sqlite3 "$f" "select * from call;" >>"$CALL_TMP"
+       done
+       verbose "Sorting plain ASCII call log ..."
+       sort -u "$CALL_TMP" >"$CALL_LOG"
+       rm -f "$CALL_TMP"
+       first_d=$(date -r `head -1 "$CALL_LOG" | cut -d'|' -f3` "+%Y-%m-%d %H:%M")
+       last_d=$(date -r `tail -1 "$CALL_LOG" | cut -d'|' -f3` "+%Y-%m-%d %H:%M")
+       message `wc -l "$CALL_LOG" | awk '{print \$1}'`" unique entries logged, from $first_d to $last_d."
+}
 
 NAME=`basename "$0" | cut -d'.' -f1`
 DATA_DIR=~/Library/Application\ Support/$NAME
@@ -43,39 +71,10 @@ debug "DATA_DIR=$DATA_DIR"
 
 mkdir -p "$DATA_DIR" || abort "Can't create \"$DATA_DIR\"!"
 
-if [ -z "$backup_d" ]; then
-       verbose "Locating backup directory ..."
-       cd ~/Library/Application\ Support/MobileSync/Backup/ \
-               || abort "No backup data stores found!?"
-       cd * \
-               || abort "Can't access backup directory!?"
-else
-       cd "$backup_d" || abort "Can't access backup directory!?"
-fi
-verbose "iPhone Backup directory is \"$PWD\"."
-
-if [ -z "$call_db" ]; then
-       verbose "Locating SQLite call database(s) ..."
-       call_db=$(for f in `file * | fgrep SQLite | cut -d':' -f1`; do
-               sqlite3 "$f" ".schema" | fgrep "CREATE TABLE call (" >/dev/null;
-               [ $? -eq 0 ] && echo "$f"; done
-       )
-fi
-for f in $call_db; do
-       verbose "Found call database: \"$f\""
-done
+verbose "Locating backup directories ..."
+[ -d ~/Library/Application\ Support/MobileSync/Backup ] \
+       || abort "No backup data stores found!?"
 
-if [ -e "$CALL_LOG" ]; then
-       debug "Copying existing ASCII call log ..."
-       cp "$CALL_LOG" "$CALL_TMP" || abort "Can't copy old log file!"
-fi
-for f in $call_db; do
-       verbose "Dumping SQLite call databse \"$f\" ..."
-       sqlite3 "$f" "select * from call;" >>"$CALL_TMP"
+for d in ~/Library/Application\ Support/MobileSync/Backup/*; do
+       import_d "$d"
 done
-verbose "Sorting plain ASCII call log ..."
-sort -u "$CALL_TMP" >"$CALL_LOG"
-rm -f "$CALL_TMP"
-first_d=$(date -r `head -1 "$CALL_LOG" | cut -d'|' -f3` "+%Y-%m-%d %H:%M")
-last_d=$(date -r `tail -1 "$CALL_LOG" | cut -d'|' -f3` "+%Y-%m-%d %H:%M")
-message `wc -l "$CALL_LOG" | awk '{print \$1}'`" unique entries logged, from $first_d to $last_d."