From 798f744bd6949c6b77e237f945962d5e5d97f55e Mon Sep 17 00:00:00 2001 From: Fred Gleason Date: Tue, 21 Jun 2016 20:36:32 -0400 Subject: [PATCH] 2016-06-21 Fred Gleason * Reimplemented 'get_distro.sh' as 'get_distro.pl'. --- ChangeLog | 2 + Makefile.am | 2 +- acinclude.m4 | 8 +-- get_distro.pl | 148 ++++++++++++++++++++++++++++++++++++++++++++++++++ get_distro.sh | 115 --------------------------------------- 5 files changed, 155 insertions(+), 120 deletions(-) create mode 100755 get_distro.pl delete mode 100755 get_distro.sh diff --git a/ChangeLog b/ChangeLog index e68089ed..e8e62583 100644 --- a/ChangeLog +++ b/ChangeLog @@ -15259,3 +15259,5 @@ 2016-06-18 Fred Gleason * Fixed a bug in 'xdg/Makefile.am' that caused the 'make rpm' target to break when HPI support was not enabled. +2016-06-21 Fred Gleason + * Reimplemented 'get_distro.sh' as 'get_distro.pl'. diff --git a/Makefile.am b/Makefile.am index 20937709..f58eb310 100644 --- a/Makefile.am +++ b/Makefile.am @@ -116,7 +116,7 @@ doxygen: EXTRA_DIST = autogen.sh\ build_win32.bat\ CODINGSTYLE\ - get_distro.sh\ + get_distro.pl\ get_target.sh\ install-init.sh\ make_slack.in\ diff --git a/acinclude.m4 b/acinclude.m4 index f7507397..2744f0e5 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -52,10 +52,10 @@ dnl AC_DEFUN([AR_GET_DISTRO],[] [ AC_MSG_CHECKING(distribution) - ar_distro_name=$(./get_distro.sh NAME $AWK) - ar_distro_version=$(./get_distro.sh VERSION $AWK) - ar_distro_major=$(./get_distro.sh MAJOR $AWK) - ar_distro_minor=$(./get_distro.sh MINOR $AWK) + ar_distro_name=$(./get_distro.pl NAME) + ar_distro_version=$(./get_distro.pl VERSION) + ar_distro_major=$(./get_distro.pl MAJOR) + ar_distro_minor=$(./get_distro.pl MINOR) AC_MSG_RESULT([$ar_distro_name $ar_distro_version]) ] ) diff --git a/get_distro.pl b/get_distro.pl new file mode 100755 index 00000000..7c03a220 --- /dev/null +++ b/get_distro.pl @@ -0,0 +1,148 @@ +#!/usr/bin/perl -W + +# get_distro.pl +# +# Try to determine the distribution name and version of the host machine. +# Used as part of the AR_GET_DISTRO() macro. +# +# (C) Copyright 2012,2016 Fred Gleason +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public +# License along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# + +#USAGE: get_distro.pl NAME|VERSION|MAJOR|MINOR|POINT + +if($ARGV[0] eq "NAME") { + if(!system("test","-f","/etc/SuSE-release")) { + print "SuSE"; + exit 0; + } + if(!system("test","-f","/etc/debian_version")) { + print "Debian"; + exit 0; + } + if(!system("test","-f","/etc/redhat-release")) { + print "RedHat"; + exit 0; + } +} + +if($ARGV[0] eq "VERSION") { + if(!system("test","-f","/etc/SuSE-release")) { + print &GetVersion("/etc/SuSE-release"); + exit 0; + } + if(!system("test","-f","/etc/debian_version")) { + print &GetVersion("/etc/debian_version"); + exit 0; + } + if(!system("test","-f","/etc/redhat-release")) { + print &GetVersion("/etc/redhat-release"); + exit 0; + } +} + +if($ARGV[0] eq "MAJOR") { + if(!system("test","-f","/etc/SuSE-release")) { + print &GetMajor("/etc/SuSE-release"); + exit 0; + } + if(!system("test","-f","/etc/debian_version")) { + print &GetMajor("/etc/debian_version"); + exit 0; + } + if(!system("test","-f","/etc/redhat-release")) { + print &GetMajor("/etc/redhat-release"); + exit 0; + } +} + +if($ARGV[0] eq "MINOR") { + if(!system("test","-f","/etc/SuSE-release")) { + print &GetMinor("/etc/SuSE-release"); + exit 0; + } + if(!system("test","-f","/etc/debian_version")) { + print &GetMinor("/etc/debian_version"); + exit 0; + } + if(!system("test","-f","/etc/redhat-release")) { + print &GetMinor("/etc/redhat-release"); + exit 0; + } +} + +if($ARGV[0] eq "POINT") { + if(!system("test","-f","/etc/SuSE-release")) { + print &GetPoint("/etc/SuSE-release"); + exit 0; + } + if(!system("test","-f","/etc/debian_version")) { + print &GetPoint("/etc/debian_version"); + exit 0; + } + if(!system("test","-f","/etc/redhat-release")) { + print &GetPoint("/etc/redhat-release"); + exit 0; + } +} + +exit 256; + + +sub GetVersion +{ + if(open VERSION,"<",$_[0]) { + my $version=; + my @f0=split " ",$version; + for(my $i=0;$i<@f0;$i++) { + my @f1=split "[.]",$f0[$i]; + if(@f1>1) { + return $f0[$i]; + } + } + } + return ""; +} + + +sub GetMajor +{ + my @f0=split "[.]",&GetVersion($_[0]); + + return $f0[0]; +} + + +sub GetMinor +{ + my @f0=split "[.]",&GetVersion($_[0]); + + if(@f0 ge 2) { + return $f0[1]; + } + return ""; +} + + +sub GetPoint +{ + my @f0=split "[.]",&GetVersion($_[0]); + + if(@f0 ge 3) { + return $f0[2]; + } + return ""; +} diff --git a/get_distro.sh b/get_distro.sh deleted file mode 100755 index 4dd7012c..00000000 --- a/get_distro.sh +++ /dev/null @@ -1,115 +0,0 @@ -#!/bin/bash - -# get_distro.sh -# -# Try to determine the distribution name and version of the host machine. -# Used as part of the AR_GET_DISTRO() macro. -# -# (C) Copyright 2012,2016 Fred Gleason -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU 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 General Public License for more details. -# -# You should have received a copy of the GNU General Public -# License along with this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -# - -case "$1" in - NAME) - if test -f /etc/SuSE-release ; then - echo -n "SuSE" - exit 0 - fi - if test -f /etc/debian_version ; then - echo -n "Debian" - exit 0 - fi - if test -f /etc/redhat-release ; then - echo -n "RedHat" - exit 0 - fi - if test `uname` = "Darwin" ; then - echo -n "OS X" - exit 0 - fi - echo -n "unknown" - ;; - VERSION) - if test -f /etc/SuSE-release ; then - cat /etc/SuSE-release | sed "/SE/ d;s/VERSION = //" - exit 0 - fi - if test -f /etc/debian_version ; then - cat /etc/debian_version - exit 0 - fi - if test -f /etc/redhat-release ; then - VER=`awk '/release/ {print $3}' /etc/redhat-release` - if test $VER = "release" ; then - VER=`awk '/release/ {print $4}' /etc/redhat-release` - fi - if test $VER = "Enterprise" ; then - VER=`awk '/release/ {print $7}' /etc/redhat-release` - fi - echo $VER - exit 0 - fi - if test `uname` = "Darwin" ; then - echo -n `uname -r` - exit 0 - fi - ;; - MAJOR) - if test -f /etc/SuSE-release ; then - cat /etc/SuSE-release | sed "/SE/ d;s/VERSION = //" | awk -F '.' '{print $1}' - exit 0 - fi - if test -f /etc/debian_version ; then - cat /etc/debian_version | awk -F '.' '{print $1}' - exit 0 - fi - if test -f /etc/redhat-release ; then - VER=`awk '/release/ {print $3}' /etc/redhat-release` - if test $VER = "release" ; then - VER=`awk '/release/ {print $4}' /etc/redhat-release` - fi - if test $VER = "Enterprise" ; then - VER=`awk '/release/ {print $7}' /etc/redhat-release` - fi - echo $VER | awk -F '.' '{print $1}' - exit 0 - fi - ;; - MINOR) - if test -f /etc/SuSE-release ; then - cat /etc/SuSE-release | sed "/SE/ d;s/VERSION = //" | awk -F '.' '{print $2}' - exit 0 - fi - if test -f /etc/debian_version ; then - cat /etc/debian_version | awk -F '.' '{print $2}' - exit 0 - fi - if test -f /etc/redhat-release ; then - VER=`awk '/release/ {print $3}' /etc/redhat-release` - if test $VER = "release" ; then - VER=`awk '/release/ {print $4}' /etc/redhat-release` - fi - if test $VER = "Enterprise" ; then - VER=`awk '/release/ {print $7}' /etc/redhat-release` - fi - echo $VER | awk -F '.' '{print $2}' - exit 0 - fi - ;; -esac - - -# End of get_distro.sh