diff options
author | Andinus <andinus@nand.sh> | 2020-07-03 17:24:58 +0530 |
---|---|---|
committer | Andinus <andinus@nand.sh> | 2020-07-03 17:24:58 +0530 |
commit | 33de99a28ddc24e1bf6c694dff0a5fed06427e3e (patch) | |
tree | c8d3dfeea08bb7e8ba2da4b985c9eeddb280c209 | |
parent | ad6253ced70f17796634660199167a1f89a734e7 (diff) | |
download | leo-33de99a28ddc24e1bf6c694dff0a5fed06427e3e.tar.gz |
Sync irclogs, seperate sync options
By default it syncs only the config now & the user has to mention `irclogs' or `authinfo' to sync them.
-rwxr-xr-x | leo.pl | 4 | ||||
-rw-r--r-- | lib/Emacs.pm | 76 |
2 files changed, 51 insertions, 29 deletions
diff --git a/leo.pl b/leo.pl index 462d2bf..0a3e540 100755 --- a/leo.pl +++ b/leo.pl @@ -22,7 +22,9 @@ GetOptions( ) or die "Error in command line arguments\n"; my %dispatch = ( - "sync emacs" => sub { Emacs::sync(\%options) }, + "sync emacs" => sub { $options{config} = 1; Emacs::sync(\%options); }, + "sync emacs irclogs" => sub { $options{irclogs} = 1; Emacs::sync(\%options); }, + "sync emacs authinfo" => sub { $options{authinfo} = 1; Emacs::sync(\%options); }, ); if ( $dispatch{ "@ARGV" } ) { diff --git a/lib/Emacs.pm b/lib/Emacs.pm index e15a664..dc409a3 100644 --- a/lib/Emacs.pm +++ b/lib/Emacs.pm @@ -14,39 +14,44 @@ use Term::ANSIColor qw/ :pushpop colored color /; sub sync { my ( $options ) = @_; my $verbose = $options->{verbose}; - my $authinfo_remote = "$ENV{HOME}/.authinfo-remote"; - my %path_perms = ( - $authinfo_remote => 0700, - "$authinfo_remote/team" => 0600, - "$authinfo_remote/inst" => 0600, - "$authinfo_remote/town" => 0600, - ); - - # Check path permissions. - say LOCALCOLOR CYAN "Checking path permissions..."; - foreach my $path ( sort keys %path_perms ) { - my $mode = S_IMODE(path($path)->stat->mode); - - if ( $mode == $path_perms{$path} ) { - say LOCALCOLOR GREEN "[OK] $path" - if $verbose; - } else { - warn "[ERR] $path - Expected: $path_perms{$path} :: Got: $mode - Changing permission...\n"; - - path("$path")->chmod($path_perms{$path}); - } - } - say LOCALCOLOR CYAN "[DONE] Permissions checked"; sub rsync { run3 ["openrsync", @_]; } - my @def_opt = qw{ --delete -oprt }; + my @def_opt = qw{ --delete -oprtl }; push @def_opt, "-v" if $verbose; - { + # Remove --delete. + my @no_del_opt = @def_opt; + shift @no_del_opt; + + if ($options->{authinfo}) { + my $authinfo_remote = "$ENV{HOME}/.authinfo-remote"; + my %path_perms = ( + $authinfo_remote => 0700, + "$authinfo_remote/team" => 0600, + "$authinfo_remote/inst" => 0600, + "$authinfo_remote/town" => 0600, + ); + + # Check path permissions. + say LOCALCOLOR CYAN "Checking path permissions..."; + foreach my $path ( sort keys %path_perms ) { + my $mode = S_IMODE(path($path)->stat->mode); + + if ( $mode == $path_perms{$path} ) { + say LOCALCOLOR GREEN "[OK] $path" + if $verbose; + } else { + warn "[ERR] $path + Expected: $path_perms{$path} :: Got: $mode + Changing permission...\n"; + + path("$path")->chmod($path_perms{$path}); + } + } + say LOCALCOLOR CYAN "[DONE] Permissions checked"; + say LOCALCOLOR CYAN "Syncing authinfo..."; my %authinfo_hosts = ( "tilde.team" => "$authinfo_remote/team", @@ -60,7 +65,7 @@ sub sync { say LOCALCOLOR CYAN "[DONE] authinfo sync"; } - { + if ($options->{config}) { say LOCALCOLOR CYAN "Syncing emacs config..."; my @hosts = qw{ tilde.team tilde.institute envs.net tilde.town }; @@ -80,6 +85,21 @@ sub sync { } say LOCALCOLOR CYAN "[Done] Emacs config sync"; } + + if ( $options->{irclogs} ) { + say LOCALCOLOR CYAN "Syncing irclogs..."; + my @hosts = qw{ tilde.team tilde.institute envs.net tilde.town }; + + my $e_conf = "$ENV{HOME}/.emacs.d"; + foreach my $host (@hosts) { + say LOCALCOLOR MAGENTA "$host"; + rsync( @no_del_opt, "andinus\@$host:~/.emacs.d/irclogs/", + "$e_conf/irclogs/$host/"); + } + + say LOCALCOLOR CYAN "[DONE] irclogs sync"; + } + } 1; |