Subversion Repositories camp_sysinfo_client_3

Rev

Rev 123 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

#! /usr/bin/env perl

use strict;
use warnings;

# checks different things to try and figure out what operating system we are running
# pretty basic stuff, actually. Looks for the existence of a file or directory first.
# if it can not find one that matches, will then do a uname and attempt to locate a
# particular string in that.

# opnsense is freebsd, but does not have the same capabilities as freebsd, so we look for the file
# /conf/config.xml which appears to be uniq. We could also look for the /usr/local/opnsense directory
# if we don't find that, then we look in uname -a for debian or mx or devuan (it is a debian system),
# ipfire (it is an ipfire router) or freebsd (it is a freebsd system)

# returns a string (debian, ipfire, freebsd or opnsense) without a line return on success.
# on failure, returns an empty string and a failure return code

our $VERSION = '1.0';

my %osDefinitions = (
                  'debian' => {
                     'regex'  => '(debian|mx|devuan)',
                  },
                  'ipfire' => {
                     'regex'  => 'ipfire',
                  },
                  'freebsd' => {
                     'regex' => 'freebsd',
                  },
                  'opnsense' => {
                     'fileexists' => '/conf/config.xml',
                  },
                  
                );

# script which determines which operating system we are running on.
my $os = shift;
my $osType;
# first, look through our entries for fileexists
unless ( $os ) {
   foreach $osType ( keys %osDefinitions ) {
      next unless defined $osDefinitions{$osType}{'fileexists'};
      if (  -e $osDefinitions{$osType}{'fileexists'} ) {
         print $osType;
         exit;
      } # if
   } # foreach
} # unless
# next, look for uname and see if that gives us a clue
unless ( $os ) {
   my $osString = `uname -a`;
   foreach $osType ( keys %osDefinitions ) {
      next unless defined $osDefinitions{$osType}{'regex'};
      if ( $osString =~ m/$osDefinitions{$osType}{'regex'}/i ) {
         print $osType;
         exit;
      }
   } # foreach
} # unless
exit 0; # we were not able to determine operating system

Generated by GNU Enscript 1.6.5.90.