blob: ccbbfde006eb74f7bc020e61d848b1f8907d405e (
plain)
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
|
#!/usr/bin/perl
use MDK::Common;
sub outpend { my $f = shift; local *F; open F, ">>$f" or die "outpend in file $f failed: $!\n"; print F foreach @_ }
sub logit { outpend "/var/log/etc-monitorer.log", sprintf("[%s] @_\n", chomp_(`date`)) }
my $machine_ident = cat_('/var/lib/machine_ident');
my $sysconf = "/home/.sysconf/$machine_ident";
foreach my $dir (@ARGV) {
my $destdir = "/home/.sysconf/$machine_ident";
my @etcfiles = glob_("$dir/*");
foreach (@etcfiles) {
if ($_ eq '/etc/sudoers' #- /etc/sudoers can't be a link
|| !-f
|| -l && readlink =~ m|^/|) { #- we want to trap relative symlinks only
next;
}
my $dest = "$destdir$_";
mkdir_p(dirname($dest)); #- case of newly created directories
logit("restoring broken symlink $_ -> $dest");
if (-l) {
system("cp $_ $dest 2>/dev/null");
} else {
system("mv $_ $dest 2>/dev/null");
}
symlinkf($dest, $_);
}
foreach (difference2([ grep { -f && s/^\Q$destdir\E// } glob_("$destdir$dir/*") ], [ @etcfiles ])) {
logit("removing $destdir$_ because of deleted $_");
unlink "$destdir$_";
}
}
|