[alt.sources.d] platform - determine Unix flavor from Bourne Shell

df@sei.cmu.edu (Dan Farmer) (01/17/91)

In article <foo>, meissner@osf.org (Michael Meissner) writes:
> In article <bar> sean@ms.uky.edu (Sean Casey)
> writes:
> | One thing that might be considered is using the output of "file" as
> | ran on a known executable.
> 
> However, even that can mislead you.  We discovered that the Mach 386
> a.out format uses the same magic number as the VAX.

  Sure, but it might give you a hint.  You could try combinations of the
methods mentioned; something like:

#!/usr/local/bin/perl
#
# plat-X
#
#   Attemps, in vain, to determine the platform -- great if we could get
# hardware and software (OS) base.  First shot at this -- wanted to do this
# for a while, then re-stolen from Todd Merriman's "platform".
#
# *might* work on Xenix/386, CTIX, 386/ix, DG/UX, SunOS, DYNIX, eta10's,
# ibm risc boxes, pyramids, decstations, etc.  Uses the arch, file, and
# uname commands to try to figure things out.  Vaxen and such will
# definitely not work.
#

if (-x "/bin/arch") {
    print `arch -k`;
    exit 0;
    }

if (-x "/bin/uname") {
    $type=`uname -m`;
        # Convergent S640
    if ($type eq "miti2") { print "CTIX\n"; exit 0; }
        # Sequent Interactive 386/ix and DYNIX
    elsif ($type eq "i386") {
        if (`uname -v` eq "DYNIX") { print "DYNIX\n"; exit 0; }
        else { print "386/ix\n"; exit 0; }
        }
        # DG/UX 88000
    elsif ($type eq "AViiON") { print "DG/UX\n"; exit 0; }
        # IBM's RISC/AIX
    elsif ($type eq "AIX") { print "IBM AIX\n"; exit 0; }
        # SCO Xenix
    elsif ($type eq "3") { print "Xenix/386\n"; exit 0; }
        # ETA 10
    elsif ($type =~ /ETA10/) { print "$type\n"; exit 0; }
    }

# locations of "file" executable?
@dirs = ("/bin", "/usr/bin");
$typical_executable="/bin/ls";
foreach $dir (@dirs) {
    if (-x "$dir/file" && -r "$dir/file") {
        $output=`$dir/file $typical_executable`;
        ($junk, $type, $more_junk) = split('\s', $output);
        if ($type eq "mipsel") { print "DECstation\n"; exit 0; }
        elsif ($type eq "90x") { print "Pyramid\n"; exit 0; }
        elsif ($type eq "SYMMETRY") { print "Sequent Symmetry\n"; exit 0; }
        else { print "$type???\n"; exit 0; }
        }
    }

exit 1;