X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=iPhone2Mac.git;a=blobdiff_plain;f=iPhone2Mac.sh;h=4070cc60c5b0d419683e6b0afd2183e0a096a8bf;hp=5ef17c03b7ee903842c1a30a13c02765657605c2;hb=HEAD;hpb=04715eb45e2264950c0e78ef7f5dd94f8265f586 diff --git a/iPhone2Mac.sh b/iPhone2Mac.sh index 5ef17c0..4070cc6 100755 --- a/iPhone2Mac.sh +++ b/iPhone2Mac.sh @@ -1,7 +1,7 @@ #!/bin/bash # # iPhone2Mac -- save call logs from iPhone backups -# Copyright (c)2009 Alexander Barton (alex@barton.de). +# 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 @@ -13,8 +13,7 @@ DEBUG= VERBOSE=1 -backup_d="" -call_db="" +umask 0077 [ -n "$DEBUG" ] && VERBOSE=1 @@ -33,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 @@ -43,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."