forked from OTRS/module-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremove_links.pl
executable file
·50 lines (41 loc) · 1.14 KB
/
remove_links.pl
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
#!/usr/bin/perl
use strict;
my $Dest = shift || die "Need Application-Root location as ARG1";
if ( !-d $Dest ) {
die "ERROR: invalid Application-Root directory '$Dest'";
}
if ( !( -e $Dest . '/Kernel' && -e $Dest . '/Kernel/System' ) ) {
print <<"WARNING";
Can't find $Dest/Kernel and $Dest/Kernel/System, so I assume it's not a
root directory of an OTRS instance. Remove links anyway? [y/N]
WARNING
chomp( my $Answer = <STDIN> );
if ( $Answer !~ m{ ^ y $ }xi ) {
exit;
}
}
my @Dirs = ();
my $Start = $Dest;
R($Start);
sub R {
my $In = shift;
my @List = glob("$In/*");
foreach my $File (@List) {
$File =~ s/\/\//\//g;
if ( -d $File ) {
R($File);
}
else {
my $OrigFile = $File;
$File =~ s/$Start//;
if ( -l $OrigFile ) {
print "Unlink Symlink: $File\n";
unlink $OrigFile || die $!;
if ( -f "$OrigFile.old" ) {
print "Restore orginal copy: $File\n";
rename( "$OrigFile.old", $OrigFile ) || die $!;
}
}
}
}
}