-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsync-pidgin
executable file
·58 lines (47 loc) · 1.44 KB
/
sync-pidgin
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
57
58
#!/usr/bin/perl
use strict;
use warnings;
my $localPurpleDir = "$ENV{HOME}/.purple";
my $remotePurpleDir = "/home/user/.purple";
my @opts = qw(
-a --no-owner --no-group
-v -P
-z
);
sub run(@);
sub main(@){
die "Usage: $0\n" if @_ != 0;
my $host = `n9`;
chomp $host;
my $rem = "root\@$host:$remotePurpleDir";
my $loc = $localPurpleDir;
my $remoteUserGroup = "user.users";
my $localUserGroup = "$ENV{USER}" . "." . `id -gn $ENV{USER}`;
chomp $localUserGroup;
my $dirOk = `n9 -s 'test -d $remotePurpleDir && echo success || echo failure'`;
chomp $dirOk;
if($dirOk eq "success"){
print "$remotePurpleDir exists, syncing just logs\n";
}elsif($dirOk eq "failure"){
print "!!$remotePurpleDir does NOT exist, syncing all of purple\n";
run "rsync", @opts, "--exclude=logs", "$loc/", $rem;
run "n9", "-s", "mkdir $remotePurpleDir/logs";
run "n9", "-s", "chown -R $remoteUserGroup $remotePurpleDir/";
}else{
die "error detecting $remotePurpleDir\n";
}
print "\n\nlogs REMOTE => LOCAL\n";
run "rsync", @opts, "$rem/logs/", "$loc/logs";
print "\n\nlogs LOCAL => REMOTE\n";
run "rsync", @opts, "$loc/logs/", "$rem/logs";
print "\n\nCHOWN REMOTE\n";
run "ssh", "root\@$host", "chown -R $remoteUserGroup $remotePurpleDir/logs";
print "\n\nCHOWN LOCAL\n";
run "chown", "-R", $localUserGroup, "$localPurpleDir/logs";
}
sub run(@){
print "@_\n";
system @_;
die "failed" if $? != 0;
}
&main(@ARGV);