1*9780544fSAndrew Rist#************************************************************** 2*9780544fSAndrew Rist# 3*9780544fSAndrew Rist# Licensed to the Apache Software Foundation (ASF) under one 4*9780544fSAndrew Rist# or more contributor license agreements. See the NOTICE file 5*9780544fSAndrew Rist# distributed with this work for additional information 6*9780544fSAndrew Rist# regarding copyright ownership. The ASF licenses this file 7*9780544fSAndrew Rist# to you under the Apache License, Version 2.0 (the 8*9780544fSAndrew Rist# "License"); you may not use this file except in compliance 9*9780544fSAndrew Rist# with the License. You may obtain a copy of the License at 10*9780544fSAndrew Rist# 11*9780544fSAndrew Rist# http://www.apache.org/licenses/LICENSE-2.0 12*9780544fSAndrew Rist# 13*9780544fSAndrew Rist# Unless required by applicable law or agreed to in writing, 14*9780544fSAndrew Rist# software distributed under the License is distributed on an 15*9780544fSAndrew Rist# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*9780544fSAndrew Rist# KIND, either express or implied. See the License for the 17*9780544fSAndrew Rist# specific language governing permissions and limitations 18*9780544fSAndrew Rist# under the License. 19*9780544fSAndrew Rist# 20*9780544fSAndrew Rist#************************************************************** 21*9780544fSAndrew Rist 22*9780544fSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir 25cdf0e10cSrcweirpackage par2script::systemactions; 26cdf0e10cSrcweir 27cdf0e10cSrcweiruse File::Copy; 28cdf0e10cSrcweiruse par2script::exiter; 29cdf0e10cSrcweiruse par2script::globals; 30cdf0e10cSrcweir 31cdf0e10cSrcweir###################################################### 32cdf0e10cSrcweir# Creating a new direcotory 33cdf0e10cSrcweir###################################################### 34cdf0e10cSrcweir 35cdf0e10cSrcweirsub create_directory 36cdf0e10cSrcweir{ 37cdf0e10cSrcweir my ($directory) = @_; 38cdf0e10cSrcweir 39cdf0e10cSrcweir my $returnvalue = 1; 40cdf0e10cSrcweir 41cdf0e10cSrcweir if (!(-d $directory)) 42cdf0e10cSrcweir { 43cdf0e10cSrcweir $returnvalue = mkdir($directory, 0775); 44cdf0e10cSrcweir 45cdf0e10cSrcweir if ($returnvalue) 46cdf0e10cSrcweir { 47cdf0e10cSrcweir $infoline = "Created directory: $directory\n"; 48cdf0e10cSrcweir push(@par2script::globals::logfileinfo, $infoline); 49cdf0e10cSrcweir 50cdf0e10cSrcweir if ($par2script::globals::isunix) 51cdf0e10cSrcweir { 52cdf0e10cSrcweir my $localcall = "chmod 775 $directory \>\/dev\/null 2\>\&1"; 53cdf0e10cSrcweir system($localcall); 54cdf0e10cSrcweir } 55cdf0e10cSrcweir } 56cdf0e10cSrcweir else 57cdf0e10cSrcweir { 58cdf0e10cSrcweir par2script::exiter::exit_program("Error: Could not create directory: $directory", "create_directory"); 59cdf0e10cSrcweir } 60cdf0e10cSrcweir } 61cdf0e10cSrcweir} 62cdf0e10cSrcweir 63cdf0e10cSrcweir####################################################################### 64cdf0e10cSrcweir# Creating the directories, in which files are generated or unzipped 65cdf0e10cSrcweir####################################################################### 66cdf0e10cSrcweir 67cdf0e10cSrcweirsub create_directories 68cdf0e10cSrcweir{ 69cdf0e10cSrcweir my ($directory, $languagesref) =@_; 70cdf0e10cSrcweir 71cdf0e10cSrcweir $par2script::globals::unpackpath =~ s/\Q$par2script::globals::separator\E\s*$//; # removing ending slashes and backslashes 72cdf0e10cSrcweir 73cdf0e10cSrcweir my $path = $par2script::globals::unpackpath; # this path already exists 74cdf0e10cSrcweir 75cdf0e10cSrcweir $path = $path . $par2script::globals::separator . $par2script::globals::build . $par2script::globals::separator; 76cdf0e10cSrcweir create_directory($path); 77cdf0e10cSrcweir 78cdf0e10cSrcweir $path = $path . $par2script::globals::minor . $par2script::globals::separator; 79cdf0e10cSrcweir create_directory($path); 80cdf0e10cSrcweir 81cdf0e10cSrcweir if ($directory eq "unzip" ) 82cdf0e10cSrcweir { 83cdf0e10cSrcweir $path = $path . "common" . $par2script::globals::productextension . $par2script::globals::separator; 84cdf0e10cSrcweir create_directory($path); 85cdf0e10cSrcweir 86cdf0e10cSrcweir $path = $path . $directory . $par2script::globals::separator; 87cdf0e10cSrcweir create_directory($path); 88cdf0e10cSrcweir } 89cdf0e10cSrcweir else 90cdf0e10cSrcweir { 91cdf0e10cSrcweir $path = $path . $par2script::globals::compiler . $par2script::globals::productextension . $par2script::globals::separator; 92cdf0e10cSrcweir create_directory($path); 93cdf0e10cSrcweir 94cdf0e10cSrcweir $path = $path . $par2script::globals::product . $par2script::globals::separator; 95cdf0e10cSrcweir create_directory($path); 96cdf0e10cSrcweir 97cdf0e10cSrcweir $path = $path . $directory . $par2script::globals::separator; 98cdf0e10cSrcweir create_directory($path); 99cdf0e10cSrcweir 100cdf0e10cSrcweir if (!($$languagesref eq "" )) # this will be a path like "01_49", for Profiles and ConfigurationFiles, idt-Files 101cdf0e10cSrcweir { 102cdf0e10cSrcweir $path = $path . $$languagesref . $par2script::globals::separator; 103cdf0e10cSrcweir create_directory($path); 104cdf0e10cSrcweir } 105cdf0e10cSrcweir } 106cdf0e10cSrcweir 107cdf0e10cSrcweir $path =~ s/\Q$par2script::globals::separator\E\s*$//; 108cdf0e10cSrcweir 109cdf0e10cSrcweir return $path; 110cdf0e10cSrcweir} 111cdf0e10cSrcweir 112cdf0e10cSrcweir######################## 113cdf0e10cSrcweir# Copying one file 114cdf0e10cSrcweir######################## 115cdf0e10cSrcweir 116cdf0e10cSrcweirsub copy_one_file 117cdf0e10cSrcweir{ 118cdf0e10cSrcweir my ($source, $dest) = @_; 119cdf0e10cSrcweir 120cdf0e10cSrcweir my ($copyreturn, $returnvalue); 121cdf0e10cSrcweir my $infoline; 122cdf0e10cSrcweir 123cdf0e10cSrcweir $copyreturn = copy($source, $dest); 124cdf0e10cSrcweir 125cdf0e10cSrcweir if ($copyreturn) 126cdf0e10cSrcweir { 127cdf0e10cSrcweir $infoline = "Copy: $source to $dest\n"; 128cdf0e10cSrcweir $returnvalue = 1; 129cdf0e10cSrcweir } 130cdf0e10cSrcweir else 131cdf0e10cSrcweir { 132cdf0e10cSrcweir $infoline = "Error: Could not copy $source to $dest\n"; 133cdf0e10cSrcweir $returnvalue = 0; 134cdf0e10cSrcweir } 135cdf0e10cSrcweir 136cdf0e10cSrcweir push(@par2script::globals::logfileinfo, $infoline); 137cdf0e10cSrcweir 138cdf0e10cSrcweir return $returnvalue; 139cdf0e10cSrcweir} 140cdf0e10cSrcweir 141cdf0e10cSrcweir########################################## 142cdf0e10cSrcweir# Copying all files from one directory 143cdf0e10cSrcweir# to another directory 144cdf0e10cSrcweir########################################## 145cdf0e10cSrcweir 146cdf0e10cSrcweirsub copy_directory 147cdf0e10cSrcweir{ 148cdf0e10cSrcweir my ($sourcedir, $destdir) = @_; 149cdf0e10cSrcweir 150cdf0e10cSrcweir my ($onefile, $sourcefile, $destfile); 151cdf0e10cSrcweir my @sourcefiles = (); 152cdf0e10cSrcweir 153cdf0e10cSrcweir $sourcedir =~ s/\Q$par2script::globals::separator\E\s*$//; 154cdf0e10cSrcweir $destdir =~ s/\Q$par2script::globals::separator\E\s*$//; 155cdf0e10cSrcweir 156cdf0e10cSrcweir $infoline = "\n"; 157cdf0e10cSrcweir push(@par2script::globals::logfileinfo, $infoline); 158cdf0e10cSrcweir $infoline = "Copying files from directory $sourcedir to directory $destdir\n"; 159cdf0e10cSrcweir push(@par2script::globals::logfileinfo, $infoline); 160cdf0e10cSrcweir 161cdf0e10cSrcweir opendir(DIR, $sourcedir); 162cdf0e10cSrcweir @sourcefiles = readdir(DIR); 163cdf0e10cSrcweir closedir(DIR); 164cdf0e10cSrcweir 165cdf0e10cSrcweir foreach $onefile (@sourcefiles) 166cdf0e10cSrcweir { 167cdf0e10cSrcweir if ((!($onefile eq ".")) && (!($onefile eq ".."))) 168cdf0e10cSrcweir { 169cdf0e10cSrcweir $sourcefile = $sourcedir . $par2script::globals::separator . $onefile; 170cdf0e10cSrcweir $destfile = $destdir . $par2script::globals::separator . $onefile; 171cdf0e10cSrcweir if ( -f $sourcefile ) # only files, no directories 172cdf0e10cSrcweir { 173cdf0e10cSrcweir copy_one_file($sourcefile, $destfile); 174cdf0e10cSrcweir } 175cdf0e10cSrcweir } 176cdf0e10cSrcweir } 177cdf0e10cSrcweir} 178cdf0e10cSrcweir 179cdf0e10cSrcweir 180cdf0e10cSrcweir1; 181