1*cdf0e10cSrcweir#************************************************************************* 2*cdf0e10cSrcweir# 3*cdf0e10cSrcweir# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir# 5*cdf0e10cSrcweir# Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir# 7*cdf0e10cSrcweir# OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir# 9*cdf0e10cSrcweir# This file is part of OpenOffice.org. 10*cdf0e10cSrcweir# 11*cdf0e10cSrcweir# OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir# it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir# only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir# 15*cdf0e10cSrcweir# OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir# but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir# GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir# (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir# 21*cdf0e10cSrcweir# You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir# version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir# <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir# for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir# 26*cdf0e10cSrcweir#************************************************************************* 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir 29*cdf0e10cSrcweirpackage par2script::systemactions; 30*cdf0e10cSrcweir 31*cdf0e10cSrcweiruse File::Copy; 32*cdf0e10cSrcweiruse par2script::exiter; 33*cdf0e10cSrcweiruse par2script::globals; 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir###################################################### 36*cdf0e10cSrcweir# Creating a new direcotory 37*cdf0e10cSrcweir###################################################### 38*cdf0e10cSrcweir 39*cdf0e10cSrcweirsub create_directory 40*cdf0e10cSrcweir{ 41*cdf0e10cSrcweir my ($directory) = @_; 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir my $returnvalue = 1; 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir if (!(-d $directory)) 46*cdf0e10cSrcweir { 47*cdf0e10cSrcweir $returnvalue = mkdir($directory, 0775); 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir if ($returnvalue) 50*cdf0e10cSrcweir { 51*cdf0e10cSrcweir $infoline = "Created directory: $directory\n"; 52*cdf0e10cSrcweir push(@par2script::globals::logfileinfo, $infoline); 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir if ($par2script::globals::isunix) 55*cdf0e10cSrcweir { 56*cdf0e10cSrcweir my $localcall = "chmod 775 $directory \>\/dev\/null 2\>\&1"; 57*cdf0e10cSrcweir system($localcall); 58*cdf0e10cSrcweir } 59*cdf0e10cSrcweir } 60*cdf0e10cSrcweir else 61*cdf0e10cSrcweir { 62*cdf0e10cSrcweir par2script::exiter::exit_program("Error: Could not create directory: $directory", "create_directory"); 63*cdf0e10cSrcweir } 64*cdf0e10cSrcweir } 65*cdf0e10cSrcweir} 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir####################################################################### 68*cdf0e10cSrcweir# Creating the directories, in which files are generated or unzipped 69*cdf0e10cSrcweir####################################################################### 70*cdf0e10cSrcweir 71*cdf0e10cSrcweirsub create_directories 72*cdf0e10cSrcweir{ 73*cdf0e10cSrcweir my ($directory, $languagesref) =@_; 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir $par2script::globals::unpackpath =~ s/\Q$par2script::globals::separator\E\s*$//; # removing ending slashes and backslashes 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir my $path = $par2script::globals::unpackpath; # this path already exists 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir $path = $path . $par2script::globals::separator . $par2script::globals::build . $par2script::globals::separator; 80*cdf0e10cSrcweir create_directory($path); 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir $path = $path . $par2script::globals::minor . $par2script::globals::separator; 83*cdf0e10cSrcweir create_directory($path); 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir if ($directory eq "unzip" ) 86*cdf0e10cSrcweir { 87*cdf0e10cSrcweir $path = $path . "common" . $par2script::globals::productextension . $par2script::globals::separator; 88*cdf0e10cSrcweir create_directory($path); 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir $path = $path . $directory . $par2script::globals::separator; 91*cdf0e10cSrcweir create_directory($path); 92*cdf0e10cSrcweir } 93*cdf0e10cSrcweir else 94*cdf0e10cSrcweir { 95*cdf0e10cSrcweir $path = $path . $par2script::globals::compiler . $par2script::globals::productextension . $par2script::globals::separator; 96*cdf0e10cSrcweir create_directory($path); 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir $path = $path . $par2script::globals::product . $par2script::globals::separator; 99*cdf0e10cSrcweir create_directory($path); 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir $path = $path . $directory . $par2script::globals::separator; 102*cdf0e10cSrcweir create_directory($path); 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir if (!($$languagesref eq "" )) # this will be a path like "01_49", for Profiles and ConfigurationFiles, idt-Files 105*cdf0e10cSrcweir { 106*cdf0e10cSrcweir $path = $path . $$languagesref . $par2script::globals::separator; 107*cdf0e10cSrcweir create_directory($path); 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir } 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir $path =~ s/\Q$par2script::globals::separator\E\s*$//; 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir return $path; 114*cdf0e10cSrcweir} 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir######################## 117*cdf0e10cSrcweir# Copying one file 118*cdf0e10cSrcweir######################## 119*cdf0e10cSrcweir 120*cdf0e10cSrcweirsub copy_one_file 121*cdf0e10cSrcweir{ 122*cdf0e10cSrcweir my ($source, $dest) = @_; 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir my ($copyreturn, $returnvalue); 125*cdf0e10cSrcweir my $infoline; 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir $copyreturn = copy($source, $dest); 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir if ($copyreturn) 130*cdf0e10cSrcweir { 131*cdf0e10cSrcweir $infoline = "Copy: $source to $dest\n"; 132*cdf0e10cSrcweir $returnvalue = 1; 133*cdf0e10cSrcweir } 134*cdf0e10cSrcweir else 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir $infoline = "Error: Could not copy $source to $dest\n"; 137*cdf0e10cSrcweir $returnvalue = 0; 138*cdf0e10cSrcweir } 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir push(@par2script::globals::logfileinfo, $infoline); 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir return $returnvalue; 143*cdf0e10cSrcweir} 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir########################################## 146*cdf0e10cSrcweir# Copying all files from one directory 147*cdf0e10cSrcweir# to another directory 148*cdf0e10cSrcweir########################################## 149*cdf0e10cSrcweir 150*cdf0e10cSrcweirsub copy_directory 151*cdf0e10cSrcweir{ 152*cdf0e10cSrcweir my ($sourcedir, $destdir) = @_; 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir my ($onefile, $sourcefile, $destfile); 155*cdf0e10cSrcweir my @sourcefiles = (); 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir $sourcedir =~ s/\Q$par2script::globals::separator\E\s*$//; 158*cdf0e10cSrcweir $destdir =~ s/\Q$par2script::globals::separator\E\s*$//; 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir $infoline = "\n"; 161*cdf0e10cSrcweir push(@par2script::globals::logfileinfo, $infoline); 162*cdf0e10cSrcweir $infoline = "Copying files from directory $sourcedir to directory $destdir\n"; 163*cdf0e10cSrcweir push(@par2script::globals::logfileinfo, $infoline); 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir opendir(DIR, $sourcedir); 166*cdf0e10cSrcweir @sourcefiles = readdir(DIR); 167*cdf0e10cSrcweir closedir(DIR); 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir foreach $onefile (@sourcefiles) 170*cdf0e10cSrcweir { 171*cdf0e10cSrcweir if ((!($onefile eq ".")) && (!($onefile eq ".."))) 172*cdf0e10cSrcweir { 173*cdf0e10cSrcweir $sourcefile = $sourcedir . $par2script::globals::separator . $onefile; 174*cdf0e10cSrcweir $destfile = $destdir . $par2script::globals::separator . $onefile; 175*cdf0e10cSrcweir if ( -f $sourcefile ) # only files, no directories 176*cdf0e10cSrcweir { 177*cdf0e10cSrcweir copy_one_file($sourcefile, $destfile); 178*cdf0e10cSrcweir } 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir } 181*cdf0e10cSrcweir} 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir1; 185