/usr/share/doc/syncevolution/examples/update-samples.pl is in syncevolution 1.2.2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | #! /usr/bin/env perl
sub basename {
$_ = shift;
s;.*/;;;
return $_;
}
# Concatenate all files ending in .xml in the given directory
# plus those in a specific subdirectory for client or server.
# Order lexicographic ascending of the base filename.
sub readfragments {
my $dir = shift;
my $subdir = shift;
my @res = ();
my @files = ();
if (opendir(my $dh, $dir)) {
foreach (grep (/.*\.xml$/, readdir($dh))) {
push @files, "$dir/$_";
}
closedir($dh);
if (opendir(my $dh, "$dir/$subdir")) {
foreach (grep (/.*\.xml$/, readdir($dh))) {
push @files, "$dir/$subdir/$_";
}
closedir($dh);
}
}
@files = sort { basename($a) <=> basename($b) } @files;
foreach (@files) {
open(IN, "<$_") || die "cannot read $_: $!";
push @res, <IN>;
close(IN);
}
return join("", @res);
}
# replace content of <debug>, <scripting>, <datatypes> and all <remoterule>s
# with the corresponding shared and/or client/server .xml fragments
sub update {
my $file = shift;
my $subdir = shift;
my $write = shift;
open(IN, "<$file") || die "cannot read $file: $!";
$_ = join("", <IN>);
close(IN) || die "closing $file: $!";
s;(<debug>\n).*(\n *</debug>);$1 . readfragments("debug", $subdir) . $2;se;
s;(<scripting>\n).*(\n *</scripting>);$1 . readfragments("scripting", $subdir) . $2;se ||
s;(\n *)<scripting/>;$1 . "<scripting>\n" . readfragments("scripting", $subdir) . $1 . "</scripting>";se;
s;(<datatypes>\n).*(\n *</datatypes>);$1 . readfragments("datatypes", $subdir) . $2;se ||
s;(\n *)<datatypes/>;$1 . "<datatypes>\n" . readfragments("datatypes", $subdir) . $1 . "</datatypes>";se;
s;(\n *)<remoterule>.*</remoterule>;$1 . readfragments("remoterules", $subdir);se ||
s;(\n *)<remoterules/>;readfragments("remoterules", $subdir);se;
if ($write) {
open(OUT, ">$file") || die "cannot write $file: $!";
print OUT;
close(OUT) || die "closing $file: $!";
} else {
print;
}
}
if ($#ARGV == -1) {
update("syncclient_sample_config.xml", "client", 1);
update("syncserv_sample_config.xml", "server", 1);
} else {
update($ARGV[0], $ARGV[1], 0);
}
|