]> arthur.barton.de Git - iPhone2Mac.git/blobdiff - iPhone2Mac.sh
Update nice level and import interval
[iPhone2Mac.git] / iPhone2Mac.sh
index df7ea4f2d2c3d08938e9389d4666f0642ec049ee..4070cc60c5b0d419683e6b0afd2183e0a096a8bf 100755 (executable)
@@ -1,11 +1,19 @@
 #!/bin/bash
-# 2009-07-25, alex@barton.de
+#
+# iPhone2Mac -- save call logs from iPhone backups
+# Copyright (c)2009-2011 Alexander Barton (alex@barton.de).
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+# Please read the file COPYING and README for more information.
+#
 
 DEBUG=
 VERBOSE=1
 
-backup_d=""
-call_db=""
+umask 0077
 
 [ -n "$DEBUG" ] && VERBOSE=1
 
@@ -24,7 +32,50 @@ 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;" | while read row; do
+                       IFS="|"
+                       arr=($row)
+                       unset IFS
+
+                       rowid=${arr[0]}
+                       address=${arr[1]}
+                       date=${arr[2]}
+                       duration=${arr[3]}
+                       flags=${arr[4]}
+                       id=${arr[5]}
+
+                       echo "$date|$rowid|$address|$duration|$flags|$id" \
+                         >>"$CALL_TMP"
+               done
+       done
+       verbose "Sorting plain ASCII call log ..."
+       sort -un "$CALL_TMP" >"$CALL_LOG"
+       rm -f "$CALL_TMP"
+       first_d=$(date -r `head -1 "$CALL_LOG" | cut -d'|' -f1` "+%Y-%m-%d %H:%M")
+       last_d=$(date -r `tail -1 "$CALL_LOG" | cut -d'|' -f1` "+%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
@@ -34,39 +85,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."