File: sync.pl

package info (click to toggle)
libnet-async-matrix-perl 0.19-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 264 kB
  • sloc: perl: 2,595; makefile: 2
file content (58 lines) | stat: -rw-r--r-- 1,095 bytes parent folder | download | duplicates (2)
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;

use IO::Async::Loop;
use Net::Async::Matrix;
use Net::Netrc;

use Getopt::Long;

GetOptions(
   'server=s' => \my $SERVER,
   'SSL'      => \my $SSL,
   'user=s'   => \my $USER,
   'pass=s'   => \my $PASS,

   'since=s'  => \my $SINCE,
) or exit 1;

die "Require --server\n" unless defined $SERVER;

if( !defined $PASS ) {
   my $ent = Net::Netrc->lookup( $SERVER, $USER ) or
      die "No --pass given and not found in .netrc\n";

   $USER //= $ent->login;
   $PASS //= $ent->password;
}

my $loop = IO::Async::Loop->new;

my $matrix = Net::Async::Matrix->new(
   server          => $SERVER,
   SSL             => $SSL,
   SSL_verify_mode => 0,
);
$loop->add( $matrix );

print STDERR "Logging in to $SERVER as $USER...\n";

$matrix->login(
   user_id  => $USER,
   password => $PASS,

   _no_start => 1,
)->get;

print STDERR "Requesting sync...\n";

use JSON::MaybeXS;
STDOUT->binmode( ":encoding(UTF-8)" );

print JSON::MaybeXS->new( pretty => 1 )->encode(
   scalar $matrix->sync(
      ( defined $SINCE ? ( since => $SINCE ) : () )
   )->get
);