File patterns-server-monitoring.spec of Package patterns-server-monitoring

#
# spec file for package patterns-server-monitoring
#
# This file and all modifications and additions to the pristine
# package are under the same license as the package itself.
#

# norootforbuild

Name:           patterns-server-monitoring
License:        GPL-2.0+
Group:          Metapackages
Summary:        Patterns for the server:monitoring project
Version:        1.0
Release:        0
Url:            http://en.opensuse.org/server:monitoring
AutoReqProv:    off
Source:         %name.tar.bz2
Source1:        patterns-server-monitoring-rpmlintrc
Source2:        EXTRA_PROV
BuildRequires:  coreutils
%if 0%{?suse_version} > 1020
BuildRequires:  gzip
%endif
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
# The name below will be added as global pattern name 
# in the comment header of each pattern file.
# So you can choose a "generic" one to identify all 
# your patterns later
%define         global_name "Monitoring"

# since openSUSE 11.0 all patterns are collected in 
# one big pattern file - so this name must be different 
# from the ones in the tarball
%define         all_in_one_pattern_name all-%{name}

# if you need 32bit packages (and patterns), 
# set the macro below to 1
%define         create_xxbit_pattern 0

# to get a list of all packages for product config, define 1 below
%define         create_packagelist 1

# FYI: "Ord" must be unique - so we must have one for each pattern file
# and architecture. You only need to define the first number (for
# i386 - the rest should be done automatically.

%description
Pattern files for the Server:Monitoring Add on CD.

%prep
%setup -q -n %name

%build

%install
#
# Enviroment
#
rm -Rf %buildroot
mkdir %buildroot
mkdir -p %buildroot/CD1/suse/setup/descr
mkdir -p %buildroot/%_datadir/%name/repodata
install -m644 %{SOURCE2} %buildroot/CD1/suse/setup/descr/

#
# Patterns
#
TMPFILE=`mktemp /tmp/%{name}-XXXXXX`
YEAR=`date "+%Y"`

# EXTENSION defines xxbit packages (and patterns)
EXTENSION=""

function create_pattern(){
  for patname in $(ls -d *); do
    test -f $TMPFILE && rm $TMPFILE
    pushd $patname 1>/dev/null

	# Ordernumber must defined and unique
	ORDERNUMBER=$(cat Ord)
	if [ x"$ORDERNUMBER" = x"" ]; then
		echo "Ordernumber not defined"
		exit 1
	fi
	# EXTENSION defines xxbit packages (and patterns)
	%ifarch ia64
	  ORDERNUMBER=$((ORDERNUMBER+1))
	%endif
	%ifarch ppc
	  ORDERNUMBER=$((ORDERNUMBER+2))
	%endif
	%ifarch ppc64
	  ORDERNUMBER=$((ORDERNUMBER+3))
	%endif
	%ifarch s390x
	  ORDERNUMBER=$((ORDERNUMBER+4))
	%endif
	%ifarch x86_64
	  ORDERNUMBER=$((ORDERNUMBER+5))
	%endif
	if [ "$EXTENSION" != "" ]; then
		# TODO: is this really necessary ?
		ORDERNUMBER=$((ORDERNUMBER+10))
	fi

    pat="${patname}${EXTENSION}-%{version}-%{release}.%{_target_cpu}.pat"
    target="%buildroot/CD1/suse/setup/descr/$pat"
    xmltarget="%buildroot/%{_datadir}/%name/repodata/$patname${EXTENSION}"
    kiwiinclude="%buildroot/%{_datadir}/%name/kiwi-include-$patname${EXTENSION}.xml"

	#############################
	#     generation starts
	#############################

    #
    # the "normal" patterns for the media
    #
	# top header
	echo "# %{global_name} Pattern %{version}${EXTENSION}-%{release}.%{_target_cpu} -- (c) $YEAR %{vendor}" > $target
	echo -n "# generated on " >> $target
	date >> $target
	echo >> $target
	echo "=Ver: 5.0" >> $target
	echo >> $target
	echo "=Pat: ${EXTENSION#-*} $patname %{version} %{release} %{_target_cpu}" >> $target
	# Category, summary and description must be present
    for tag in Cat Ico Sum Vis Ord; do
        if [ -f $tag ]; then
            echo >> $target
            echo -n "=${tag}: " >> $target
            cat $tag >> $target
        fi
    done
	if [ -f Des ]; then
		echo >> $target
		echo "+Des:" >> $target
		cat Des >> $target
		echo "-Des:" >> $target
	fi
	# now the translations
	# for supported languages see: https://forgesvn1.novell.com/svn/suse-i18n/trunk/yast/
	for tag in $(ls Cat.*); do
        echo >> $target
        echo -n "=${tag}: " >> $target
        cat $tag >> $target
	done
	for tag in $(ls Sum.*); do 
    	echo >> $target
    	echo -n "=${tag}: " >> $target
    	cat $tag >> $target
	done
	for tag in $(ls Des.*); do
		echo >> $target
        echo "+${tag}:" >> $target
        cat $tag >> $target
	    echo "-${tag}:" >> $target
	done
	# the interesting part: dependencies
    for tag in Fre Prv Req Rec Con Ext Inc Obs Sug Sup Prc Prq Psg; do
      test -f $TMPFILE && rm $TMPFILE
	  test -f ${TMPFILE}2 && rm ${TMPFILE}2
      if [ -f "$tag" ]; then
        sort -u $tag > $TMPFILE
	  fi
	  # check if there is a file like "Prc+i586"
	  # packages listed in this file should be added 
	  # to the Tag if the pattern is build for i586
	  if [ -f "${tag}+%{_target_cpu}" ]; then
		sort -u ${tag}+%{_target_cpu} >> $TMPFILE
	  fi
	  # check if there is a file like "Prc-x86_64"
	  # packages listed in this file should be removed
	  # from the Tag if the pattern is build for x86_64
	  if [ -f "${tag}-%{_target_cpu}" ]; then
		for i in $(cat ${tag}-%{_target_cpu}); do
			grep -vw $i $TMPFILE > ${TMPFILE}2
			mv ${TMPFILE}2 $TMPFILE
		done
	  fi
	  # now get it all together
	  # whatch for packages with version informations
	  # "kernel-default >= 2.6.25" for example
	  if [ -f "${TMPFILE}" ]; then
		echo >> $target
		echo "+${tag}:" >> $target
	  	sort -u ${TMPFILE} | while read a b;
	  	do
			if [ x"$b" = x"" ]; then
				echo "${a}${EXTENSION}"
			else
	        	echo "${a}${EXTENSION} $b"
			fi
		done >> $target
        echo "-${tag}:" >> $target
      fi
      if [ "$EXTENSION" != "" ]; then
		if [ ! -f ${tag} ]; then
			case ${tag} in 
				Sup)
					echo "+${tag}:" >> $target
					echo "${EXTENSION}" >> $target
					echo "-${tag}:" >> $target
				;;
				Fre)
					echo "+${tag}:" >> $target
					echo "${patname}" >> $target
					echo "-${tag}:" >> $target
				;;
			esac
		fi
	  fi
    done
    #
    # now the xml pattern for buildservice
    #
	echo "<pattern" >> $xmltarget
	echo " xmlns=\"http://novell.com/package/metadata/suse/pattern\"" >> $xmltarget
	echo " xmlns:rpm=\"http://linux.duke.edu/metadata/rpm\">" >> $xmltarget
    # Pattern name
    if [ -f Sum ]; then
        echo -n " <name>" >> $xmltarget
        cat Sum | tr -d "\n" >> $xmltarget
        echo "</name>" >> $xmltarget  
    else
        echo " <name>$patname</name>" >> $xmltarget
    fi
	# Summary
	if [ -f Sum ]; then
	  echo -n " <summary>" >> $xmltarget
	  cat Sum | tr -d "\n" >> $xmltarget
	  echo " </summary>" >> $xmltarget
#	  for i in $(ls Sum.*); do
#		if [ -f $i ]; then
#			echo -n " <summary lang=\"${i/Sum./}\">" >> $xmltarget
#			cat $i | tr -d "\n" >> $xmltarget
#			echo " </summary>" >> $xmltarget
#		fi
#	  done
	fi
	# Description
	if [ -f Des ]; then
	  echo -n " <description>" >> $xmltarget
	  cat Des | tr -d "\n" >> $xmltarget
	  echo " </description>"  >> $xmltarget
#	  for i in $(ls Des.*); do
#	      echo -n " <description lang=\"${i/Des./}\">" >> $xmltarget
#		  cat $i | tr -d "\n" >> $xmltarget
#          echo " </description>"  >> $xmltarget
#	  done
	fi
	# Visible
	if [ "$(cat Vis)" == "true" ]; then
		echo " <uservisible/>" >> $xmltarget
	fi
	# Category
	if [ -f Cat ]; then 
	  echo -n " <category>" >> $xmltarget
	  cat Cat | tr -d "\n" >> $xmltarget
	  echo " </category>" >> $xmltarget
#	  for i in $(ls Cat.*); do
#		echo -n " <category lang=\"${i/Cat./}\">" >> $xmltarget
#		cat $i | tr -d "\n" >> $xmltarget
#		echo " </category>" >> $xmltarget
#	  done
	fi

	# the interesting part: dependencies
    for tag in Prv Req Rec Con Ext Fre Inc Obs Sug Sup Prc Prq Psg; do
		if [ -f $tag ]; then
			case $tag in 
				Prv)
				TAG="rpm:provides"
				KIND="pattern"
				;;
				Req)
				TAG="rpm:requires"
				KIND="pattern"
				;; 
				Rec)
				TAG="rpm:recommends"
				KIND="pattern"
				;;
				Con)
				TAG="rpm:conflicts"
				KIND="pattern"
				;;
				Ext)
				TAG="rpm:extends"
				KIND="pattern"
				;;
				Fre)
				TAG="rpm:freshens"
				KIND="pattern"
				;;
				Inc) 
				TAG="rpm:freshens"
				KIND="pattern"
				;;
				Obs) 
				TAG="rpm:obsoletes"
				KIND="pattern"
				;;
				Sug) 
				TAG="rpm:suggests"
				KIND="pattern"
				;;
				Sup) 
				TAG="rpm:supplements"
				KIND="pattern"
				;;
				Prc) 
				TAG="rpm:recommends"
				KIND=""
				;;
				Prq) 
				TAG="rpm:requires"
				KIND=""
				;;
				Psg)
				TAG="rpm:suggests"
				KIND=""
				;;
			esac
			if [ "$KIND" != "" ]; then
				PRE="${KIND}:"
			else
				PRE=""
			fi
			echo " <$TAG>" >> $xmltarget
			test -f $TMPFILE && rm $TMPFILE
			sort -u $tag > $TMPFILE
			for entry in $(cat $TMPFILE); do
				echo "  <rpm:entry name=\"${PRE}${entry}\"/>" >> $xmltarget
                %if 0%{?create_packagelist}
                  if [ x"$KIND" = x"package" ]; then
                    echo "  <package name=\"$entry\"/>" >> "$LIST"
                  fi
                  echo "  <package name=\"$entry\"/>" >> "$kiwiinclude"
                %endif
			done
			echo " </$TAG>" >> $xmltarget
		fi
	done
	echo "</pattern>" >> $xmltarget
	popd 1>/dev/null
  done
}

%if 0%{?create_packagelist}
  LIST="%buildroot/%_datadir/%name/%name.xml"
  echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" >> $LIST
  echo "<group name=\"%name\">" >> $LIST 
  echo " <packagelist id=\"%name\">" >> $LIST
%endif

create_pattern

%if 0%{?create_xxbit_pattern}
%ifarch ia64
  EXTENSION="-x86"
%endif
%ifarch ppc
  EXTENSION="-64bit"
%endif
%ifarch s390x
  EXTENSION="-32bit"
%endif
%ifarch x86_64
  EXTENSION="-32bit"
%endif
%endif

if [ "$EXTENSION" != "" ]; then
	create_pattern
fi

%if 0%{?create_packagelist}
  echo " </packagelist>" >> $LIST
  echo "</group>" >> $LIST
%endif

pushd %buildroot/CD1/suse/setup/descr 1>/dev/null
# since openSUSE 11.0 all patterns are collected in one file
%if 0%{?suse_version} > 1030
  ALL_NAME=%{all_in_one_pattern_name}
  if [ -f "$ALL_NAME-%{version}-%{release}.%{_target_cpu}.pat" ]; then
    echo "pattern $ALL_NAME-%{version}-%{release}.%{_target_cpu}.pat exists"
    exit 1
  else
    for i in *.pat; do
      cat $i >> $ALL_NAME-%{version}-%{release}.%{_target_cpu}.pat
      rm $i
    done
  fi
%endif
# since openSUSE 10.3, pattern files are compressed...
%if 0%{?suse_version} > 1020
	gzip *.pat
%endif
popd 1>/dev/null

%clean
rm -rf %buildroot

%files
%defattr(-,root,root)
%dir /CD1
%dir /CD1/suse
%dir /CD1/suse/setup
%dir /CD1/suse/setup/descr
/CD1/suse/setup/descr/*
%{_datadir}/%name/

%changelog
openSUSE Build Service is sponsored by