-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsync-klomp-books
executable file
·51 lines (44 loc) · 1.28 KB
/
sync-klomp-books
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
#!/usr/bin/perl
use strict;
use warnings;
system "klomp-playlist main";
system "n9u", "-s", "klomp-playlist main";
sub modS($$){
my $file = shift;
my $remote = shift;
my $cmd = "stat -c %Y $file";
my $fs;
if($remote eq 'remote'){
$fs = `n9u -b "$cmd"`;
}elsif($remote eq 'local'){
$fs = `$cmd`;
}
if($fs =~ /^(\d+)/){
return $1;
}else{
return 0;
}
}
my $dir = "~/.klomp/list-books";
my $localCur = modS "$dir/cur", "local";
my $remoteCur = modS "$dir/cur", "remote";
my $localList = modS "$dir/list", "local";
my $remoteList = modS "$dir/list", "remote";
print " cur list\n";
print "loc: " . localtime($localCur) . " " . localtime($localList) . "\n";
print "rem: " . localtime($remoteCur) . " " . localtime($remoteList) . "\n";
system "mkdir -p $dir";
system "n9u", "-b", "mkdir -p $dir";
if($localCur < $remoteCur and $localList <= $remoteList){
print "remote => local\n";
system "rsync -avP user@`n9`:$dir/ $dir";
print "books on local\n";
system "klomp-playlist", "books";
}elsif($localCur > $remoteCur and $localList >= $remoteList){
print "local => remote\n";
system "rsync -avP $dir/ user@`n9`:$dir";
print "books on remote\n";
system "n9u", "-s", "klomp-playlist", "books";
}else{
print "not updating\n";
}