Fix whitespace irregularities in code
[xapian.git] / xapian-core / tests / perftest / get_machine_info.in
blob46a493293a433d3816261f81b3dd3d0d61051247
1 #!@PERL@
2 BEGIN{$^W = 1} # equivalent of -w
3 # -*- Mode: perl; indent-tabs-mode: nil -*-
5 # This script does not need to run under taint perl.
7 # This script is derived from a generic build script for tinderbox.  It will
8 # display, on stdout, details of the OS and distribution in use.
10 # The contents of this file are subject to the Mozilla Public
11 # License Version 1.1 (the "License"); you may not use this file
12 # except in compliance with the License. You may obtain a copy of
13 # the License at http://www.mozilla.org/NPL/
15 # Software distributed under the License is distributed on an "AS
16 # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
17 # implied. See the License for the specific language governing
18 # rights and limitations under the License.
20 # The Original Code is the Tinderbox build tool.
22 # The Initial Developer of the Original Code is Netscape Communications
23 # Corporation. Portions created by Netscape are
24 # Copyright (C) 1998 Netscape Communications Corporation. All
25 # Rights Reserved.
27 # complete rewrite by Ken Estes, Mail.com (kestes@staff.mail.com).
28 # Contributor(s):
30 # $Revision: 1.14 $
31 # $Date: 2002/01/02 18:09:59 $
32 # $Author: kestes%walrus.com $
33 # $Name:  $
35 use strict;
37 sub run_command {
38     my $cmd;
39     if (scalar @_ == 1) {
40         $cmd = $_[0];
41     } else {
42         my %a = @_;
43         $cmd = $a{String};
44     }
45     my $out = `$cmd`;
46     chomp $out;
47     return wantarray ? split /\n/, $out : $out;
50 my $OS = $^O;
52 my $distro = '';
53 if (lc $OS eq "linux") {
54     if (open F, "/etc/debian_version") {
55         # e.g. "3.0"
56         chomp($_ = <F>);
57         $distro = "Debian $_";
58         if (open F, "/etc/lsb-release") {
59             # For Ubuntu (derived from Debian)
60             my ($id, $release, $codename, $desc);
61             while (<F>) {
62                 if (/^DISTRIB_ID=(.+)/) {
63                     $id = $1;
64                 } elsif (/^DISTRIB_RELEASE=(.+)/) {
65                     $release = $1;
66                 } elsif (/^DISTRIB_CODENAME=(.+)/) {
67                     $codename = $1;
68                 } elsif (/^DISTRIB_DESCRIPTION=(.+)/) {
69                     $desc = $1;
70                 }
71             }
72             if (defined $id) {
73                 $distro = $id;
74                 if (defined $codename) {
75                     $distro .= " $codename";
76                 } elsif (defined $release) {
77                     $distro .= " $release";
78                 } elsif (defined $codename) {
79                     $distro = $codename;
80                 }
81             }
82         }
83     } elsif (open F, "/etc/redhat-release") {
84         # e.g. "Red Hat Linux release 7.2 (Enigma)"
85         # or "Red Hat Enterprise Linux AS release 3 (Taroon Update 1)"
86         # or "Red Hat Enterprise Linux ES release 3 (Taroon Update 3)"
87         chomp($_ = <F>);
88         if (/^Red Hat Enterprise Linux ([AE]S) release ([0-9]\S*)\b/) {
89             $distro = "RHEL_$1 $2";
90         } elsif (/^Fedora Core release ([0-9]\S*)\b/) {
91             $distro = "FC $1";
92         } elsif (/^(.+) release ([0-9]\S*)\b/) {
93             $distro = "$1 $2";
94         } else {
95             /(\b[0-9]\S*)/;
96             $distro = "RH $1";
97         }
98     } elsif (open F, "/etc/SuSE-release") {
99         # e.g. "SuSE Linux 8.1 (i386)" "VERSION = 8.1"
100         <F>;
101         chomp($_ = <F>);
102         /VERSION *= *(.*)/;
103         $distro = "SuSE $1";
104     } elsif (open F, "/etc/gentoo-release") {
105         # e.g. "Gentoo Base System version 1.4.2.8"
106         chomp($_ = <F>);
107         /(\b[0-9]\S*)/;
108         $distro = "Gentoo $1";
109     } elsif (open F, "/etc/slackware-version") {
110         # e.g. "Slackware 9.1.0"
111         chomp($_ = <F>);
112         /(\b[0-9]\S*)/;
113         $distro = "Slackware $1";
114     }
115     close F;
116 } elsif (lc $OS eq "darwin") {
117     $distro = join(' ', run_command("/usr/bin/sw_vers 2>/dev/null|sed 's/^Product[A-Za-z]*: *//p;d'"));
118     $distro =~ s/\s+/ /g;
119     $distro =~ s/^ //;
120     $distro =~ s/ $//;
123 my $version;
124 my $uname_m;
125 if (lc $OS eq "MSWin32") {
126     require Win32;
127     import Win32;
128     $distro = Win32::GetOSName();
129     $version = Win32::GetOSVersion();
130     $uname_m = '';
131 } else {
132     $version = run_command("uname -r");
133     $uname_m = run_command("uname -m");
136 my $SERVER_BUILD_NAME;
137 $SERVER_BUILD_NAME = "$OS $distro $version $uname_m";
138 $SERVER_BUILD_NAME =~ s/\n/ /g;
139 $SERVER_BUILD_NAME =~ s/^ +//;
140 $SERVER_BUILD_NAME =~ s/ +$//;
141 $SERVER_BUILD_NAME =~ s!/!_!g; # tinderbox doesn't like /
142 print $SERVER_BUILD_NAME;