summaryrefslogtreecommitdiffstats
path: root/move/etc-monitorer.pl
blob: b0bb903620e877d5ece341998f1efd5fbaaa5713 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/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 (chomp_(`find $ARGV[0] -type f -maxdepth 1`)) {
    next if $_ eq '/etc/sudoers';  #- /etc/sudoers can't be a link
    if (-f && !-l) {
        my $dest = "/home/.sysconf/$machine_ident$_";
        mkdir_p(dirname($dest));  #- case of newly created directories
        logit("restoring broken symlink $_ -> $dest");
        system("mv $_ $dest");
        symlink($dest, $_);
    }
}