in scripts/InstallLicAndStartLK.pl [51:121]
sub GetLicenseFile {
my $cmd = "curl --insecure --connect-timeout 5 -s -S";
my @results;
my $retCode;
my $localPath = "/tmp/LK4L.lic";
my @cmdOutput;
my $s3URI = 0;
# Check to see if the url is actually an s3 uri
if ($licenseURL =~ /^s3:\/\/(.*)/) {
$cmd = "/usr/local/bin/aws s3 cp";
$s3URI = 1;
}
# Lop off the trailing slash if there is one.
if ((substr $licenseURL, -1) eq '/') {
chop $licenseURL;
}
# Append default license filename to the end of the URL if
# no license filename already present
if ($licenseURL =~ m/.lic$/) {
$cmd = $cmd . " $licenseURL";
} else {
$cmd = $cmd . " $licenseURL" . $DEFAULT_LIC_NAME;
}
# Download file from S3 URI, and save it to localPath location.
if ($s3URI) {
$cmd = $cmd . " $localPath";
@results = `$cmd 2>&1`;
# The expected return code here is zero.
# However, zero in perl is the boolean false.
# if(False) does not evaluate to True, it evaulates to False.
#
# DB<3> if (0) { print "this is true" };
#
# DB<4> if (!0) { print "this is true" };
# this is true
#
if(!$?) {
return $localPath;
} else {
return undef;
}
}
# Get the license file
@results = `$cmd 2>&1`;
# Check and see if what is returned looks like a license file
# because curl does not always set the return code to a non-zero
# value when there is a problem. For example a typo on the URL
# could result in a "404 Not Found" issue but curl exits with 0.
if (!grep (/^FEATURE lklc/, @results)) {
print "Failed to obtain LifeKeeper license.\n";
foreach (@results) {
print "$_";
}
return undef;
}
# Save the license info to a file for use with lkkeyins.
open(LIC, ">$localPath") or die "Failed to open license file!";
foreach (@results) {
print LIC $_;
}
close (LIC);
return $localPath;
}