#!/usr/bin/env perl #-*- Mode: perl; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- # Determine the platform we're running on. # # Copyright (C) 2000-2001 Ximian, Inc. # # Authors: Arturo Espinosa # Hans Petter Jansson # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU Library General Public License as published # by the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Library General Public License for more details. # # You should have received a copy of the GNU Library General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. # --- System guessing --- # require "___scriptsdir___/parse.pl"; sub check_lsb { my ($ver, $dist); # xst_prefix not required here: parse already does that for us. $dist = lc (&xst_parse_sh ("/etc/lsb-release", "DISTRIB_ID")); $ver = lc (&xst_parse_sh ("/etc/lsb-release", "DISTRIB_RELEASE")); return -1 if ($dist eq "") || ($ver eq ""); return "$dist-$ver"; } sub check_debian { my $ver; open DEBIAN, "$xst_prefix/etc/debian_version" or return -1; chomp ($ver = ); close DEBIAN; return "debian-$ver"; } sub check_redhat { open RELEASE, "$xst_prefix/etc/redhat-release" or return -1; while () { chomp; if (/^Red Hat Linux.*\s+([0-9.]+)\s+.*/) { close RELEASE; return "redhat-$1"; } } close RELEASE; return -1; } sub check_caldera { open INSTALLED, "$xst_prefix/etc/.installed" or return -1; while () { chomp; if (/^OpenLinux-(.*)-.*/) { close INSTALLED; return "caldera-$1"; } } close INSTALLED; return -1; } sub check_suse { open RELEASE, "$xst_prefix/etc/SuSE-release" or return -1; while () { chomp; if (/^VERSION\s*=\s*(\S+)/) { close RELEASE; return "suse-$1"; } } close RELEASE; return -1; } sub check_mandrake { open MANDRAKE, "$xst_prefix/etc/mandrake-release" or return -1; while () { chomp; if (/^Linux Mandrake release (\S+)/) { close MANDRAKE; return "mandrake-$1"; } } close MANDRAKE; return -1; } sub check_turbolinux { open RELEASE, "$xst_prefix/etc/turbolinux-release" or return -1; while () { chomp; if (/release\s([0-9.]+)\s.*/) { close RELEASE; return "turbolinux-$1"; } } close RELEASE; return -1; } sub check_linuxppc { open RELEASE, "$xst_prefix/etc/redhat-release" or return -1; while () { chomp; if (/^LinuxPPC\s+(\S+)/) { close RELEASE; return "linuxppc-$1"; } } close RELEASE; return -1; } sub check_freebsd { my ($sysctl_cmd, @output); $sysctl_cmd = &xst_file_locate_tool ("sysctl"); @output = (readpipe("$sysctl_cmd -n kern.version")); foreach (@output) { chomp; if (/^FreeBSD\s(\S+)\.\S+.*/) { return "freebsd-$1"; } } return -1; } sub xst_platform_guess { my $dir = "___scriptsdir___"; if (! -f "$dir/system.guess") { system ("$dir/guess_system.sh 2> /dev/null > $dir/system.guess"); # FIXME: is this check for success correct? Taken from perlfunc. # NOTE: Don't need this check anymore. The system checks below are enough. # # if ($? >> 8) # { # &xst_report ("Couldn't guess system."); # return; # } } if (-f "$dir/system.guess") { open FILE, "$dir/system.guess"; } else { open FILE, "$dir/guess_system.sh 2>/dev/null |"; } chomp ($xst_system = ); close FILE; # set $xst_dist and $xst_dist_version if ($xst_system =~ /linux/) { # Red Hat check must run after Mandrake my @checks = (\&check_lsb, \&check_debian, \&check_caldera, \&check_suse, \&check_mandrake, \&check_linuxppc, \&check_redhat, \&check_turbolinux); my ($check, $dist); foreach $check (@checks) { $dist = &$check (); if ($dist != -1) { $xst_dist = $dist; return; } } $xst_dist = "unknown"; } if ($xst_system =~ /freebsdelf/) { my $dist; $dist = &check_freebsd (); if ($dist != -1) { $xst_dist = $dist; return; } $xst_dist = "unknown"; } } # xst_platform_ensure_supported # # Takes a list of supported platforms and sees if the one detected is found in # this list. If not, will report a list of supported platforms and fail. sub xst_platform_ensure_supported { my @supported = @_; for $platform (@supported) { if ($platform eq $xst_dist) { &xst_report ("platform_success", $platform); return; } } # Not supported. Now list the ones we do support, and die. foreach $platform (@supported) { &xst_report ("platform_list", $platform); } if ($xst_dist) { &xst_report ("platform_unsup", $xst_dist); if (!$xst_report_threshold && !$xst_verbose) { print STDERR "Fatal error: Your platform is not supported.\n"; } } else { &xst_report ("platform_undet"); if (!$xst_report_threshold && !$xst_verbose) { print STDERR "Fatal error: Unable to determine host platform.\n"; } } &xst_end (); exit (2); } 1;