File sort_patterns of Package patterns-openSUSE

#! /bin/sh

# don't forget: export RPM_BUILD_ROOT and RPM_SOURCE_DIR
version=$1
release=$2
uname=$3
product=$4

if test -d $RPM_BUILD_ROOT; then
  echo RPM_BUILD_ROOT already exists!
fi

if ! test -f $RPM_SOURCE_DIR/preprocess; then
  echo RPM_SOURCE_DIR/preprocess does not exist
  exit 1
fi

mkdir -p $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT/CD1/suse/setup/descr

case $uname in
  x86_64|s390x)
    pat_ext="32bit"
    ;;
  ia64)
    pat_ext="x86"
    ;;
  ppc)
    pat_ext="64bit"
    ;;
  ppc64)
    pat_ext="32bit"
    ;;
  *)
    pat_ext=""
esac

cp_path=/usr/sbin/create_pattern.sh
if test -f $RPM_SOURCE_DIR/create_pattern.sh; then
  cp_path=$RPM_SOURCE_DIR/create_pattern.sh
fi

sh $cp_path $version $release $uname $RPM_BUILD_ROOT $pat_ext

set +x
descrdir=$RPM_BUILD_ROOT/CD1/suse/setup/descr

# Handle architecture dependend patterns
case $uname in
  i*86|x86_64)
    ;;
  *)
    rm -fv $descrdir/xen_server*.pat
    ;;
esac
if test "$uname" != ia64; then
  rm -vf $descrdir/x86*.pat
fi
if test "$pat_ext" != 64bit; then
  rm -vf $descrdir/64bit*.pat
fi
if test "$pat_ext" != 32bit; then
  rm -vf $descrdir/32bit*.pat
fi

mkdir sortin
if test "$product" = "openSUSE"; then
grep update_test toinstall/rest_dvd/requires || rm -v $descrdir/update_test*.pat
cat $descrdir/rest_cd_kde4* > sortin/kde4_cd
cat $descrdir/rest_promo_dvd* > sortin/promo_dvd
rm $descrdir/rest_promo_dvd*
cat $descrdir/rest_cd_gnome* > sortin/gnome_cd 
cat $descrdir/rest_cd_x11* > sortin/x11_cd
cat $descrdir/non_oss*.pat > sortin/non_oss
rm $descrdir/non_oss_opt*.pat
echo > sortin/dvd
for pat in $descrdir/*.pat; do
   pat=`basename $pat`
   nicename=`echo $pat | sed -e "s,-$version.*,,"`
   basepat=$nicename
   if test -n "$pat_ext"; then
      basepat=`echo $basepat | sed -e "s,-$pat_ext,,"`
   fi
   if grep -q -x $nicename toinstall/rest_cd_kde4/{requires,recommends}; then
     cat $descrdir/$pat >> sortin/kde4_cd
   fi
   if grep -q -x $nicename toinstall/rest_cd_gnome/{requires,recommends}; then
     cat $descrdir/$pat >> sortin/gnome_cd
   fi
   if grep -q -x $nicename toinstall/rest_promo_dvd/{requires,recommends}; then
     cat $descrdir/$pat >> sortin/promo_dvd
   fi
   if grep -q -x $nicename toinstall/rest_cd_x11/requires; then
     cat $descrdir/$pat >> sortin/x11_cd
   fi
   if grep -q -x $basepat toinstall/rest_dvd9/{requires,recommends}; then
     cat $descrdir/$pat >> sortin/dvd9
   fi
   if grep -q -x $basepat toinstall/rest_dvd/{requires,recommends} || test "$nicename" = rest_dvd; then
     cat $descrdir/$pat >> sortin/dvd
   else
     cat $descrdir/$pat >> sortin/ftp
   fi
   rm $descrdir/$pat
done
fi
if test "$product" = "sled"; then
echo > sortin/sled
for pat in $descrdir/*.pat; do
   pat=`basename $pat`
   nicename=`echo $pat | sed -e "s,-$version.*,,"`
   cat $descrdir/$pat >> sortin/sled
   rm $descrdir/$pat
done
fi

if test "$product" = "sles"; then
echo > sortin/sles
for pat in $descrdir/*.pat; do
   pat=`basename $pat`
   nicename=`echo $pat | sed -e "s,-$version.*,,"`
   cat $descrdir/$pat >> sortin/sles
   rm $descrdir/$pat
done
fi

if test "$product" = "sdk"; then
echo > sortin/sdk
for pat in $descrdir/*.pat; do
   pat=`basename $pat`
   nicename=`echo $pat | sed -e "s,-$version.*,,"`
   cat $descrdir/$pat >> sortin/sdk
   rm $descrdir/$pat
done
fi

cd sortin
for i in *; do
  mv $i $descrdir/$i-$version-$release.$uname.pat
done
cd ..
rmdir sortin
openSUSE Build Service is sponsored by