From cede69d8d74d1acee282edc6ba0c2b7014502a81 Mon Sep 17 00:00:00 2001 From: ericagar Date: Thu, 6 Oct 2011 17:45:08 +0000 Subject: [PATCH] Fix for defect 3419745: Fix Method to Determine if System is Ubuntu git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@10710 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- perl-xCAT/xCAT/Utils.pm | 36 +++++++++++++++++++++------- xCAT-server/lib/xcat/plugins/AAsn.pm | 24 +++++++++---------- xCAT-server/lib/xcat/plugins/ddns.pm | 14 +++++------ xCAT-server/lib/xcat/plugins/dhcp.pm | 8 +++---- xCAT-server/sbin/makenamed.conf | 29 +++++++++++++++++++++- xCAT-server/sbin/xcatconfig | 27 ++++++++++++++++++++- xCAT/postscripts/remoteshell | 3 +-- xCAT/postscripts/setupntp | 29 +++++++++++++++++++++- xCAT/postscripts/syslog | 33 ++++++++++++++++++++++--- 9 files changed, 163 insertions(+), 40 deletions(-) diff --git a/perl-xCAT/xCAT/Utils.pm b/perl-xCAT/xCAT/Utils.pm index 184b14191..c68885b7c 100644 --- a/perl-xCAT/xCAT/Utils.pm +++ b/perl-xCAT/xCAT/Utils.pm @@ -4925,17 +4925,35 @@ sub osver $ver =~ tr/\.//; $ver =~ s/[^0-9]*([0-9]+).*/$1/; } - elsif (-f "/etc/lsb-release")#ubuntu + elsif (-f "/etc/lsb-release") # Possibly Ubuntu { - $os = "ubuntu"; - open($relfile,"<","/etc/lsb-release"); - my @text = <$relfile>; - close($relfile); - foreach (@text){ - if ( $_ =~ /DISTRIB_RELEASE=(\S+)/ ) { - $ver = $1; - } + if (open($relfile,"<","/etc/lsb-release")) { + my @text = <$relfile>; + close($relfile); + chomp(@text); + my $distrib_id = ''; + my $distrib_rel = ''; + + foreach (@text) { + if ( $_ =~ /^\s*DISTRIB_ID=(.*)$/ ) { + $distrib_id = $1; # last DISTRIB_ID value in file used + } elsif ( $_ =~ /^\s*DISTRIB_RELEASE=(.*)$/ ) { + $distrib_rel = $1; # last DISTRIB_RELEASE value in file used + } + } + + if ( $distrib_id =~ /^(Ubuntu|"Ubuntu")\s*$/ ) { + $os = "ubuntu"; + + if ( $distrib_rel =~ /^(.*?)\s*$/ ) { # eliminate trailing blanks, if any + $distrib_rel = $1; + } + if ( $distrib_rel =~ /^"(.*?)"$/ ) { # eliminate enclosing quotes, if any + $distrib_rel = $1; + } + $ver = $distrib_rel; + } } } $os = "$os" . "$ver"; diff --git a/xCAT-server/lib/xcat/plugins/AAsn.pm b/xCAT-server/lib/xcat/plugins/AAsn.pm index 2bdd0a2bb..6436383b3 100644 --- a/xCAT-server/lib/xcat/plugins/AAsn.pm +++ b/xCAT-server/lib/xcat/plugins/AAsn.pm @@ -654,12 +654,12 @@ sub setup_DHCP ${"xCAT_plugin::" . $modname . "::"}{process_request} ->($cmdref, \&xCAT::Client::handle_response); + my $distro = xCAT::Utils->osver(); + my $serv = "dhcpd"; + if ( $distro =~ /ubuntu.*/ ){ + $serv = "dhcp3-server"; + } - my $distro = xCAT::Utils->osver(); - my $serv = "dhcpd"; - if ( $distro =~ /ubuntu*/ ){ - $serv = "dhcp3-server"; - } my $rc = xCAT::Utils->startService($serv); if ($rc != 0) { @@ -781,13 +781,13 @@ sub setup_DNS system("$XCATROOT/sbin/makenamed.conf"); # turn DNS on - - my $distro = xCAT::Utils->osver(); - my $serv = "named"; - if ( $distro =~ /ubuntu*/ ){ - $serv = "bind9"; - } - + + my $distro = xCAT::Utils->osver(); + my $serv = "named"; + if ( $distro =~ /ubuntu.*/ ){ + $serv = "bind9"; + } + my $rc = xCAT::Utils->startService($serv); if ($rc != 0) { diff --git a/xCAT-server/lib/xcat/plugins/ddns.pm b/xCAT-server/lib/xcat/plugins/ddns.pm index 198c9cd8e..10c9af56e 100644 --- a/xCAT-server/lib/xcat/plugins/ddns.pm +++ b/xCAT-server/lib/xcat/plugins/ddns.pm @@ -19,8 +19,8 @@ my $distro = xCAT::Utils->osver(); my $service="named"; # is this ubuntu ? -if ( $distro =~ /ubuntu*/ ){ - $service = "bind9"; +if ( $distro =~ /ubuntu.*/ ){ + $service = "bind9"; } sub handled_commands @@ -547,11 +547,11 @@ sub get_zonesdir { sub get_conf { my $conf="/etc/named.conf"; - # is this ubuntu ? - if ( $distro =~ /ubuntu*/ ){ - $conf="/etc/bind/named.conf"; - } - + # is this ubuntu ? + if ( $distro =~ /ubuntu.*/ ){ + $conf="/etc/bind/named.conf"; + } + my $sitetab = xCAT::Table->new('site'); unless ($sitetab) diff --git a/xCAT-server/lib/xcat/plugins/dhcp.pm b/xCAT-server/lib/xcat/plugins/dhcp.pm index 806f32ba9..e9b27f350 100644 --- a/xCAT-server/lib/xcat/plugins/dhcp.pm +++ b/xCAT-server/lib/xcat/plugins/dhcp.pm @@ -62,8 +62,8 @@ if ( $^O ne 'aix' and -d "/etc/dhcp" ) { my $usingipv6; # is this ubuntu ? -if ( $distro =~ /ubuntu*/ ){ - $dhcpconffile = '/etc/dhcp3/dhcpd.conf'; +if ( $distro =~ /ubuntu.*/ ){ + $dhcpconffile = '/etc/dhcp3/dhcpd.conf'; } sub check_uefi_support { @@ -1402,9 +1402,9 @@ sub process_request { restart_dhcpd_aix(); } - elsif ( $distro =~ /ubuntu*/) + elsif ( $distro =~ /ubuntu.*/) { - #ubuntu config + #ubuntu config system("chmod a+r /etc/dhcp3/dhcpd.conf"); system("/etc/init.d/dhcp3-server restart"); } diff --git a/xCAT-server/sbin/makenamed.conf b/xCAT-server/sbin/makenamed.conf index bbfb7b38a..6264facb2 100755 --- a/xCAT-server/sbin/makenamed.conf +++ b/xCAT-server/sbin/makenamed.conf @@ -1,5 +1,32 @@ #!/bin/sh +# is_lsb_ubuntu exit status indicates whether system appears to be Ubuntu. +# Using required /etc/lsb-release file, instead of optional lsb_release command. + +is_lsb_ubuntu () +{ + awk ' + (match($0, "^[ \t]*DISTRIB_ID=") == 1) { # A DISTRIB_ID line + id = substr($0, RLENGTH + 1) # Save its value + } + + END { + # Examine last DISTRIB_ID value to see if Ubuntu indicated + + if (match(id, "^(Ubuntu|\"Ubuntu\")[ \t]*$") == 1) { + exit 0 # Ubuntu + } + exit 1 # Not Ubuntu + } + + ' /etc/lsb-release >/dev/null 2>&1 + + # Routine exit status is exit status of the last command -- the awk script. + # + # Note: if /etc/lsb-release does not exist, the exit status indicates + # failure (not Ubuntu), which is the correct outcome. +} + DIRECTORY=/var/named @@ -8,7 +35,7 @@ if [ -f /etc/SuSE-release ]; then fi FILE=/etc/named.conf -if [ -f /etc/lsb-release ]; then +if ( is_lsb_ubuntu ); then FILE=/etc/bind/named.conf fi diff --git a/xCAT-server/sbin/xcatconfig b/xCAT-server/sbin/xcatconfig index eedfff03f..55f8e0136 100755 --- a/xCAT-server/sbin/xcatconfig +++ b/xCAT-server/sbin/xcatconfig @@ -831,6 +831,31 @@ sub genSSHNodeHostKey } } +# is_lsb_ubuntu return value indicates whether system appears to be Ubuntu. +# Using required /etc/lsb-release file, instead of optional lsb_release command. + +sub is_lsb_ubuntu +{ + if (open(my $relfile, "<", "/etc/lsb-release")) { + my @text = <$relfile>; + close($relfile); + chomp(@text); + my $distrib_id = ''; + + foreach (@text) { + if ( $_ =~ /^\s*DISTRIB_ID=(.*)$/ ) { + $distrib_id = $1; # last DISTRIB_ID value in file used + } + } + + if ( $distrib_id =~ /^(Ubuntu|"Ubuntu")\s*$/ ) { + return 1; # return "true" + } + } + + return 0; # return "false" +} + # on Ubuntu need to painstakingly compare /etc/localtime with files under # /usr/share/zoneinfo since /etc/localtime # isn't always a symbolic link sub discover_timezone_ubuntu @@ -942,7 +967,7 @@ sub initDB $tz = `grep ^ZONE /etc/sysconfig/clock|cut -d= -f 2|sed -e 's/"//g'`; } - elsif (-f "/etc/lsb-release") + elsif ( is_lsb_ubuntu() ) { $tz = discover_timezone_ubuntu; } diff --git a/xCAT/postscripts/remoteshell b/xCAT/postscripts/remoteshell index 0166103a1..903fde515 100755 --- a/xCAT/postscripts/remoteshell +++ b/xCAT/postscripts/remoteshell @@ -146,8 +146,7 @@ fi # start up the sshd for syncfiles postscript to do the sync work logger -t xCAT "start up sshd" -DISTRO=`lsb_release -si` -if [ $DISTRO = "Ubuntu" ] +if [[ $OSVER == ubuntu* ]] then if [ ! -d /var/run/sshd ] then diff --git a/xCAT/postscripts/setupntp b/xCAT/postscripts/setupntp index 28cad51b4..b2ef081a6 100755 --- a/xCAT/postscripts/setupntp +++ b/xCAT/postscripts/setupntp @@ -23,6 +23,33 @@ pmatch () return 1 # non-zero return code means string not matched by pattern } +# is_lsb_ubuntu exit status indicates whether system appears to be Ubuntu. +# Using required /etc/lsb-release file, instead of optional lsb_release command. + +is_lsb_ubuntu () +{ + awk ' + (match($0, "^[ \t]*DISTRIB_ID=") == 1) { # A DISTRIB_ID line + id = substr($0, RLENGTH + 1) # Save its value + } + + END { + # Examine last DISTRIB_ID value to see if Ubuntu indicated + + if (match(id, "^(Ubuntu|\"Ubuntu\")[ \t]*$") == 1) { + exit 0 # Ubuntu + } + exit 1 # Not Ubuntu + } + + ' /etc/lsb-release >/dev/null 2>&1 + + # Routine exit status is exit status of the last command -- the awk script. + # + # Note: if /etc/lsb-release does not exist, the exit status indicates + # failure (not Ubuntu), which is the correct outcome. +} + logger -t xcat "Install: Setup NTP" # if master is the sitemaster, then use the ntpservers defined in the site # table, if they exist. If they don't exist, do not setup ntp @@ -73,7 +100,7 @@ restrict 127.0.0.1" >>$conf_file # default service for redhat/fedora SERVICE=ntpd echo $SERVICE -if ( pmatch $OSVER "sles*" ) || ( pmatch $OSVER "suse*" ) || [ -f /etc/SuSE-release ] || ( pmatch $OSVER "ubuntu*" ); then +if ( pmatch $OSVER "sles*" ) || ( pmatch $OSVER "suse*" ) || [ -f /etc/SuSE-release ] || ( pmatch $OSVER "ubuntu*" ) || ( is_lsb_ubuntu ); then SERVICE=ntp fi diff --git a/xCAT/postscripts/syslog b/xCAT/postscripts/syslog index dc903ff9f..5d1ed1fc9 100755 --- a/xCAT/postscripts/syslog +++ b/xCAT/postscripts/syslog @@ -35,6 +35,33 @@ pmatch () return 1 # non-zero return code means string not matched by pattern } +# is_lsb_ubuntu exit status indicates whether system appears to be Ubuntu. +# Using required /etc/lsb-release file, instead of optional lsb_release command. + +is_lsb_ubuntu () +{ + awk ' + (match($0, "^[ \t]*DISTRIB_ID=") == 1) { # A DISTRIB_ID line + id = substr($0, RLENGTH + 1) # Save its value + } + + END { + # Examine last DISTRIB_ID value to see if Ubuntu indicated + + if (match(id, "^(Ubuntu|\"Ubuntu\")[ \t]*$") == 1) { + exit 0 # Ubuntu + } + exit 1 # Not Ubuntu + } + + ' /etc/lsb-release >/dev/null 2>&1 + + # Routine exit status is exit status of the last command -- the awk script. + # + # Note: if /etc/lsb-release does not exist, the exit status indicates + # failure (not Ubuntu), which is the correct outcome. +} + config_Rsyslog_C3() { isReceiving=0 @@ -85,7 +112,7 @@ if [ $NTYPE = service ]; then fi if [ "$(uname -s)" = "Linux" ]; then - if ( pmatch $OSVER "fedora*" ) || ( pmatch $OSVER "rhels5*" ) || ( pmatch $OSVER "rhel6*" ) || ( pmatch $OSVER "rhels6*" ) || [ -f /etc/fedora-release ] || [ -f /etc/redhat-release ] || ( pmatch $OSVER "ubuntu*" ); then + if ( pmatch $OSVER "fedora*" ) || ( pmatch $OSVER "rhels5*" ) || ( pmatch $OSVER "rhel6*" ) || ( pmatch $OSVER "rhels6*" ) || [ -f /etc/fedora-release ] || [ -f /etc/redhat-release ] || ( pmatch $OSVER "ubuntu*" ) || ( is_lsb_ubuntu ); then if [ -e /etc/rsyslog.conf ]; then conf_file="/etc/rsyslog.conf" sysconfig="/etc/sysconfig/rsyslog" @@ -207,7 +234,7 @@ else #Ubuntu doesn't have sysconfig # so configuring the MN to receive UDP connections here. - if ( pmatch $OSVER "ubuntu*" ); then + if ( pmatch $OSVER "ubuntu*" ) || ( is_lsb_ubuntu ); then egrep \('^\$UDPServerRun 514'\|'^\$ModLoad imudp'\) $conf_file > /dev/null 2>&1; if [ $? -eq 1 ]; then echo "\$ModLoad imudp" >> $conf_file; @@ -238,7 +265,7 @@ else if [ $isLinux -eq 0 ]; then echo "*.debug @$master" >> $conf_file else - if ( pmatch $OSVER "ubuntu*" ); then + if ( pmatch $OSVER "ubuntu*" ) || ( is_lsb_ubuntu ); then echo "\$ModLoad imuxsock" >> $conf_file echo "*.* @$master" >> $conf_file else