]> arthur.barton.de Git - iPhone2Mac.git/blob - iPhone2Mac.sh
df7ea4f2d2c3d08938e9389d4666f0642ec049ee
[iPhone2Mac.git] / iPhone2Mac.sh
1 #!/bin/bash
2 # 2009-07-25, alex@barton.de
3
4 DEBUG=
5 VERBOSE=1
6
7 backup_d=""
8 call_db=""
9
10 [ -n "$DEBUG" ] && VERBOSE=1
11
12 abort() {
13         echo "$*"
14         exit 1
15 }
16
17 message() {
18         echo "$*"
19 }
20 verbose() {
21         [ -n "$VERBOSE" ] && message "$*"
22 }
23 debug() {
24         [ -n "$DEBUG" ] && verbose "$*"
25 }
26
27 umask 0077
28
29 NAME=`basename "$0" | cut -d'.' -f1`
30 DATA_DIR=~/Library/Application\ Support/$NAME
31 CALL_LOG="${DATA_DIR}/call.log"
32 CALL_TMP="/tmp/$NAME.$$.call.log.tmp"
33 debug "DATA_DIR=$DATA_DIR"
34
35 mkdir -p "$DATA_DIR" || abort "Can't create \"$DATA_DIR\"!"
36
37 if [ -z "$backup_d" ]; then
38         verbose "Locating backup directory ..."
39         cd ~/Library/Application\ Support/MobileSync/Backup/ \
40                 || abort "No backup data stores found!?"
41         cd * \
42                 || abort "Can't access backup directory!?"
43 else
44         cd "$backup_d" || abort "Can't access backup directory!?"
45 fi
46 verbose "iPhone Backup directory is \"$PWD\"."
47
48 if [ -z "$call_db" ]; then
49         verbose "Locating SQLite call database(s) ..."
50         call_db=$(for f in `file * | fgrep SQLite | cut -d':' -f1`; do
51                 sqlite3 "$f" ".schema" | fgrep "CREATE TABLE call (" >/dev/null;
52                 [ $? -eq 0 ] && echo "$f"; done
53         )
54 fi
55 for f in $call_db; do
56         verbose "Found call database: \"$f\""
57 done
58
59 if [ -e "$CALL_LOG" ]; then
60         debug "Copying existing ASCII call log ..."
61         cp "$CALL_LOG" "$CALL_TMP" || abort "Can't copy old log file!"
62 fi
63 for f in $call_db; do
64         verbose "Dumping SQLite call databse \"$f\" ..."
65         sqlite3 "$f" "select * from call;" >>"$CALL_TMP"
66 done
67 verbose "Sorting plain ASCII call log ..."
68 sort -u "$CALL_TMP" >"$CALL_LOG"
69 rm -f "$CALL_TMP"
70 first_d=$(date -r `head -1 "$CALL_LOG" | cut -d'|' -f3` "+%Y-%m-%d %H:%M")
71 last_d=$(date -r `tail -1 "$CALL_LOG" | cut -d'|' -f3` "+%Y-%m-%d %H:%M")
72 message `wc -l "$CALL_LOG" | awk '{print \$1}'`" unique entries logged, from $first_d to $last_d."