forked from carlosfrodriguez/module-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlink.pl
More file actions
executable file
·146 lines (122 loc) · 4.39 KB
/
Copy pathlink.pl
File metadata and controls
executable file
·146 lines (122 loc) · 4.39 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/perl
# --
# module-tools/link.pl
# - script for linking OTRS modules into framework root
# Copyright (C) 2001-2012 OTRS AG, http://otrs.org/
# --
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU AFFERO General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
# or see http://www.gnu.org/licenses/agpl.txt.
# --
=head1 NAME
link.pl - script for linking OTRS modules into framework root
=head1 SYNOPSIS
link.pl -h
link.pl <source-module-folder> <otrs-folder>
=head1 DESCRIPTION
This script installs a given OTRS module into the OTRS framework by creating
appropriate links.
Beware that code from the .sopm file is not executed.
Existing files are backupped by adding the extension '.old'.
So this script can be used for an already installed module, when linking
files from CVS checkout directory.
Please send any questions, suggestions & complaints to <ot@otrs.com>
=head1 TODO
When running the scripts twice, the '.old' files might be overwritten.
=cut
use strict;
use warnings;
use Getopt::Long;
use Pod::Usage;
use File::Spec ();
# get options
my ($OptHelp);
GetOptions( 'h' => \$OptHelp ) || pod2usage( -verbose => 1, message => 'invalid params' );
if ($OptHelp) {
pod2usage( -verbose => 0 ); # this will exit the script
}
# Now get the work done
my $Source = shift || die "Need Application CVS location as ARG0";
$Source = File::Spec->rel2abs($Source);
if ( !-d $Source ) {
die "ERROR: invalid Application CVS directory '$Source'";
}
my $Dest = shift || die "Need Framework-Root location as ARG1";
$Dest = File::Spec->rel2abs($Dest);
if ( !-d $Dest ) {
die "ERROR: invalid Framework-Root directory '$Dest'";
}
my @Dirs;
my $Start = $Source;
R($Start);
sub R {
my $In = shift;
my @List = glob("$In/*");
foreach my $File (@List) {
$File =~ s/\/\//\//g;
# recurse into subdirectories
if ( -d $File ) {
# skip CVS directories
if ( $File !~ /\/CVS$/ ) {
R($File);
}
}
else {
my $OrigFile = $File;
$File =~ s/$Start//;
# check directory of location (in case create a directory)
if ( "$Dest/$File" =~ /^(.*)\/(.+?|)$/ )
{
my $Directory = $1;
my @Directories = split( /\//, $Directory );
my $DirectoryCurrent = '';
foreach my $Directory (@Directories) {
$DirectoryCurrent .= "/$Directory";
if ( $DirectoryCurrent && !-d $DirectoryCurrent ) {
if ( mkdir $DirectoryCurrent ) {
print STDERR "NOTICE: Create Directory $DirectoryCurrent\n";
}
else {
die "ERROR: can't create directory $DirectoryCurrent: $!";
}
}
}
}
if ( -l "$Dest/$File" ) {
unlink("$Dest/$File") || die "ERROR: Can't unlink symlink: $Dest/$File";
}
if ( -e "$Dest/$File" ) {
if ( rename( "$Dest/$File", "$Dest/$File.old" ) ) {
print "NOTICE: Backup orig file: $Dest/$File.old\n";
}
else {
die "ERROR: Can't rename $Dest/$File to $Dest/$File.old: $!";
}
}
if ( !-e $Dest ) {
die "ERROR: No such directory: $Dest";
}
elsif ( !-e $OrigFile ) {
die "ERROR: No such orig file: $OrigFile";
}
elsif ( !symlink( $OrigFile, "$Dest/$File" ) ) {
die "ERROR: Can't $File link: $!";
}
else {
print "NOTICE: Link: $OrigFile -> \n";
print "NOTICE: $Dest/$File\n";
}
}
}
}