3 # iPhone2Mac -- save call logs from iPhone backups
4 # Copyright (c)2009-2011 Alexander Barton (alex@barton.de).
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 # Please read the file COPYING and README for more information.
18 [ -n "$DEBUG" ] && VERBOSE=1
29 [ -n "$VERBOSE" ] && message "$*"
32 [ -n "$DEBUG" ] && verbose "$*"
37 cd "$1" || abort "Can't change directory to \"$1\"!"
38 verbose "iPhone Backup directory is \"$1\"."
39 if [ -z "$call_db" ]; then
40 verbose "Locating SQLite call database(s) ..."
41 call_db=$(for f in `file * | fgrep SQLite | cut -d':' -f1`; do
42 sqlite3 "$f" ".schema" | fgrep "CREATE TABLE call (" >/dev/null;
43 [ $? -eq 0 ] && echo "$f"; done
47 verbose "Found call database: \"$f\""
50 if [ -e "$CALL_LOG" ]; then
51 debug "Copying existing ASCII call log ..."
52 cp "$CALL_LOG" "$CALL_TMP" || abort "Can't copy old log file!"
55 verbose "Dumping SQLite call databse \"$f\" ..."
56 sqlite3 "$f" "select * from call;" | while read row; do
68 echo "$date|$rowid|$address|$duration|$flags|$id" \
72 verbose "Sorting plain ASCII call log ..."
73 sort -un "$CALL_TMP" >"$CALL_LOG"
75 first_d=$(date -r `head -1 "$CALL_LOG" | cut -d'|' -f1` "+%Y-%m-%d %H:%M")
76 last_d=$(date -r `tail -1 "$CALL_LOG" | cut -d'|' -f1` "+%Y-%m-%d %H:%M")
77 message `wc -l "$CALL_LOG" | awk '{print \$1}'`" unique entries logged, from $first_d to $last_d."
80 NAME=`basename "$0" | cut -d'.' -f1`
81 DATA_DIR=~/Library/Application\ Support/$NAME
82 CALL_LOG="${DATA_DIR}/call.log"
83 CALL_TMP="/tmp/$NAME.$$.call.log.tmp"
84 debug "DATA_DIR=$DATA_DIR"
86 mkdir -p "$DATA_DIR" || abort "Can't create \"$DATA_DIR\"!"
88 verbose "Locating backup directories ..."
89 [ -d ~/Library/Application\ Support/MobileSync/Backup ] \
90 || abort "No backup data stores found!?"
92 for d in ~/Library/Application\ Support/MobileSync/Backup/*; do