1*cdf0e10cSrcweirpackage filehelper;
2*cdf0e10cSrcweir
3*cdf0e10cSrcweir#*************************************************************************
4*cdf0e10cSrcweir#
5*cdf0e10cSrcweir# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6*cdf0e10cSrcweir#
7*cdf0e10cSrcweir# Copyright 2000, 2010 Oracle and/or its affiliates.
8*cdf0e10cSrcweir#
9*cdf0e10cSrcweir# OpenOffice.org - a multi-platform office productivity suite
10*cdf0e10cSrcweir#
11*cdf0e10cSrcweir# This file is part of OpenOffice.org.
12*cdf0e10cSrcweir#
13*cdf0e10cSrcweir# OpenOffice.org is free software: you can redistribute it and/or modify
14*cdf0e10cSrcweir# it under the terms of the GNU Lesser General Public License version 3
15*cdf0e10cSrcweir# only, as published by the Free Software Foundation.
16*cdf0e10cSrcweir#
17*cdf0e10cSrcweir# OpenOffice.org is distributed in the hope that it will be useful,
18*cdf0e10cSrcweir# but WITHOUT ANY WARRANTY; without even the implied warranty of
19*cdf0e10cSrcweir# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20*cdf0e10cSrcweir# GNU Lesser General Public License version 3 for more details
21*cdf0e10cSrcweir# (a copy is included in the LICENSE file that accompanied this code).
22*cdf0e10cSrcweir#
23*cdf0e10cSrcweir# You should have received a copy of the GNU Lesser General Public License
24*cdf0e10cSrcweir# version 3 along with OpenOffice.org.  If not, see
25*cdf0e10cSrcweir# <http://www.openoffice.org/license.html>
26*cdf0e10cSrcweir# for a copy of the LGPLv3 License.
27*cdf0e10cSrcweir#
28*cdf0e10cSrcweir#*************************************************************************
29*cdf0e10cSrcweir
30*cdf0e10cSrcweiruse strict;
31*cdf0e10cSrcweiruse warnings;
32*cdf0e10cSrcweiruse strict;
33*cdf0e10cSrcweiruse English;                  # $OSNAME, ...
34*cdf0e10cSrcweiruse stringhelper;
35*cdf0e10cSrcweir
36*cdf0e10cSrcweirBEGIN {
37*cdf0e10cSrcweir    use Exporter   ();
38*cdf0e10cSrcweir    our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
39*cdf0e10cSrcweir
40*cdf0e10cSrcweir    $VERSION     = 1.00;
41*cdf0e10cSrcweir    # if using RCS/CVS, this may be preferred
42*cdf0e10cSrcweir    $VERSION = do { my @r = (q$Revision: 1.1 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; # must be all one line, for MakeMaker
43*cdf0e10cSrcweir    @ISA         = qw(Exporter);
44*cdf0e10cSrcweir    @EXPORT      = qw(&dospath &unixpath &appendPath &appendClass &setPrefix &getToolsPrefix &rmkdir &getJavaPathSeparator &getJavaFileDirSeparator &getFromPathes &convertCygwinPath);
45*cdf0e10cSrcweir    %EXPORT_TAGS = ( );     # eg: TAG => [ qw!name1 name2! ],
46*cdf0e10cSrcweir    # your exported package globals go here,
47*cdf0e10cSrcweir    # as well as any optionally exported functions
48*cdf0e10cSrcweir    @EXPORT_OK   = ( ); # qw($Var1 %Hashit &func3);
49*cdf0e10cSrcweir}
50*cdf0e10cSrcweir
51*cdf0e10cSrcweir
52*cdf0e10cSrcweir# ------------------------------------------------------------------------------
53*cdf0e10cSrcweir# helper, to change all file separators
54*cdf0e10cSrcweirsub dospath($)
55*cdf0e10cSrcweir{
56*cdf0e10cSrcweir    my $sPath = shift;
57*cdf0e10cSrcweir    if ($OSNAME eq "MSWin32")
58*cdf0e10cSrcweir    {
59*cdf0e10cSrcweir        # make out of '/' a '\'
60*cdf0e10cSrcweir        $sPath =~ s/\//\\/g;
61*cdf0e10cSrcweir    }
62*cdf0e10cSrcweir    else
63*cdf0e10cSrcweir    {
64*cdf0e10cSrcweir    }
65*cdf0e10cSrcweir    return $sPath;
66*cdf0e10cSrcweir}
67*cdf0e10cSrcweir
68*cdf0e10cSrcweirsub unixpath($)
69*cdf0e10cSrcweir{
70*cdf0e10cSrcweir    my $sPath = shift;
71*cdf0e10cSrcweir    if ($OSNAME ne "MSWin32")
72*cdf0e10cSrcweir    {
73*cdf0e10cSrcweir        # make out of '\' a '/'
74*cdf0e10cSrcweir        $sPath =~ s/\\/\//g;
75*cdf0e10cSrcweir    }
76*cdf0e10cSrcweir    else
77*cdf0e10cSrcweir    {
78*cdf0e10cSrcweir    }
79*cdf0e10cSrcweir    return $sPath;
80*cdf0e10cSrcweir}
81*cdf0e10cSrcweir
82*cdf0e10cSrcweir# ------------------------------------------------------------------------------
83*cdf0e10cSrcweir# sub getGlobalInstSet()
84*cdf0e10cSrcweir# {
85*cdf0e10cSrcweir#     my $sJumbo;
86*cdf0e10cSrcweir#     if ($OSNAME eq "MSWin32")
87*cdf0e10cSrcweir#     {
88*cdf0e10cSrcweir#         # $sJumbo = "\\\\so-gfxcmp-lin\\jumbo_ship\\install";
89*cdf0e10cSrcweir#         $sJumbo = "\\\\jumbo.germany.sun.com\\ship\\install";
90*cdf0e10cSrcweir#     }
91*cdf0e10cSrcweir#     elsif ($OSNAME eq "cygwin")
92*cdf0e10cSrcweir#     {
93*cdf0e10cSrcweir#         $sJumbo = "//jumbo.germany.sun.com/ship/install";
94*cdf0e10cSrcweir#     }
95*cdf0e10cSrcweir#     else
96*cdf0e10cSrcweir#     {
97*cdf0e10cSrcweir#         $sJumbo = "/net/jumbo.germany.sun.com/ship/install";
98*cdf0e10cSrcweir#     }
99*cdf0e10cSrcweir#     return $sJumbo;
100*cdf0e10cSrcweir# }
101*cdf0e10cSrcweir
102*cdf0e10cSrcweir# ------------------------------------------------------------------------------
103*cdf0e10cSrcweir# sub getSolarisLockFile()
104*cdf0e10cSrcweir# {
105*cdf0e10cSrcweir#     my $sSolarisLockFile = "/tmp/.ai.pkg.zone.lock-afdb66cf-1dd1-11b2-a049-000d560ddc3e";
106*cdf0e10cSrcweir#     return $sSolarisLockFile;
107*cdf0e10cSrcweir# }
108*cdf0e10cSrcweir#
109*cdf0e10cSrcweir# sub checkForSolarisLock()
110*cdf0e10cSrcweir# {
111*cdf0e10cSrcweir#     if ($OSNAME eq "solaris")
112*cdf0e10cSrcweir#     {
113*cdf0e10cSrcweir#         # wait until the internal installer lock is gone
114*cdf0e10cSrcweir#         while ( -e getSolarisLockFile() )
115*cdf0e10cSrcweir#         {
116*cdf0e10cSrcweir#             while ( -e getSolarisLockFile() )
117*cdf0e10cSrcweir#             {
118*cdf0e10cSrcweir#                 log_print( "Warning: Wait active until installer lock is gone. \n");
119*cdf0e10cSrcweir#                 sleep 1;
120*cdf0e10cSrcweir#             }
121*cdf0e10cSrcweir#             sleep 5;
122*cdf0e10cSrcweir#         }
123*cdf0e10cSrcweir#         log_print( "[ok], lock is gone.\n");
124*cdf0e10cSrcweir#     }
125*cdf0e10cSrcweir# }
126*cdf0e10cSrcweir#
127*cdf0e10cSrcweir# sub deleteSolarisLock()
128*cdf0e10cSrcweir# {
129*cdf0e10cSrcweir#     if ($OSNAME eq "solaris")
130*cdf0e10cSrcweir#     {
131*cdf0e10cSrcweir#         sleep 1;
132*cdf0e10cSrcweir#         unlink getSolarisLockFile();
133*cdf0e10cSrcweir#
134*cdf0e10cSrcweir#         sleep 1;
135*cdf0e10cSrcweir#         if ( -e getSolarisLockFile() )
136*cdf0e10cSrcweir#         {
137*cdf0e10cSrcweir#             # try delete the file as super user?
138*cdf0e10cSrcweir#             `sudo rm -f getSolarisLockFile()`;
139*cdf0e10cSrcweir#             sleep 1;
140*cdf0e10cSrcweir#         }
141*cdf0e10cSrcweir#     }
142*cdf0e10cSrcweir# }
143*cdf0e10cSrcweir
144*cdf0e10cSrcweir# ------------------------------------------------------------------------------
145*cdf0e10cSrcweirsub appendPath($$)
146*cdf0e10cSrcweir{
147*cdf0e10cSrcweir    my $sPath = shift;
148*cdf0e10cSrcweir    my $sAddPath = shift;
149*cdf0e10cSrcweir    if ($sPath && $sAddPath)
150*cdf0e10cSrcweir    {
151*cdf0e10cSrcweir        if (! endswith($sPath, "/") &&
152*cdf0e10cSrcweir            ! endswith($sPath, "\\"))
153*cdf0e10cSrcweir        {
154*cdf0e10cSrcweir            # getJavaFileDirSeparator();
155*cdf0e10cSrcweir            $sPath .= "/";
156*cdf0e10cSrcweir        }
157*cdf0e10cSrcweir        $sPath .= $sAddPath;
158*cdf0e10cSrcweir    }
159*cdf0e10cSrcweir    return $sPath;
160*cdf0e10cSrcweir}
161*cdf0e10cSrcweir
162*cdf0e10cSrcweirsub appendClass($$)
163*cdf0e10cSrcweir{
164*cdf0e10cSrcweir    my $sPath = shift;
165*cdf0e10cSrcweir    my $sAddPath = shift;
166*cdf0e10cSrcweir
167*cdf0e10cSrcweir    my $sSeparator = getJavaPathSeparator();
168*cdf0e10cSrcweir    if ($sPath && $sAddPath)
169*cdf0e10cSrcweir    {
170*cdf0e10cSrcweir        if (! endswith($sPath, $sSeparator))
171*cdf0e10cSrcweir        {
172*cdf0e10cSrcweir            # getJavaFileDirSeparator();
173*cdf0e10cSrcweir            $sPath .= $sSeparator;
174*cdf0e10cSrcweir        }
175*cdf0e10cSrcweir        $sPath .= $sAddPath;
176*cdf0e10cSrcweir    }
177*cdf0e10cSrcweir    return $sPath;
178*cdf0e10cSrcweir}
179*cdf0e10cSrcweir
180*cdf0e10cSrcweir# ------------------------------------------------------------------------------
181*cdf0e10cSrcweir
182*cdf0e10cSrcweirour $sPrefix;
183*cdf0e10cSrcweirsub setPrefix($)
184*cdf0e10cSrcweir{
185*cdf0e10cSrcweir    $sPrefix = shift;
186*cdf0e10cSrcweir}
187*cdf0e10cSrcweir
188*cdf0e10cSrcweirsub getPrefix()
189*cdf0e10cSrcweir{
190*cdf0e10cSrcweir    return $sPrefix;
191*cdf0e10cSrcweir}
192*cdf0e10cSrcweir
193*cdf0e10cSrcweir# ------------------------------------------------------------------------------
194*cdf0e10cSrcweirour $programprefix;
195*cdf0e10cSrcweir
196*cdf0e10cSrcweir# sub getProgramPrefix($)
197*cdf0e10cSrcweir# {
198*cdf0e10cSrcweir#     my $sDBDistinct = shift;
199*cdf0e10cSrcweir#
200*cdf0e10cSrcweir#     my $sProgramPrefix;
201*cdf0e10cSrcweir#     if (! $programprefix)
202*cdf0e10cSrcweir#     {
203*cdf0e10cSrcweir#         if ($OSNAME eq "MSWin32")
204*cdf0e10cSrcweir#         {
205*cdf0e10cSrcweir#             # $programprefix = "C:/gfxcmp/programs";
206*cdf0e10cSrcweir#             $programprefix = "C:";
207*cdf0e10cSrcweir#             if (getPrefix() eq "performance")
208*cdf0e10cSrcweir#             {
209*cdf0e10cSrcweir#                 $programprefix = "D:";
210*cdf0e10cSrcweir#             }
211*cdf0e10cSrcweir#             $programprefix = appendPath($programprefix, "gp");
212*cdf0e10cSrcweir#         }
213*cdf0e10cSrcweir#         elsif ($OSNAME eq "linux")
214*cdf0e10cSrcweir#         {
215*cdf0e10cSrcweir#             $programprefix = "/space/" . getPrefix() . "/programs";
216*cdf0e10cSrcweir#         }
217*cdf0e10cSrcweir#         elsif ($OSNAME eq "solaris")
218*cdf0e10cSrcweir#         {
219*cdf0e10cSrcweir#             $programprefix = "/space/" . getPrefix() . "/programs";
220*cdf0e10cSrcweir#         }
221*cdf0e10cSrcweir#         else
222*cdf0e10cSrcweir#         {
223*cdf0e10cSrcweir#             print "Error: This environment isn't supported yet.\n";
224*cdf0e10cSrcweir#             exit(1);
225*cdf0e10cSrcweir#         }
226*cdf0e10cSrcweir#     }
227*cdf0e10cSrcweir#     $sProgramPrefix = appendPath($programprefix, substr($sDBDistinct, 0, 19));
228*cdf0e10cSrcweir#     return $sProgramPrefix;
229*cdf0e10cSrcweir# }
230*cdf0e10cSrcweir# ------------------------------------------------------------------------------
231*cdf0e10cSrcweirour $toolsprefix;
232*cdf0e10cSrcweir
233*cdf0e10cSrcweirsub getToolsPrefix()
234*cdf0e10cSrcweir{
235*cdf0e10cSrcweir    my $sToolsPrefix;
236*cdf0e10cSrcweir    if (! $toolsprefix)
237*cdf0e10cSrcweir    {
238*cdf0e10cSrcweir        if ($OSNAME eq "MSWin32")
239*cdf0e10cSrcweir        {
240*cdf0e10cSrcweir            $toolsprefix = "C:";
241*cdf0e10cSrcweir            if (getPrefix() eq "performance")
242*cdf0e10cSrcweir            {
243*cdf0e10cSrcweir                $toolsprefix = "D:";
244*cdf0e10cSrcweir            }
245*cdf0e10cSrcweir        }
246*cdf0e10cSrcweir        elsif ($OSNAME eq "linux")
247*cdf0e10cSrcweir        {
248*cdf0e10cSrcweir            $toolsprefix = "/space";
249*cdf0e10cSrcweir        }
250*cdf0e10cSrcweir        elsif ($OSNAME eq "solaris")
251*cdf0e10cSrcweir        {
252*cdf0e10cSrcweir            $toolsprefix = "/space";
253*cdf0e10cSrcweir        }
254*cdf0e10cSrcweir        else
255*cdf0e10cSrcweir        {
256*cdf0e10cSrcweir            print "Error: This environment isn't supported yet.\n";
257*cdf0e10cSrcweir            exit(1);
258*cdf0e10cSrcweir        }
259*cdf0e10cSrcweir        $toolsprefix = appendPath($toolsprefix, getPrefix());
260*cdf0e10cSrcweir        $toolsprefix = appendPath($toolsprefix, "tools");
261*cdf0e10cSrcweir    }
262*cdf0e10cSrcweir    $sToolsPrefix = $toolsprefix;
263*cdf0e10cSrcweir    return $sToolsPrefix;
264*cdf0e10cSrcweir}
265*cdf0e10cSrcweir
266*cdf0e10cSrcweir# also Windows safe
267*cdf0e10cSrcweirsub rmkdir($)
268*cdf0e10cSrcweir{
269*cdf0e10cSrcweir    my($tpath) = shift;
270*cdf0e10cSrcweir    my $dir;
271*cdf0e10cSrcweir    my $accum = "";
272*cdf0e10cSrcweir
273*cdf0e10cSrcweir    my @dirs = split(/\//, $tpath);
274*cdf0e10cSrcweir    if ( $#dirs eq 0 )
275*cdf0e10cSrcweir    {
276*cdf0e10cSrcweir        @dirs = split("\\\\", $tpath);
277*cdf0e10cSrcweir    }
278*cdf0e10cSrcweir
279*cdf0e10cSrcweir    foreach $dir (@dirs)
280*cdf0e10cSrcweir    {
281*cdf0e10cSrcweir	$accum = "$accum$dir/";
282*cdf0e10cSrcweir	if($dir ne "")
283*cdf0e10cSrcweir	{
284*cdf0e10cSrcweir	    if(! -d "$accum")
285*cdf0e10cSrcweir	    {
286*cdf0e10cSrcweir		mkdir ($accum);
287*cdf0e10cSrcweir                chmod (0777,$accum);
288*cdf0e10cSrcweir	    }
289*cdf0e10cSrcweir	}
290*cdf0e10cSrcweir    }
291*cdf0e10cSrcweir}
292*cdf0e10cSrcweir
293*cdf0e10cSrcweir# ------------------------------------------------------------------------------
294*cdf0e10cSrcweirsub getJavaPathSeparator()
295*cdf0e10cSrcweir{
296*cdf0e10cSrcweir    my $ps = ":";
297*cdf0e10cSrcweir    if ($OSNAME eq "MSWin32" || $OSNAME eq "cygwin")
298*cdf0e10cSrcweir    {
299*cdf0e10cSrcweir        $ps = ";";
300*cdf0e10cSrcweir    }
301*cdf0e10cSrcweir    return $ps;
302*cdf0e10cSrcweir}
303*cdf0e10cSrcweir# ------------------------------------------------------------------------------
304*cdf0e10cSrcweirsub getJavaFileDirSeparator()
305*cdf0e10cSrcweir{
306*cdf0e10cSrcweir    my $sfs = "/";
307*cdf0e10cSrcweir    if ($OSNAME eq "MSWin32")
308*cdf0e10cSrcweir    {
309*cdf0e10cSrcweir        $sfs = "\\";
310*cdf0e10cSrcweir    }
311*cdf0e10cSrcweir    return $sfs;
312*cdf0e10cSrcweir}
313*cdf0e10cSrcweir# ------------------------------------------------------------------------------
314*cdf0e10cSrcweirsub getFromPathes($$)
315*cdf0e10cSrcweir{
316*cdf0e10cSrcweir    my $sPathesIni = shift;
317*cdf0e10cSrcweir    my $searchvalue = shift;
318*cdf0e10cSrcweir    my $sResult;
319*cdf0e10cSrcweir    if ( -e $sPathesIni)
320*cdf0e10cSrcweir    {
321*cdf0e10cSrcweir        local *PATHES;
322*cdf0e10cSrcweir        if (open(PATHES, "$sPathesIni"))
323*cdf0e10cSrcweir        {
324*cdf0e10cSrcweir            my $line;
325*cdf0e10cSrcweir            while ($line = <PATHES>)
326*cdf0e10cSrcweir            {
327*cdf0e10cSrcweir                chomp($line);
328*cdf0e10cSrcweir                if ($line =~ /^$searchvalue=(.*)$/)
329*cdf0e10cSrcweir                {
330*cdf0e10cSrcweir                    $sResult = $1;
331*cdf0e10cSrcweir                }
332*cdf0e10cSrcweir            }
333*cdf0e10cSrcweir            close(PATHES);
334*cdf0e10cSrcweir        }
335*cdf0e10cSrcweir    }
336*cdf0e10cSrcweir    return $sResult;
337*cdf0e10cSrcweir}
338*cdf0e10cSrcweir
339*cdf0e10cSrcweirsub convertCygwinPath($)
340*cdf0e10cSrcweir{
341*cdf0e10cSrcweir    my $sPath = shift;
342*cdf0e10cSrcweir
343*cdf0e10cSrcweir    if ($OSNAME eq "cygwin")
344*cdf0e10cSrcweir    {
345*cdf0e10cSrcweir        # print "Cygwin Path Patch.\n" if ($verbose);
346*cdf0e10cSrcweir        if ($sPath =~ /\/cygdrive\/(.)/)
347*cdf0e10cSrcweir        {
348*cdf0e10cSrcweir            my $Letter = $1;
349*cdf0e10cSrcweir            $sPath =~ s/\/cygdrive\/${Letter}/${Letter}\:/;
350*cdf0e10cSrcweir            # print "Cygwin Path Patch: '$sPath'\n" if ($verbose);
351*cdf0e10cSrcweir        }
352*cdf0e10cSrcweir    }
353*cdf0e10cSrcweir    return $sPath;
354*cdf0e10cSrcweir}
355*cdf0e10cSrcweir
356*cdf0e10cSrcweir
357*cdf0e10cSrcweir
358*cdf0e10cSrcweir1;
359