3 # iPhone2Mac -- save call logs from iPhone backups
4 # Copyright (c)2009 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.
19 [ -n "$DEBUG" ] && VERBOSE=1
30 [ -n "$VERBOSE" ] && message "$*"
33 [ -n "$DEBUG" ] && verbose "$*"
38 NAME=`basename "$0" | cut -d'.' -f1`
39 DATA_DIR=~/Library/Application\ Support/$NAME
40 CALL_LOG="${DATA_DIR}/call.log"
41 CALL_TMP="/tmp/$NAME.$$.call.log.tmp"
42 debug "DATA_DIR=$DATA_DIR"
44 mkdir -p "$DATA_DIR" || abort "Can't create \"$DATA_DIR\"!"
46 if [ -z "$backup_d" ]; then
47 verbose "Locating backup directory ..."
48 cd ~/Library/Application\ Support/MobileSync/Backup/ \
49 || abort "No backup data stores found!?"
51 || abort "Can't access backup directory!?"
53 cd "$backup_d" || abort "Can't access backup directory!?"
55 verbose "iPhone Backup directory is \"$PWD\"."
57 if [ -z "$call_db" ]; then
58 verbose "Locating SQLite call database(s) ..."
59 call_db=$(for f in `file * | fgrep SQLite | cut -d':' -f1`; do
60 sqlite3 "$f" ".schema" | fgrep "CREATE TABLE call (" >/dev/null;
61 [ $? -eq 0 ] && echo "$f"; done
65 verbose "Found call database: \"$f\""
68 if [ -e "$CALL_LOG" ]; then
69 debug "Copying existing ASCII call log ..."
70 cp "$CALL_LOG" "$CALL_TMP" || abort "Can't copy old log file!"
73 verbose "Dumping SQLite call databse \"$f\" ..."
74 sqlite3 "$f" "select * from call;" >>"$CALL_TMP"
76 verbose "Sorting plain ASCII call log ..."
77 sort -u "$CALL_TMP" >"$CALL_LOG"
79 first_d=$(date -r `head -1 "$CALL_LOG" | cut -d'|' -f3` "+%Y-%m-%d %H:%M")
80 last_d=$(date -r `tail -1 "$CALL_LOG" | cut -d'|' -f3` "+%Y-%m-%d %H:%M")
81 message `wc -l "$CALL_LOG" | awk '{print \$1}'`" unique entries logged, from $first_d to $last_d."