root/juggler/trunk/release/scripts/install-src.pl
| Revision 20974, 5.4 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 a source (i.e., software source) directory to a specified |
| 31 | # destination directory. Only pre-defined file types (determined by file |
| 32 | # extension) are copied. No CVS subdirectories are installed. |
| 33 | # |
| 34 | # Usage: |
| 35 | # install-src.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::Path; |
| 47 | use Getopt::Std; |
| 48 | |
| 49 | # Do this to include the path to the script in @INC. |
| 50 | BEGIN |
| 51 | { |
| 52 | $path = (fileparse("$0"))[1]; |
| 53 | } |
| 54 | |
| 55 | use lib("$path"); |
| 56 | use InstallOps; |
| 57 | |
| 58 | # Our recurseAction() subroutine wants the current file as a parameter. |
| 59 | $InstallOps::pass_rec_func_cur_file = 1; |
| 60 | |
| 61 | $Win32 = 1 if $ENV{'OS'} =~ /Windows/; |
| 62 | |
| 63 | # Ensure that there are four command-line arguments. If not, exit with |
| 64 | # error status. |
| 65 | if ( $#ARGV < 3 ) |
| 66 | { |
| 67 | warn "Usage: $0 -i <source directory> -o <destination directory>\n"; |
| 68 | exit 1; |
| 69 | } |
| 70 | |
| 71 | # Get the -i and -o options and store their values in $opt_i and $opt_o |
| 72 | # respectively. |
| 73 | getopts('e:g:i:lm:o:u:'); |
| 74 | |
| 75 | my $dest_dir = "$opt_o"; |
| 76 | |
| 77 | # Defaults for ownership and permissions (except on Win32). |
| 78 | my($uid, $gid, $mode) = ($<, (getpwuid($<))[3], "0644") unless $Win32; |
| 79 | |
| 80 | if ( $opt_u ) |
| 81 | { |
| 82 | $uname = "$opt_u" if $opt_u; |
| 83 | my(@user_info) = getpwnam("$uname") or die "getpwnam($uname): $!\n"; |
| 84 | $uid = $user_info[2]; |
| 85 | } |
| 86 | |
| 87 | if ( $opt_g && ! $Win32 ) |
| 88 | { |
| 89 | $gname = "$opt_g" if $opt_g; |
| 90 | my(@group_info) = getgrnam("$gname") or die "getgrnam($gname): $!\n"; |
| 91 | $gid = $group_info[2]; |
| 92 | } |
| 93 | |
| 94 | $mode = "$opt_m" if $opt_m; |
| 95 | |
| 96 | # If the mode does not have at least one bit set for execution, define |
| 97 | # $script_mode to set the execute bit for all owners. |
| 98 | if ( $mode !~ /[157]/ ) |
| 99 | { |
| 100 | if ( $mode =~ /^(\d)(\d)(\d)(\d)$/ ) |
| 101 | { |
| 102 | $script_mode = sprintf("%d%d%d%d", $1, $2 + 1, $3 + 1, $4 + 1); |
| 103 | } |
| 104 | elsif ( $mode =~ /^(\d)(\d)(\d)$/ ) |
| 105 | { |
| 106 | $script_mode = sprintf("0%d%d%d", $1 + 1, $2 + 1, $3 + 1); |
| 107 | } |
| 108 | } |
| 109 | else |
| 110 | { |
| 111 | $script_mode = "$mode"; |
| 112 | } |
| 113 | |
| 114 | umask(002); |
| 115 | mkpath("$dest_dir", 0, 0755); # Make sure that $dest_dir exists |
| 116 | |
| 117 | $start_dir = cwd() unless $dest_dir =~ /^\//; # Save this for later |
| 118 | |
| 119 | # Push the source directory onto the InstallOps module's internal directory |
| 120 | # stack. This is used for recursion through the source directory. |
| 121 | push(@InstallOps::dirstack, "$opt_i"); |
| 122 | |
| 123 | # List of installable file extensions. These are checked with a |
| 124 | # case-insensitive regular expression. |
| 125 | my @exts = qw(.txt .c .h .cxx .cpp .pl .jdef .desc .dsc .mk .htm .html .gif |
| 126 | .jpg .dsw .dsp .sln .vcproj .java .jar .jconf .config .cfg .idl); |
| 127 | |
| 128 | if ( $opt_e ) |
| 129 | { |
| 130 | foreach ( split(/,/, "$opt_e") ) |
| 131 | { |
| 132 | push(@exts, "$_"); |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | my $make_symlink = ($opt_l ? 1 : 0); |
| 137 | |
| 138 | # Recurse through $src_dir and create the destination directory tree. |
| 139 | # recurseAction() handles further work. |
| 140 | recurseDir("$opt_i", "$start_dir/$dest_dir"); |
| 141 | |
| 142 | exit 0; |
| 143 | |
| 144 | # ----------------------------------------------------------------------------- |
| 145 | # Copy files of a selected type (based on extension) to the appropriate place |
| 146 | # in the destination directory tree. |
| 147 | # |
| 148 | # Syntax: |
| 149 | # recurseAction($curfile); |
| 150 | # |
| 151 | # Arguments: |
| 152 | # $curfile - The name of the current file in the recursion process. |
| 153 | # ----------------------------------------------------------------------------- |
| 154 | sub recurseAction |
| 155 | { |
| 156 | my $curfile = shift; |
| 157 | |
| 158 | my $installed = 0; |
| 159 | |
| 160 | my $ext = ''; |
| 161 | foreach $ext ( @exts ) |
| 162 | { |
| 163 | if ( $curfile =~ /$ext$/i ) |
| 164 | { |
| 165 | installFile("$curfile", $uid, $gid, "$mode", "$dest_dir", |
| 166 | $make_symlink); |
| 167 | $installed = 1; |
| 168 | last; |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | unless ( $installed ) |
| 173 | { |
| 174 | # This is equivalent to a C switch block. |
| 175 | SWITCH: |
| 176 | { |
| 177 | # Match README. |
| 178 | if ( "$curfile" eq "README" ) |
| 179 | { |
| 180 | installFile("$curfile", $uid, $gid, "$mode", "$dest_dir", |
| 181 | $make_symlink); |
| 182 | last SWITCH; |
| 183 | } |
| 184 | |
| 185 | # Match Makefile. |
| 186 | if ( "$curfile" eq "Makefile" ) |
| 187 | { |
| 188 | installFile("$curfile", $uid, $gid, "$mode", "$dest_dir", |
| 189 | $make_symlink); |
| 190 | last SWITCH; |
| 191 | } |
| 192 | } |
| 193 | } |
| 194 | } |
Note: See TracBrowser for help on using the browser.
