File create_pattern.sh of Package patterns

#!/bin/bash

# For syntax of .pat files see:
# http://en.opensuse.org/Pattern_Metadata_YaST

version=$1
release=$2
target_cpu=$3
RPM_BUILD_ROOT=$4
pat_ext=$5

warnings=`mktemp /tmp/fileXXXXXX`

for pat in `/bin/ls toinstall` ; do

if [ -f toinstall/$pat/skip ] ; then
  echo "Skipping $pat"
else
### top header
  echo "# openSUSE Patterns ${version}-${release}.${target_cpu} -- (c) 2008 SUSE LINUX Products GmbH" > tmpfile
  echo -n "# generated on " >> tmpfile
  date >> tmpfile
  echo >> tmpfile
  echo "=Ver: 5.0" >> tmpfile
  echo >> tmpfile
  echo "=Pat: " $pat ${version} ${release} ${target_cpu} >> tmpfile
  echo >> tmpfile
  if [ -f toinstall/$pat/role ] ; then
    cat utf8_roles/"`cat toinstall/$pat/role`"/* >> tmpfile
    #echo -n "=Cat: " >> tmpfile
    #cat toinstall/$pat/role >> tmpfile
    echo >> tmpfile
  fi
  if [ -f toinstall/$pat/icon ] ; then
    echo -n "=Ico: " >> tmpfile
    cat toinstall/$pat/icon >> tmpfile
    echo >> tmpfile
  fi
### lang specific label in utf8 format
### special handling of default first:
  if [ -f utf8_summary/$pat/default ] ; then
    cat utf8_summary/$pat/default >> tmpfile
  else
    # we don't have a default selection, use the name of
    # the selection instead.
    echo "=Sum: $pat" >> tmpfile
    echo "No default label for $pat"
  fi
 if [ -d utf8_summary/$pat ] ; then
   for lang in `ls -A utf8_summary/$pat` ; do
    case $lang in
     default)
      ;;
     *)
      cat utf8_summary/$pat/$lang >> tmpfile
      ;;
    esac
   done
   echo >> tmpfile
 else
   echo "No summary for $pat"
   exit 1
 fi
### lang specific description in utf8 format
### special handling of default first:
 if [ -d utf8_description/$pat ] ; then
   for lang in `ls -A utf8_description/$pat` ; do
     cat utf8_description/$pat/$lang >> tmpfile
   done
   echo >> tmpfile
 else
   echo "No description for $pat"
   exit 1
 fi
 if [ -f toinstall/$pat/conflicts ] ; then
   echo "+Con:" >> tmpfile
   bash $RPM_SOURCE_DIR/preprocess toinstall/$pat/conflicts >> tmpfile
   echo "-Con:" >> tmpfile
   echo >> tmpfile
 fi
 if [ -f toinstall/$pat/extends ] ; then
   echo "+Ext:" >> tmpfile
   bash $RPM_SOURCE_DIR/preprocess toinstall/$pat/extends >> tmpfile
   echo "-Ext:" >> tmpfile
   echo >> tmpfile
 fi
 if [ -f toinstall/$pat/freshens ] ; then
   echo "+Fre:" >> tmpfile
   bash $RPM_SOURCE_DIR/preprocess toinstall/$pat/freshens >> tmpfile
   echo "-Fre:" >> tmpfile
   echo >> tmpfile
 fi
 if [ -f toinstall/$pat/includes ] ; then
   echo "+Inc:" >> tmpfile
   bash $RPM_SOURCE_DIR/preprocess toinstall/$pat/extends >> tmpfile
   echo "-Inc:" >> tmpfile
   echo >> tmpfile
 fi
 if [ -f toinstall/$pat/obsoletes ] ; then
   echo "+Obs:" >> tmpfile
   bash $RPM_SOURCE_DIR/preprocess toinstall/$pat/obsoletes >> tmpfile
   echo "-Obs:" >> tmpfile
   echo >> tmpfile
 fi
 if [ -f toinstall/$pat/provides ] ; then
   echo "+Prv:" >> tmpfile
   bash $RPM_SOURCE_DIR/preprocess toinstall/$pat/provides >> tmpfile
   echo "-Prv:" >> tmpfile
   echo >> tmpfile
 fi
 if [ -f toinstall/$pat/recommends ] ; then
   echo "+Rec:" >> tmpfile
   bash $RPM_SOURCE_DIR/preprocess toinstall/$pat/recommends >> tmpfile
   echo "-Rec:" >> tmpfile
   echo >> tmpfile
 fi
 if [ -f toinstall/$pat/requires ] ; then
   echo "+Req:" >> tmpfile
   bash $RPM_SOURCE_DIR/preprocess toinstall/$pat/requires >> tmpfile
   echo "-Req:" >> tmpfile
   echo >> tmpfile
 fi
 if [ -f toinstall/$pat/suggests ] ; then
   echo "+Sug:" >> tmpfile
   bash $RPM_SOURCE_DIR/preprocess toinstall/$pat/suggests >> tmpfile
   echo "-Sug:" >> tmpfile
   echo >> tmpfile
 fi
 if [ -f toinstall/$pat/supplements ] ; then
   echo "+Sup:" >> tmpfile
   bash $RPM_SOURCE_DIR/preprocess toinstall/$pat/supplements >> tmpfile
   echo "-Sup:" >> tmpfile
   echo >> tmpfile
 fi

### YaST2 visible info
 echo -n "=Vis: " >> tmpfile
 if [ -f toinstall/$pat/visible ]; then
   bash $RPM_SOURCE_DIR/preprocess toinstall/$pat/visible >> tmpfile
 else
   echo "true" >> tmpfile
 fi
 echo >> tmpfile
### ordering for displaying the names
 if [ -f toinstall/$pat/order ]; then
   echo -n "=Ord: " >> tmpfile
   bash $RPM_SOURCE_DIR/preprocess toinstall/$pat/order >> tmpfile
   echo >> tmpfile
 fi
### general selections
 if [ -f toinstall/$pat/sel ]; then
   for file in `cat toinstall/$pat/sel`; do
     if [ ! -f "data/$file" ] ; then
       echo "toinstall/$pat/sel references nonexisting pattern $file"
       exit 1
     fi
     bash $RPM_SOURCE_DIR/preprocess "data/$file" | while read line; do
       case "$line" in
         \#*)
	        continue
                ;;
       esac
       echo "$line" >> tmpfile
       case "$line" in
         +*|-*)
                continue
		;;
       esac
       test -f /.buildenv && source /.buildenv
       rpmids=/.rpm-cache/$BUILD_BASENAME/rpm.deps.id
       if test -f $rpmids && ! grep -q "^P:$line-[^-]*-[^-]*-[^-]*:" $rpmids; then
          if grep -q "^P:.* $line " $rpmids || grep -q "^P:.* $line"'$' $rpmids; then
             ( grep "^P:.* $line " $rpmids ; grep "^P:.* $line"'$' $rpmids ) | sed -e 's,^P:\([^ ]*\)-[^-]*-[^-]*-[^-]*:.*,\1,' | \
             while read out; do echo "Provides $line is only virtual: $out"; done
          else
             echo "Package $line is missing" >> $warnings
          fi
       fi
     done
     echo >> tmpfile
   done
 fi
 mkdir -p $RPM_BUILD_ROOT/CD1/suse/setup/descr/
 mv tmpfile $RPM_BUILD_ROOT/CD1/suse/setup/descr/$pat-${version}-${release}.${target_cpu}.pat
# generate -32bit/-x86/-64bit patterns

  if [ "$pat_ext" != "" ] ; then
    if [ -f toinstall/$pat/sel ]; then
  ### top header
      echo "# openSUSE Patterns ${version}-${release}.${target_cpu} -- (c) 2007 SUSE LINUX Products GmbH" > tmpfile
      echo -n "# generated on " >> tmpfile
      date >> tmpfile
      echo >> tmpfile
      echo "=Ver: 5.0" >> tmpfile
      echo >> tmpfile
      echo "=Pat: " $pat-$pat_ext ${version} ${release} ${target_cpu} >> tmpfile
      echo >> tmpfile
      if [ -f toinstall/$pat/role ] ; then
        echo -n "=Cat: " >> tmpfile
        bash $RPM_SOURCE_DIR/preprocess toinstall/$pat/role >> tmpfile
        echo >> tmpfile
      fi
      echo "=Sum: $pat-$pat_ext" >> tmpfile
      echo "=Vis: false" >> tmpfile
      #echo -e "+Des:\nThis is only visible for debugging. Please don't report it as bug\n-Des:" >> tmpfile
  ### ordering for displaying the names
      if [ -f toinstall/$pat/order ]; then
        echo -n "=Ord: " >> tmpfile
        A=`bash $RPM_SOURCE_DIR/preprocess toinstall/$pat/order`
        B=$(($A + 1))
        echo $B >> tmpfile
        echo >> tmpfile
      fi
      echo -e "+Sup:\n$pat_ext\n-Sup:\n\n" >> tmpfile
      echo -e "+Fre:\n$pat\n-Fre:\n\n" >> tmpfile
      echo -e "+Ext:\n$pat_ext\n-Ext:\n\n" >> tmpfile
      echo "+Prc:" >> tmpfile
      rpmids=/.rpm-cache/$BUILD_BASENAME/rpm.deps.id
        for DATA in `bash $RPM_SOURCE_DIR/preprocess toinstall/$pat/sel`; do
          for i in `bash $RPM_SOURCE_DIR/preprocess data/$DATA | grep -v -e Prq\: -e Prc\: -e Psg\: -e '^#'` ; do
            package=$i-$pat_ext
            if test -f $rpmids && ! grep -q "^P:$package-[^-]*-[^-]*-[^-]*:" $rpmids; then
               if grep -q "^P:.* $package " $rpmids || grep -q "^P:.* $package"'$' $rpmids; then
                  ( grep "^P:.* $package " $rpmids ; grep "^P:.* $package"'$' $rpmids ) | sed -e 's,^P:\([^ ]*\)-[^-]*-[^-]*-[^-]*:.*,\1,' | \
                     while read out; do echo "Provides $package is only virtual: $out"; done
                   echo $package >> tmpfile
               fi
            else
              echo $package >> tmpfile
            fi
          done
        done
      echo "-Prc:" >> tmpfile
      mv tmpfile $RPM_BUILD_ROOT/CD1/suse/setup/descr/$pat-$pat_ext-${version}-${release}.${target_cpu}.pat
    fi
  fi
fi
done

sort -u $warnings
#test ! -s $warnings || exit 1
rm $warnings

openSUSE Build Service is sponsored by