+# copy the file pointed to by $src to the location specified by $dest. in the
+# process observe the rules regarding when the '-force' flag was passed to us.
+#
+
+sub copyFile
+{
+ my($src, $dest) = @_;
+
+ if ( !isReadable($src) )
+ {
+ debug1("$src is not readable... not creating $dest.\n");
+ return;
+ }
+
+ if ( !prepareFileWrite($dest) )
+ {
+ return;
+ }
+
+ action("cp $src $dest");
+}
+
+### copySXXScript( $in, $out )
+#
+# parse the input file, substituting in place the value of GLOBUS_LOCATION, and
+# write the result to the output file.
+#
+
+sub copySXXScript
+{
+ my($in, $out) = @_;
+ my($tmpgpath);
+
+ if ( !isReadable($in) )
+ {
+ debug1("$in is not readable... not creating $out.\n");
+ return;
+ }
+
+ if ( !prepareFileWrite($out) )
+ {
+ return;
+ }
+
+ #
+ # clean up any junk in the globus path variable
+ #
+
+ $tmpgpath = $gpath;
+ $tmpgpath =~ s:/+:/:g;
+ $tmpgpath =~ s:([^/]+)/$:\1:g;
+
+ #
+ # read in the script, substitute globus location, then write it back out
+ #
+
+ $data = readFile($in);
+ $data =~ s|\@GLOBUS_LOCATION\@|$tmpgpath|g;
+ writeFile($out, $data);
+ action("chmod 755 $out");
+}
+
+### readFile( $filename )
+#
+# reads and returns $filename's contents
+#
+
+sub readFile
+{
+ my($filename) = @_;
+ my($data);
+
+ open(IN, "$filename") || exitDie("ERROR: Can't open '$filename': $!\n");
+ $/ = undef;
+ $data = <IN>;
+ $/ = "\n";
+ close(IN);
+
+ return $data;
+}
+
+### writeFile( $filename, $fileinput )
+#
+# create the inputs to the ssl program at $filename, appending the common name to the
+# stream in the process
+#
+
+sub writeFile
+{
+ my($filename, $fileinput) = @_;
+
+ #
+ # test for a valid $filename
+ #
+
+ if ( !defined($filename) || (length($filename) lt 1) )
+ {
+ exitDie("ERROR: Filename is undefined!\n");
+ }
+
+ #
+ # verify that we are prepared to work with $filename
+ #
+
+ if ( !prepareFileWrite($filename) )
+ {
+ return;
+ }
+
+ #
+ # write the output to $filename
+ #
+
+ open(OUT, ">$filename");
+ print OUT "$fileinput";
+ close(OUT);
+}
+
+### debug1( $arg1, $arg2 )
+#
+# Print out a debugging message at level 1.
+#
+
+sub debug1
+{
+ debug(string => \@_, level => 1);
+}
+
+### debug0( $arg1, $arg2 )
+#
+# Print out a debugging message at level 0.
+#
+
+sub debug0
+{
+ debug(string => \@_, level => 0);
+}
+
+### debug( string => $string, level => $level )
+#
+# Print out debugging messages at various levels. Feel free to use debugN() directly
+# which in turn calls this subroutine.
+#
+
+sub debug
+{
+ my %args = @_;
+
+ if (!defined($args{'level'}))
+ {
+ $args{'level'} = 0;
+ }
+
+ if ($verbose >= $args{'level'})
+ {
+ printf(@{$args{'string'}});
+ }
+}
+
+### action( $command )
+#
+# run $command within a proper system() command.