menu: added new Keywords tag to .desktop files
[barry.git] / contrib / perlbarry / barrybkup
blobd61f9c24c75aa80c630f09d84fcfa5bd1e7b539f
1 #!/usr/bin/perl
3 # barrybkup version 0.1
5 # Copyright (C) 2008, ashley willis <barry@venamous.net>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 # or FITNESS FOR A PARTICULAR PURPOSE.
16 # See the GNU General Public License in the COPYING file at the
17 # root directory of this project for more details.
19 # backs up each DB in phone, or each DB given on command line,
20 # to file ~/.barry/backup/<PIN>/<PIN>-<DATE>-<TIME>.tar.gz
21 # (identical output as the barrybackup GUI).
23 `bcharge`; # inits phone
25 if (@ARGV) {
26 @list = @ARGV;
27 $arg = 1;
29 else {
30 @list = `btool -t`; # gets list of databases
32 $i = 0;
33 #print "@list\n";
35 @pin = `btool`;
36 chomp $pin[2];
37 $pin[2] =~ s/^Using device \(PIN\): //;
38 $pin = $pin[2];
40 $tmpdir = "$0-$$";
41 $tmpdir =~ s/^.*\//\/tmp\//;
42 print "$tmpdir\n";
43 mkdir($tmpdir);
45 foreach (@list) {
46 if ($arg) {
47 $found = 1;
48 $db[$i] = $_;
50 elsif (s/ Database: 0x[\da-f][\da-f]? '//) {
51 $found = 1;
52 ($db[$i], $records[$i]) = split(/' \(records: /);
53 $records[$i] =~ s/\)$//;
55 else {
56 $found = 0;
58 if ($found) {
59 print "### $i $db[$i] ###\n";
60 $hex = `btool -n -d "$db[$i]"`;
61 #print "### CONVERTING ###\n";
62 convert($hex);
63 #print "### DONE ###\n";
64 $i++;
68 print "count=$i\n";
69 $date = `date +%Y%m%d-%H%M%S`;
70 chomp $date;
71 $tgz = "$pin-$date.tar.gz"; # use PIN instead of "bb-"
72 print "$tgz\n";
73 #`tar zcf $tgz -C $tmpdir $dirs`;
74 #$pwd = `pwd`;
75 #chomp $pwd;
76 `cd $tmpdir; tar zc $dirs > ~/.barry/backup/$pin/$tgz`;
77 #`cd $tmpdir; tar zc $dirs > $pwd/$tgz; cd -`;
78 `rm -rf $tmpdir`;
80 sub convert() {
81 $file = $db[$i];
82 mkdir("$tmpdir/$file");
83 $dirs .= "\"$file/\"* ";
84 $record = -1;
85 $data = $_[0];
86 @hex = split(/\n/, $data);
87 my @out;
88 foreach (@hex) {
89 if (s/^Raw record dump for record: //) {
90 #($record) and close (OUT);
91 $record++;
92 #open(OUT, ">$file/$record");
94 if (/^ 0/) {
95 s/^ 0[\da-f]{7}: //;
96 s/ .*$//;
97 s/ //g;
98 $out[$record] .= pack("H*", $_);
99 #print OUT $out;
102 foreach $record (@out) {
103 $nl = $/;
104 $/ = undef;
105 $record =~ s/(^[\0-ΓΏ]{15})//;
106 $header = $1;
107 $/ = $nl;
108 @header = split(//, $header);
109 #$recType = $header[0] . $header[1];
110 #$length = $header[2] . $header[3];
111 #$u1 = $header[4] . $header[5] . $header[6];
112 $dbVersion = $header[7];
113 #$dbRecordHandler = $header[8] . $header[9];
114 $recordID = $header[10] . $header[11] . $header[12] . $header[13];
115 #$u2 = $header[14];
116 #print "$recType\t$length\t$u1\t$dbVersion\t$dbRecordHandler\t$recordID\t$u2\n";
117 $recordIDTXT = reverse(unpack ("h*", $recordID));
118 $recordIDTXT =~ s/^0+//;
119 ($recordIDTXT) or $recordIDTXT = "0";
120 $dbVersionTXT = unpack ("H*", reverse($dbVersion));
121 $dbVersionTXT =~ s/^0+//;
122 ($dbVersionTXT) or $dbVersionTXT = "0";
123 open(OUT, ">$tmpdir/$file/$recordIDTXT $dbVersionTXT");
124 #print OUT $header;
125 print OUT $record;
126 close OUT;
128 #close(OUT);