简体   繁体   中英

Installation script in Perl not functioning correctly

I have a program that gets installed using the following Perl script. The installation does not work and I get the message"No installer found." Obviously, nothing was done as the script just simply dies.

Here is the Perl install script (it is for installing a program called Simics) :

#!/usr/bin/perl

use strict;
use warnings;

# Find the most recent installer in the current working directory.
my $installer;
my $highest_build = 0;
opendir my $d, "." or die $!;
foreach (readdir $d) {
    if (-f && -x && /^build-(\d+)-installer/) {
    if ($1 > $highest_build) {
        $highest_build = $1;
        $installer = $_;
    }
    }
}
closedir $d;

die "No installers found.\n" unless defined $installer;
exec "./$installer", @ARGV;

Stepping through your code above, this line:

foreach (readdir $d) {

reads the name of each of the files in the directory you opened to the handle "$d" and assigns each of those files in turn to the thing variable ($ ). (This variable is one of those weird but brilliant Perl idiosyncrasies. You don't have to mention $ in most cases; it's just there.)

Then in the next line:

if (-f && -x && /^build-(\d+)-installer/) {

The "-f" and the "-x" are file test operators . Since neither one has an explicit argument (eg, -f "myfile.txt") they will use the implied thing variable, $_. The -f operator just checks to see if something is a file and the -x checks to see if the file is executable, (as indicated by the executable bit being set.) The third part, /^build-(\\d+)-installer/, checks to see if it matches that pattern.

As you mentioned in your comment above, the directory listing shows

-rw------- 1 nikk nikk 52238 Feb 27 20:50 build-4607-installer.pl

The rw------- shows the file permissions for each of three groups, the owner ("nikk") and the group that owns the file (second "nikk"). The first three characters, starting with rw-, show that nikk can read and write from the file - but not execute. The listing would show rwx if nikk could execute the file. The next two groups of three characters, --- and --- show that neither the group nikk nor anyone else on the machine can read, write, or execute.

More information on Unix file system permissions

The lack of execute permission is causing the "-x" test to fail. There are two ways of fixing this. Either remove the -x from the if test so that it looks like this:

if (-f && /^build-(\d+)-installer/) {

Or add execute permission to the file. To do that just for the owner (assuming your program is running as user nikk or as root, do this:

chmod u+x build-4607-installer.pl

More information on chmod.

I hope that's helpful!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM