Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with Perl Script subroutine &main

Status
Not open for further replies.

drewdown

IS-IT--Management
Apr 20, 2006
657
US
I am trying to migrate a couple scripts off an old red hat box and onto an ubuntu box. 1 of the 2 works fine, the one below does not, it kicks this error message out when I try to run it:

Code:
+++ Attempting to view license '12345-111111-20080902-0142089.gpg'
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++ Checking Customer License Signature
gpg: WARNING: unsafe permissions on homedir `/home/prod/license/gpg.public'
gpg: Signature made Tue 02 Sep 2008 11:08:49 AM EDT using XXXX key ID XXXXXXX
gpg: Good signature from "XXXXXX Customer Control <support@XXXXX.com>"

+++ Unpacking License File
Undefined subroutine &main::abort called at ./showLicense line 75.

Line 75 of the script is this : abort( "Internal Error:"

Here is the script:

Code:
#!/usr/bin/perl

use strict;

if ( !@ARGV ) {
        print STDERR "Usage: $0 <license_file> ...\n";
        exit -1;
}

my $homeDir = "/home/prod/license/gpg.public";

if ( ! -d $homeDir ) {
        $homeDir = "/prod/netmri/src/setup/gpg.public";
        if ( ! -d $homeDir ) {
                $homeDir = "/root/.gpg";
                if ( ! -d $homeDir ) {
                        print STDERR "Unable to locate gpg.public keyring\n";
                        exit -1;
                }
        }
}

my $tmpDir = "/tmp";
foreach my $inputFile (@ARGV) {

        print "\n";
        print "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
        print "+++ Attempting to view license '$inputFile'\n";
        print "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
        print "+++ Checking Customer License Signature\n";
        my $licenseTar = "license.tgz";
        my $cmd =  "/bin/echo \"It's really just a bunch of ones and zeros\" | "
                . "/usr/bin/gpg "
                . "     --homedir=$homeDir"
                . "     --quiet --batch"
                . "     --no-secmem-warning"
                . "     --passphrase-fd 0"
                . "     --output $tmpDir/$licenseTar"
                . "     --decrypt $inputFile 2>&1";

        my $result = `$cmd`;
        print "$result\n";

        if ( $result =~ /decryption failed: secret key not available/ ) {
                print "+++ Checking Evaluation License Signature\n";
                $cmd =  "/bin/echo \"java.lang.SecurityException: Invalid Passphrase\" | "
                        . "/usr/bin/gpg "
                        . "     --homedir=$homeDir"
                        . "     --quiet --batch"
                        . "     --no-secmem-warning"
                        . "     --passphrase-fd 0"
                        . "     --output $tmpDir/$licenseTar"
                        . "     --decrypt $inputFile 2>&1";

                $result = `$cmd`;
                print "$result\n";

                if ( $result =~ /decryption failed: secret key not available/ ) {
                        abort ( "Decryption Failure: $result" );
                }
        }

        if ($result !~ /Good signature/) {
                abort ("Invalid Digital Signature:"
                        . " The given file has not been properly signed"
                        . " by xxxxxx, Inc. Please ensure that the correct filename was specified."
                );
        }

        print "+++ Unpacking License File\n";
        system ( "cd $tmpDir; /bin/tar xfm $licenseTar"
                        . " --use-compress-program /usr/bin/gzip"
                        . " >/dev/null 2>&1" );
        if ($?) {
                abort( "Internal Error:"
                        . " The given license file could not be unpacked properly."
                        . " Please contact support\@xxxxxx.com."
                );
        }

        # Get the directory that was just unpacked by looking at the
        # tar file in case the user changed the name of the license
        # file.

        my $newLicenseDir = `cd $tmpDir; (/bin/tar tfz $licenseTar | /usr/bin/head -1)`;
        chomp $newLicenseDir;
        $newLicenseDir =~ s|/||g;

        my $metaFile = "$tmpDir/$newLicenseDir/metaData.cfg";
        if ( ! -f $metaFile ) {
        abort ( "Invalid License Package:"
                . " Meta data file missing from license package ($tmpDir/$newLicenseDir)." );
        }

        open ( META, $metaFile ) || abort ( "Error Processing License:"
                                . " Can't open meta data file ($!) from license package." );


        print "\n";
        print "+++ License contents starts.\n\n";
        while (<META>) {
                print "$_";
        }
        print "\n+++ License contents ends.\n";
        close (META);

        # Clean up tmpDir
        system ("rm -fr $tmpDir/$newLicenseDir");
        system ("rm -f $tmpDir/$licenseTar");


I am very new to Perl and haven't been able to figure this out via google. Any idea what I need to do to fix this?
 
Your script is trying to call a subroutine called "abort" that isn't in your script.
 
Thanks ishnid.

What do I need to do to fix it? And why would it work on the red hat box and not the ubuntu box?

 
I just add this bit of code:

Code:
 sub abort {
                my($msg) =@_;
                print "Error: $msg\n";
                exit;
        }

Now when I run the script I get a different error message:
Code:
+++ Unpacking License File
Error: Internal Error: The given license file could not be unpacked properly. Please contact support@XXXXXXXX.com.
 
Debugging shows a problem unpacking the file, not sure how to fix it either. Any idea's by looking at the script?

Code:
  DB<1> 
+++ Unpacking License File
main::(./showLicense:78):               system ( "cd $tmpDir; /bin/tar xfm $licenseTar"
main::(./showLicense:79):                               . " --use-compress-program /usr/bin/gzip"
main::(./showLicense:80):                               . " >/dev/null 2>&1" );
  DB<1> 
main::(./showLicense:81):               if ($?) {
  DB<1> 
main::(./showLicense:82):                       abort( "Internal Error:"
main::(./showLicense:83):                               . " The given license file could not be unpacked properly."
main::(./showLicense:84):                               . " Please contact support\@XXXXXXXX.com."
main::(./showLicense:85):                       );
  DB<1> 
main::abort(./showLicense:6):                   my($msg) =@_;
  DB<1> 
main::abort(./showLicense:7):                   print "Error: $msg\n";
  DB<1> 
Error: Internal Error: The given license file could not be unpacked properly. Please contact support@XXXXXXX.com.
main::abort(./showLicense:8):                   exit;
 
Commenting out this line
Code:
. " --use-compress-program /usr/bin/gzip"

solved the problem. Everything is working now.
 
maybe you should do a which gzip or whence gzip and find the correct path to gzip

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
travs69, I am not familiar with 'which' or 'whence', can you shed some light on it?

Thanks.
 
just do a
which gzip
or a
whence gzip
one of those should show you the full path to gzip if it's there. "which" is more popular, both are unix commands but I'm sure at least one of them is on red hat I just don't have a RH box around to test.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
I see what you mean, I thought you meant within the script. I know where gzip is, I moved it to the same location that the script called for it at: /usr/bin instead of just editing the script and pointing it to the location on the ubuntu box.

I am no longer using red hat, I migrated the script to an Ubuntu box.
 
you better off leaving it where it is supposed to be and putting a symmlink in or editing the script. You can pass options to make to change those locations it looks for.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top