-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfetch-contacts
executable file
·56 lines (46 loc) · 1.06 KB
/
fetch-contacts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/perl
use strict;
use warnings;
my $destDir = "$ENV{HOME}/Code/n9/backup/backup-contacts";
my $srcDir = "/home/user/MyDocs/backup-contacts";
my $repo = "$destDir/repo";
sub getLatestVcf();
sub run(@);
sub maybeRun(@);
sub main(@){
die "Usage: $0\n" if @_ != 0;
my $host = `n9`;
chomp $host;
run "n9", "-s", "backup-contacts";
run "mkdir", "-p", $destDir;
run "rsync", "-avP", "root\@$host:$srcDir/", $destDir;
updateRepo();
}
sub updateRepo(){
my $latest = getLatestVcf();
my $file = "contacts.vcf";
if(defined $latest){
run "mkdir", "-p", $repo;
chdir $repo;
run "cp", $latest, $file;
run "git", "init", if not -d ".git";
run "git", "add", $file;
run "git", "--no-pager", "diff", "--cached";
maybeRun "git commit -m 'automatic commit'";
}
}
sub getLatestVcf(){
my $latest = `ls -t "$destDir"/*.vcf | head -1`;
chomp $latest;
return $latest if $latest ne "" and -e $latest;
}
sub run(@){
print "@_\n";
system @_;
die "FAILED: @_\n" if $? != 0;
}
sub maybeRun(@){
print "@_\n";
system @_;
}
&main(@ARGV);