root/juggler/trunk/release/scripts/install-dir.pl
| Revision 20974, 5.9 kB (checked in by patrick, 1 year ago) | |
|---|---|
| |
| Line | |
|---|---|
| 1 | #!/usr/bin/env perl |
| 2 | |
| 3 | # ************** <auto-copyright.pl BEGIN do not edit this line> ************** |
| 4 | # |
| 5 | # VR Juggler is (C) Copyright 1998-2008 by Iowa State University |
| 6 | # |
| 7 | # Original Authors: |
| 8 | # Allen Bierbaum, Christopher Just, |
| 9 | # Patrick Hartling, Kevin Meinert, |
| 10 | # Carolina Cruz-Neira, Albert Baker |
| 11 | # |
| 12 | # This library is free software; you can redistribute it and/or |
| 13 | # modify it under the terms of the GNU Library General Public |
| 14 | # License as published by the Free Software Foundation; either |
| 15 | # version 2 of the License, or (at your option) any later version. |
| 16 | # |
| 17 | # This library is distributed in the hope that it will be useful, |
| 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 20 | # Library General Public License for more details. |
| 21 | # |
| 22 | # You should have received a copy of the GNU Library General Public |
| 23 | # License along with this library; if not, write to the |
| 24 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 25 | # Boston, MA 02111-1307, USA. |
| 26 | # |
| 27 | # *************** <auto-copyright.pl END do not edit this line> *************** |
| 28 | |
| 29 | # ----------------------------------------------------------------------------- |
| 30 | # Install an entire directory from the VR Juggler development tree without |
| 31 | # the CVS directories. All files in the directory tree are copied to the |
| 32 | # destination directory. |
| 33 | # |
| 34 | # Usage: |
| 35 | # install-dir.pl -i <source directory> -o <destination directory> |
| 36 | # [-u <user name> -g <group name> -m <mode>] |
| 37 | # |
| 38 | # <source directory> - The source directory to be installed |
| 39 | # <destination directory> - The location to install the source directory |
| 40 | # ----------------------------------------------------------------------------- |
| 41 | |
| 42 | require 5.004; |
| 43 | |
| 44 | use Cwd; |
| 45 | use File::Basename; |
| 46 | use File::Copy; |
| 47 | use File::Path; |
| 48 | use Getopt::Std; |
| 49 | |
| 50 | # Do this to include the path to the script in @INC. |
| 51 | BEGIN |
| 52 | { |
| 53 | $path = (fileparse("$0"))[1]; |
| 54 | } |
| 55 | |
| 56 | use lib("$path"); |
| 57 | use InstallOps; |
| 58 | |
| 59 | # Our recurseAction() subroutine wants the current file as a parameter. |
| 60 | $InstallOps::pass_rec_func_cur_file = 1; |
| 61 | |
| 62 | $Win32 = 1 if $ENV{'OS'} =~ /Windows/; |
| 63 | |
| 64 | # Ensure that there are four command-line arguments. If not, exit with |
| 65 | # error status. |
| 66 | if ( $#ARGV < 3 ) |
| 67 | { |
| 68 | warn "Usage: $0 -i <source directory> -o <destination directory>\n"; |
| 69 | exit 1; |
| 70 | } |
| 71 | |
| 72 | # Get the -i and -o options and store their values in $opt_i and $opt_o |
| 73 | # respectively. |
| 74 | getopts('e:g:i:lm:o:v:'); |
| 75 | |
| 76 | my(@exts) = split(/,/, "$opt_e") if $opt_e; |
| 77 | my $src_dir = "$opt_i"; |
| 78 | my $dest_dir = "$opt_o"; |
| 79 | |
| 80 | if ( $opt_v ) |
| 81 | { |
| 82 | my @path_info = fileparse("$opt_v"); |
| 83 | push(@INC, "$path_info[1]"); |
| 84 | require "$path_info[0]"; |
| 85 | } |
| 86 | |
| 87 | # Defaults. getpwuid() is not implemented in the Win32 Perl port. |
| 88 | my($uid, $gid, $mode) = ($<, (getpwuid($<))[3], "0644") unless $Win32; |
| 89 | |
| 90 | if ( $opt_u ) |
| 91 | { |
| 92 | $uname = "$opt_u" if $opt_u; |
| 93 | my(@user_info) = getpwnam("$uname") or die "getpwnam($uname): $!\n"; |
| 94 | $uid = $user_info[2]; |
| 95 | } |
| 96 | |
| 97 | # getgrnam() is not implemented in the Win32 Perl port. |
| 98 | if ( $opt_g && ! $Win32 ) |
| 99 | { |
| 100 | $gname = "$opt_g" if $opt_g; |
| 101 | my(@group_info) = getgrnam("$gname") or die "getgrnam($gname): $!\n"; |
| 102 | $gid = $group_info[2]; |
| 103 | } |
| 104 | |
| 105 | $mode = "$opt_m" if $opt_m; |
| 106 | |
| 107 | my $make_symlink = ($opt_l ? 1 : 0); |
| 108 | |
| 109 | umask(002); |
| 110 | mkpath("$dest_dir", 0, 0755); # Make sure that $dest_dir exists |
| 111 | |
| 112 | $start_dir = cwd() unless $dest_dir =~ /^\//; # Save this for later |
| 113 | |
| 114 | # Push the source directory onto the InstallOps module's internal directory |
| 115 | # stack. This is used for recursion through the source directory. |
| 116 | push(@InstallOps::dirstack, "$src_dir"); |
| 117 | |
| 118 | # Recurse through $src_dir and create the destination directory tree. |
| 119 | # recurseAction() handles further work. |
| 120 | recurseDir("$src_dir", "$start_dir/$dest_dir"); |
| 121 | |
| 122 | exit 0; |
| 123 | |
| 124 | # ----------------------------------------------------------------------------- |
| 125 | # Copy the current file to the appropriate place in the destination directory |
| 126 | # tree. |
| 127 | # |
| 128 | # Syntax: |
| 129 | # recurseAction($curfile); |
| 130 | # |
| 131 | # Arguments: |
| 132 | # $curfile - The name of the current file in the recursion process. |
| 133 | # ----------------------------------------------------------------------------- |
| 134 | sub recurseAction |
| 135 | { |
| 136 | my $curfile = shift; |
| 137 | |
| 138 | # Install only the files with extensions listed in @exts if there are any |
| 139 | # elements in @exts. |
| 140 | if ( $#exts != -1 ) |
| 141 | { |
| 142 | foreach ( @exts ) |
| 143 | { |
| 144 | if ( $curfile =~ /$_$/ ) |
| 145 | { |
| 146 | installFile("$curfile", $uid, $gid, "$mode", "$dest_dir", |
| 147 | $make_symlink); |
| 148 | last; |
| 149 | } |
| 150 | } |
| 151 | } |
| 152 | else |
| 153 | { |
| 154 | # If the current file is a .in template file, process it before |
| 155 | # installing. |
| 156 | if ( $curfile =~ /^(.+?)\.in$/ ) |
| 157 | { |
| 158 | my $filename = "$1"; |
| 159 | |
| 160 | my $workfile; |
| 161 | |
| 162 | if ( $Win32 ) |
| 163 | { |
| 164 | $workfile = "C:/temp/$curfile"; |
| 165 | } |
| 166 | else |
| 167 | { |
| 168 | $workfile = "/tmp/$curfile"; |
| 169 | } |
| 170 | |
| 171 | # Make a working copy of the input file to be safe. |
| 172 | my @stats = (stat("$curfile"))[8,9]; |
| 173 | copy("$curfile", "$workfile") unless "$curfile" eq "$workfile"; |
| 174 | |
| 175 | # Replace the tags in $workfile with the values in %VARS. |
| 176 | if ( replaceTags("$workfile", %VARS) < 0 ) |
| 177 | { |
| 178 | copy("$curfile", "$filename"); |
| 179 | } |
| 180 | # If replaceTags() succeeded, move the work file to the file name |
| 181 | # to be installed. |
| 182 | else |
| 183 | { |
| 184 | copy("$workfile", "$filename"); |
| 185 | unlink("$workfile") |
| 186 | or warn "WARNING: Could not delete $workfile: $!"; |
| 187 | } |
| 188 | |
| 189 | # Apply the saved attributes of $curfile to $filename. |
| 190 | utime(@stats, "$filename"); |
| 191 | |
| 192 | installFile("$filename", $uid, $gid, "$mode", "$dest_dir", |
| 193 | $make_symlink); |
| 194 | |
| 195 | # Delete the generated file now that we are done with it. |
| 196 | unlink("$filename") or warn "WARNING: Could not delete $filename: $!"; |
| 197 | } |
| 198 | # Otherwise, install it as-is. |
| 199 | else |
| 200 | { |
| 201 | installFile("$curfile", $uid, $gid, "$mode", "$dest_dir", |
| 202 | $make_symlink); |
| 203 | } |
| 204 | } |
| 205 | } |
Note: See TracBrowser for help on using the browser.
