mirror of
				https://github.com/xcat2/xcat-core.git
				synced 2025-10-31 19:32:31 +00:00 
			
		
		
		
	Merge pull request #76 from immarvin/master
fix defect ospkgs can not parse package groups in centos/rhel 5.x #65
This commit is contained in:
		| @@ -1,6 +1,5 @@ | ||||
| #!/bin/bash   | ||||
| # IBM(c) 2010 EPL license http://www.eclipse.org/legal/epl-v10.html | ||||
|  | ||||
| #------------------------------------------------------------------------------- | ||||
| #=head1  ospkgs | ||||
| #=head2  Used on Linux only. It installs/updates the rpms thta are from OS distro.  | ||||
| @@ -225,86 +224,90 @@ if [ "$KERNELDIR" != "" ]; then | ||||
|     OSPKGDIR="$OSPKGDIR,$KERNELDIR" | ||||
| fi  | ||||
|  | ||||
|     OIFS=$IFS | ||||
|     IFS=$',' | ||||
|     if ( pmatch "$OSVER" "ubuntu*" ); then | ||||
|         IFS=$(printf ',') | ||||
| OIFS=$IFS | ||||
| IFS=$',' | ||||
| if ( pmatch "$OSVER" "ubuntu*" ); then | ||||
|     IFS=$(printf ',') | ||||
| fi | ||||
|  | ||||
| array_ospkgdirs=($OSPKGDIR)    | ||||
|  | ||||
| #initialize the array "os_path" with all the valid repository paths  | ||||
| #under the directories specified in "OSPKGDIR" | ||||
|  | ||||
| array_empty os_path | ||||
| index=0 | ||||
| for dir in  ${array_ospkgdirs[@]}   | ||||
| do | ||||
|       | ||||
|     default_pkgdir="$INSTALLDIR/$OSVER/$ARCH" | ||||
|     OSPKGDIR="$OSPKGDIR"  | ||||
|     if [ $mounted -eq 0 ]; then | ||||
|         #OSPKGDIR="$OSPKGDIR"  | ||||
|         ospkgdir="$NFSSERVER$dir" | ||||
|     else  | ||||
|         ospkgdir="$dir" | ||||
|     fi | ||||
|  | ||||
|     array_ospkgdirs=($OSPKGDIR)    | ||||
|     IFS=$OIFS | ||||
|     array_empty os_path | ||||
|     index=0 | ||||
|     for dir in  ${array_ospkgdirs[@]}   | ||||
|     do | ||||
|           | ||||
|         default_pkgdir="$INSTALLDIR/$OSVER/$ARCH" | ||||
|         OSPKGDIR="$OSPKGDIR"  | ||||
|         if [ $mounted -eq 0 ]; then | ||||
|             #OSPKGDIR="$OSPKGDIR"  | ||||
|             ospkgdir="$NFSSERVER$dir" | ||||
|         else  | ||||
|             ospkgdir="$dir" | ||||
|      | ||||
|     # for the os base pkg dir(default_pkgdir) , there are some special cases. | ||||
|     # (1)for rhels6, there is one repodata in the os base dir; so keep it here, and handle the other cases below | ||||
|     # (2)for sles, we should specified the baseurl should be ./install/sles11/ppc64/1 | ||||
|     # (3)for SL5, we should append the /SL | ||||
|     # (4) for other os, we just keep it here. | ||||
|     # For other pkg paths, we just keep it here. | ||||
|     if [ $dir == $default_pkgdir ] || [ $dir == "$default_pkgdir/" ]; then | ||||
|         if ( pmatch "$OSVER" "sles*" ); then | ||||
|             OSPKGDIR="$OSPKGDIR/1" | ||||
|             ospkgdir="$ospkgdir/1" | ||||
|         elif ( pmatch "$OSVER" "SL5*" ); then | ||||
|             OSPKGDIR="$OSPKGDIR/SL" | ||||
|             ospkgdir="$ospkgdir/SL" | ||||
|         fi | ||||
|          | ||||
|         # for the os base pkg dir(default_pkgdir) , there are some special cases. | ||||
|         # (1)for rhels6, there is one repodata in the os base dir; so keep it here, and handle the other cases below | ||||
|         # (2)for sles, we should specified the baseurl should be ./install/sles11/ppc64/1 | ||||
|         # (3)for SL5, we should append the /SL | ||||
|         # (4) for other os, we just keep it here. | ||||
|         # For other pkg paths, we just keep it here. | ||||
|     fi | ||||
|     array_set_element os_path $index $ospkgdir | ||||
|       | ||||
|     if ( pmatch "$OSVER" "rhel*" ); then | ||||
|         #default_pkgdir="$INSTALLDIR/$OSVER/$ARCH" | ||||
|         if [ $dir == $default_pkgdir ] || [ $dir == "$default_pkgdir/" ]; then | ||||
|             if ( pmatch "$OSVER" "sles*" ); then | ||||
|                 OSPKGDIR="$OSPKGDIR/1" | ||||
|                 ospkgdir="$ospkgdir/1" | ||||
|             elif ( pmatch "$OSVER" "SL5*" ); then | ||||
|                 OSPKGDIR="$OSPKGDIR/SL" | ||||
|                 ospkgdir="$ospkgdir/SL" | ||||
|             fi | ||||
|         fi | ||||
|         array_set_element os_path $index $ospkgdir | ||||
|           | ||||
|         if ( pmatch "$OSVER" "rhel*" ); then | ||||
|             #default_pkgdir="$INSTALLDIR/$OSVER/$ARCH" | ||||
|             if [ $dir == $default_pkgdir ] || [ $dir == "$default_pkgdir/" ]; then | ||||
|            | ||||
|                 if ( pmatch "$OSVER" "rhels6*" ); then | ||||
|                    if [ $ARCH == "ppc64" ]; then | ||||
|                        ospkgdir_ok="$ospkgdir/Server" | ||||
|                        index=$(expr $index + 1)           | ||||
|                        array_set_element os_path $index $ospkgdir_ok | ||||
|                    fi                | ||||
|   | ||||
|                    if [ $ARCH == "x86_64" ]; then | ||||
|                         for arg in "Server" "ScalableFileSystem" "HighAvailability" "ResilientStorage" "LoadBalancer"  | ||||
|                         do | ||||
|                             ospkgdir_ok="$ospkgdir/$arg" | ||||
|                             index=$(expr $index + 1)           | ||||
|                             array_set_element os_path $index $ospkgdir_ok | ||||
|                         done | ||||
|                     fi                | ||||
|        | ||||
|             if ( pmatch "$OSVER" "rhels6*" ); then | ||||
|                if [ $ARCH == "ppc64" ]; then | ||||
|                    ospkgdir_ok="$ospkgdir/Server" | ||||
|                    index=$(expr $index + 1)           | ||||
|                    array_set_element os_path $index $ospkgdir_ok | ||||
|                fi                | ||||
|  | ||||
|                 elif ( pmatch "$OSVER" "rhels5*" ); then | ||||
|                      # for rhels5, the repodata is in ./Server, ./Cluster, ./CusterStorage, not in ./ | ||||
|                      ospkgdir_ok="$ospkgdir/Server" | ||||
|                      array_set_element os_path $index $ospkgdir_ok | ||||
|                 | ||||
|                      if [ $ARCH == "x86_64" ]; then | ||||
|                          for arg in "Cluster" "ClusterStorage" | ||||
|                          do | ||||
|                              ospkgdir_ok="$ospkgdir/$arg" | ||||
|                              index=$(expr $index + 1)           | ||||
|                              array_set_element os_path $index $ospkgdir_ok | ||||
|                          done | ||||
|                      fi   # x86_64 | ||||
|                 fi # if...elif..fi | ||||
|              fi  # eq default_pkgdir | ||||
|           fi    # match rhel* | ||||
|                if [ $ARCH == "x86_64" ]; then | ||||
|                     for arg in "Server" "ScalableFileSystem" "HighAvailability" "ResilientStorage" "LoadBalancer"  | ||||
|                     do | ||||
|                         ospkgdir_ok="$ospkgdir/$arg" | ||||
|                         index=$(expr $index + 1)           | ||||
|                         array_set_element os_path $index $ospkgdir_ok | ||||
|                     done | ||||
|                 fi                | ||||
|  | ||||
|           index=$(expr $index + 1)           | ||||
|              | ||||
|    done     | ||||
|             elif ( pmatch "$OSVER" "rhels5*" ); then | ||||
|                  # for rhels5, the repodata is in ./Server, ./Cluster, ./CusterStorage, not in ./ | ||||
|                  ospkgdir_ok="$ospkgdir/Server" | ||||
|                  array_set_element os_path $index $ospkgdir_ok | ||||
|             | ||||
|                  if [ $ARCH == "x86_64" ]; then | ||||
|                      for arg in "Cluster" "ClusterStorage" | ||||
|                      do | ||||
|                          ospkgdir_ok="$ospkgdir/$arg" | ||||
|                          index=$(expr $index + 1)           | ||||
|                          array_set_element os_path $index $ospkgdir_ok | ||||
|                      done | ||||
|                  fi   # x86_64 | ||||
|             fi # if...elif..fi | ||||
|          fi  # eq default_pkgdir | ||||
|       fi    # match rhel* | ||||
|  | ||||
|       index=$(expr $index + 1)           | ||||
|          | ||||
| done     | ||||
|  | ||||
| IFS=$OIFS | ||||
|   | ||||
|  | ||||
|  | ||||
| @@ -334,6 +337,7 @@ fi | ||||
|  | ||||
| pkgs=''  #packages | ||||
| groups=''   #groups | ||||
| groups_d=''   #groups to remove | ||||
| pkgs_d=''   #packages to remove | ||||
| cudapkgs='' #cuda pkg set | ||||
|  | ||||
| @@ -343,39 +347,57 @@ if ( pmatch "$OSVER" "ubuntu*" ); then | ||||
|     IFS=$(printf ',') | ||||
| fi | ||||
| pkgarray=($OSPKGS) | ||||
| IFS=$OIFS | ||||
|  | ||||
| #parse the pkglist file, categorize the pkglist entries according to  | ||||
| #the type(package/group/patterns) and action(install/remove) | ||||
| for x in ${pkgarray[@]}; | ||||
| do | ||||
|     #a flag indication the operation to current pkg/group | ||||
|     # 0:install;1:remove | ||||
|     remove=0 | ||||
|  | ||||
|     #remove leading and trailing spaces | ||||
|     x=`echo $x |sed 's/^ *//;s/ *$//'` | ||||
|     #echo "x=$x" | ||||
|     pos=`expr index  "$x" -` | ||||
|     if [ $pos -eq 1 ]; then  | ||||
| 	pkgs_d="$pkgs_d ${x#-}" | ||||
|     else | ||||
| 	pos=`expr index  "$x" @` | ||||
| 	if [ $pos -eq 1 ]; then  | ||||
| 	    #remove leading @ | ||||
| 	    tmp=${x#@} | ||||
|             #remove leading and trailing spaces | ||||
| 	    tmp=`echo $tmp |sed 's/^ *//;s/ *$//'` | ||||
|             #if there are spaces in the middle of the name, quote it | ||||
| 	    pos=`expr index "$tmp" "\ "` | ||||
| 	    if [ $pos -gt 0  ]; then | ||||
| 		groups="$groups \"$tmp\"" | ||||
| 	    else | ||||
| 		groups="$groups $tmp" | ||||
| 	    fi | ||||
| 	else | ||||
|             if ( pmatch  "$x" "cuda*" ); then | ||||
|                 cudapkgs="$cudapkgs $x"  | ||||
|             else | ||||
|                 pkgs="$pkgs $x" | ||||
|             fi | ||||
| 	fi | ||||
|        remove=1 | ||||
|        x=${x#-} | ||||
|     fi | ||||
|  | ||||
|     pos=`expr index  "$x" @` | ||||
|     if [ $pos -eq 1 ]; then  | ||||
|         #remove leading @ | ||||
|         tmp=${x#@} | ||||
|         #remove leading and trailing spaces | ||||
|         tmp=`echo $tmp |sed 's/^ *//;s/ *$//'` | ||||
|         #if there are spaces in the middle of the name, quote it | ||||
|         pos=`expr index "$tmp" "\ "` | ||||
|         if [ $pos -gt 0  ]; then | ||||
|            tmp="\"$tmp\"" | ||||
|         fi | ||||
|          | ||||
|         #categorize the groups according to the action(install/remove) | ||||
|         if [ $remove -eq 0 ]; then | ||||
|     	   groups="$groups $tmp" | ||||
|         else | ||||
|            groups_d="$groups_d $tmp" | ||||
|         fi | ||||
|     else | ||||
|         if ( pmatch  "$x" "cuda*" ); then | ||||
|             cudapkgs="$cudapkgs $x"  | ||||
|         else | ||||
|             #categorize the packages according to the action(install/remove) | ||||
|             if [ $remove -eq 0 ]; then | ||||
|                pkgs="$pkgs $x" | ||||
|             else | ||||
|                pkgs_d="$pkgs_d $x" | ||||
|             fi | ||||
|         fi | ||||
|     fi | ||||
|  | ||||
| done | ||||
| IFS=$OIFS | ||||
|  | ||||
| if [ $debug -ne 0 ]; then | ||||
|     echo "pkgs=$pkgs" | ||||
| @@ -383,9 +405,18 @@ if [ $debug -ne 0 ]; then | ||||
|         echo "cudapkgs=$cudapkgs" | ||||
|     fi | ||||
|     echo "groups=$groups" | ||||
|     echo "remove groups=$groups_d" | ||||
|     echo "remove pkgs=$pkgs_d" | ||||
| fi | ||||
|  | ||||
| #perform the software maintenance with the available package management tools, the process: | ||||
| #1.make sure the necessary package management tool is available  | ||||
| #2.enable all the available repositories and refresh the relevant metadata | ||||
| #3.upgrade all the existing packages | ||||
| #4.install specified package groups if any | ||||
| #5.install specified packages if any | ||||
| #6.remove specified package groups if any | ||||
| #7.remove specified packages if any | ||||
| if ( pmatch "$OSVER" "sles10*" ); then | ||||
|     #check if rug is installed | ||||
|     result=`rpm -q rug` | ||||
| @@ -643,6 +674,26 @@ elif ( pmatch "$OSVER" "sles*" ); then | ||||
| 	fi | ||||
|     fi | ||||
|  | ||||
|  | ||||
|      | ||||
|     #remove  patterns if any | ||||
|     if [ -n "$groups_d" ]; then | ||||
| 	cmd="$ENVLIST zypper remove -y  -t pattern $groups_d" | ||||
| 	result=`eval $cmd 2>&1` | ||||
|         R=$? | ||||
|         if [ $R -ne 0 ]; then | ||||
|             RETURNVAL=$R | ||||
| 	    logger -t xcat -p local4.info "ospkgs: $cmd\n    $result" | ||||
| 	    echo "ospkgs: $cmd" | ||||
| 	    echo $result | ||||
| 	else | ||||
| 	    if [ $debug -ne 0 ]; then | ||||
| 		echo "ospkgs: $cmd" | ||||
| 		echo $result | ||||
| 	    fi | ||||
| 	fi | ||||
|     fi | ||||
|  | ||||
|     #remove some packages if specified | ||||
|     if [ -n "$pkgs_d" ]; then | ||||
| 	cmd="$ENVLIST zypper remove -y $pkgs_d" | ||||
| @@ -728,6 +779,9 @@ elif ( pmatch "$OSVER" "ubuntu*" ); then | ||||
|                    RETURNVAL=$R | ||||
|                 fi | ||||
| 	fi | ||||
|    | ||||
|         #remove package group is not supported in ubuntu,  | ||||
|         #cause there is no  rpm-like "groups" supported by dpkg/apt | ||||
|  | ||||
| 	# install packages | ||||
| 	if [ -n "$pkgs" ]; then | ||||
| @@ -833,7 +887,8 @@ else | ||||
|  | ||||
|     #install new groups if any | ||||
|     if [ -n "$groups" ]; then | ||||
| 	cmd="echo $groups| $ENVLIST xargs yum -y groupinstall" | ||||
| 	#cmd="echo $groups| $ENVLIST xargs yum -y groupinstall" | ||||
| 	cmd="$ENVLIST yum -y groupinstall $groups" | ||||
| 	result=`eval $cmd 2>&1` | ||||
|         R=$? | ||||
|         if [ $R -ne 0 ]; then | ||||
| @@ -867,6 +922,24 @@ else | ||||
| 	fi | ||||
|     fi | ||||
|  | ||||
|     #remove some groups if specified | ||||
|     if [ -n "$groups_d" ]; then | ||||
|         cmd="$ENVLIST yum -y groupremove $groups_d" | ||||
|         result=`eval $cmd 2>&1` | ||||
|         R=$? | ||||
|         if [ $R -ne 0 ]; then | ||||
|            RETURNVAL=$R | ||||
|             logger -t xcat -p local4.info "ospkgs: $cmd\n    $result" | ||||
|             echo "ospkgs: $cmd" | ||||
|             echo $result | ||||
|         else | ||||
|             if [ $debug -ne 0 ]; then | ||||
|                 echo "ospkgs: $cmd" | ||||
|                 echo $result | ||||
|             fi | ||||
|         fi | ||||
|     fi | ||||
|  | ||||
|     #remove some rpms if specified | ||||
|     if [ -n "$pkgs_d" ]; then | ||||
| 	cmd="$ENVLIST yum -y remove $pkgs_d" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user