#!/usr/bin/env perl

##**************************************************************
##
## Copyright (C) 1990-2007, Condor Team, Computer Sciences Department,
## University of Wisconsin-Madison, WI.
## 
## Licensed under the Apache License, Version 2.0 (the "License"); you
## may not use this file except in compliance with the License.  You may
## obtain a copy of the License at
## 
##    http://www.apache.org/licenses/LICENSE-2.0
## 
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
##
##**************************************************************



# This script is used to package up the appropriate "glidein" tarball
# for use with condor_glidein.  It must contain the master, startd and
# starter.  The only trick is that the name of the file to create is a
# little funky (for Globus's bennefit), so we use a table in here.
# Derek Wright <wright@cs.wisc.edu> 11/11/99

# Where do you want the tarball put once it's created?
$target_dir = "/p/condor/public/binaries/glidein";

# Map AFS @sys names into Globus-blessed names.
%platform_names = (
  "sun4x_55"      => "sparc-sun-solaris-2.5.1",
  "sun4x_56"      => "sparc-sun-solaris-2.6",
  "sun4x_57"      => "sparc-sun-solaris-2.7",
  "sunx86_56"     => "intel-sun-solaris-2.6",
  "i386_linux2"   => "i686-libc5-linux-2.0.36",
  "i386_linux3"   => "i686-glibc20-linux-2.2.10",
  "i386_linux22"  => "i686-glibc21-linux-2.2.10",
  "i386_rh61"     => "i686-glibc21-linux-2.2.10",
  "alpha_linux3"  => "alpha-glibc20-linux-2.2.10",
  "alpha_dux40"   => "unknown",
  "sgi_62"        => "mips-sgi-irix-6.2",
  "sgi_65"        => "mips-sgi-irix-6.5",
  "hp_ux102"      => "unknown"
);

# Deal with any command-line args we are passed:
while( $_ = shift( @ARGV ) ) {
  SWITCH: { 
    if( /-s.*/ ) {
    $sys = shift(@ARGV);
    last SWITCH;
    }
    if( /-v.*/ ) {
    $versarg = shift(@ARGV);
    print "Got version arg: $versarg\n";
    last SWITCH;

    }
    if( /-l.*/ ) {
    $libc = shift(@ARGV);
    last SWITCH;
    }
  }
}

# If we don't already know, figure out what platform we are 
if( ! $sys ) {
    $sys = `sys`;
    chomp($sys);
}
$platform = $platform_names{$sys};

# Now, grab the version of this release.
if( $versarg ) {
    $_ = $versarg;
} else {
    # If we weren't told on the command line, try to run ident
    # directly on the condor_master binary.
    if( -f "strip_dir/sbin/condor_master" ) {
        $_=`ident strip_dir/sbin/condor_master`;
    } elsif ( -f "static_dir/sbin/condor_master" ) {
        $_=`ident static_dir/sbin/condor_master`;
    } else {
    die "ERROR: can't find a condor_master, and no -v specified";
    }
}
/.*\$CondorVersion: (\d*)\.(\d*)\.(\d*).*/;
$majorv = $1;
$minorv = $2;
$releasev = $3;
$version = "$majorv.$minorv.$releasev";

# Decide what kind of build: use static if it's there. 
if( -f "static_dir/sbin/condor_master" ) {
    $dir = "static_dir/sbin";
} else {
    $dir = "strip_dir/sbin";
}

# Actually do the work.
$name = "$version-$platform.tar";
print "Working on $name\n";
chdir( $dir ) || die "Can't chdir($dir): $!\n";
print "Creating glidein tarball for $platform\n";
print `tar -cvf $name condor_master condor_startd condor_starter`;
print "Moving glidein tarball to $target_dir\n";
`mv -f $name $target_dir`;
print "Done.\n";


