build-spec 4.48 KB
Newer Older
Jean-Paul Smets's avatar
Jean-Paul Smets committed
1 2 3 4 5 6
#!/bin/bash

PARAMS=1

# Where we can find the RPM directory
# and where we want to store the source code from cvs
7 8
CVS_PATH="/home/$USER/cvs"
RPM_PATH="/home/$USER/rpm"
9
REPOSIT="cvs.erp5.org"
10

11
# TODO: The spec repository should be moved from /ERP5/spec to /spec/Mandriva in the CVS
12 13 14 15 16 17 18 19
SPEC_REPOSITORY="ERP5/spec"


# Those variables are used to build the change log
PACKAGER="Kevin Deldycke"
EMAIL="kevin@nexedi.com"
LOG_MSG="New build from the CVS"

Jean-Paul Smets's avatar
Jean-Paul Smets committed
20

21
if [ $# -lt "$PARAMS" ]
Jean-Paul Smets's avatar
Jean-Paul Smets committed
22 23
then
  echo
24
  echo "build-spec PACKAGE_NAME..."
Jean-Paul Smets's avatar
Jean-Paul Smets committed
25
  exit 0
26 27
fi

28

29
while test $# -gt 0; do
30 31 32 33 34

  ####################
  # Build the archive from the cvs files
  ####################

Jean-Paul Smets's avatar
Jean-Paul Smets committed
35
  NAME=$1
36 37
  shift
  echo Starting Building $NAME
38

39
  # Retrieve the version in the source code as anonymous user to be sure we get published code only
40
  cd $CVS_PATH && cvs -d:pserver:anonymous@$REPOSIT:/cvsroot checkout $NAME && cd -
Jean-Paul Smets's avatar
Jean-Paul Smets committed
41 42 43
  VERSION=`awk '{print $2}' $CVS_PATH/$NAME/VERSION.txt`
  echo Building --$NAME-- Version --$VERSION--
  rm -rf $CVS_PATH/$NAME-$VERSION/
44
  mkdir -p $CVS_PATH/$NAME-$VERSION
Jean-Paul Smets's avatar
Jean-Paul Smets committed
45
  cp -a $CVS_PATH/$NAME $CVS_PATH/$NAME-$VERSION
46 47
  # Remove CVS extra files
  find $CVS_PATH/$NAME-$VERSION/* -name "CVS" | xargs rm -rf
48

49 50
  # Create the archive
  cd $CVS_PATH/$NAME-$VERSION && tar jcvf $NAME-$VERSION.tar.bz2 $NAME && cd -
51 52
  mv -f $CVS_PATH/$NAME-$VERSION/$NAME-$VERSION.tar.bz2 $RPM_PATH/SOURCES/$NAME-$VERSION.tar.bz2
  rm -rf $CVS_PATH/$NAME-$VERSION
53 54 55 56 57

  TMP_SPEC="/tmp/$NAME-$VERSION-tmp.spec"
  rm -f $TMP_SPEC
  touch $TMP_SPEC

58 59 60 61 62

  ####################
  # Get data from the previous spec file commited in the CVS
  ####################

63 64
  # Now we will regenerate a spec file skeleton based on the one stored in the CVS.
  # This spec file need to be modified by hand to get
65
  cd $CVS_PATH && cvs -d:pserver:anonymous@$REPOSIT:/cvsroot checkout $SPEC_REPOSITORY/$NAME.spec
66 67
  CVS_SPEC_FILE="$CVS_PATH/$SPEC_REPOSITORY/$NAME.spec"

68
  # Get summary and required packages
69
  SUMMARY=`grep "^Summary*" $CVS_SPEC_FILE`
70 71 72
  REQUIRES=`grep "^Requires*" $CVS_SPEC_FILE`

  # Get the description and changelog from the previous spec file
73 74 75 76
  L_SECTIONS=`grep -hn "#----------------------------------------------------------------------" $CVS_SPEC_FILE | sed -e "s/:/ /g" | awk '{print $1}'`
  L_DESC_START=`echo $L_SECTIONS | awk '{print $1}'`
  L_DESC_STOP=` echo $L_SECTIONS | awk '{print $2}'`
  L_CHANGELOG=` echo $L_SECTIONS | awk '{print $3}'`
77 78
  L_CORE_START=$L_DESC_STOP
  L_CORE_STOP=$L_CHANGELOG
79 80 81
  L_TOTAL=`wc -l $CVS_SPEC_FILE | awk '{print $1}'`
  DESC_HEAD=`expr $L_DESC_STOP - 1`
  DESC_TAIL=`expr $L_DESC_STOP - $L_DESC_START - 2`
82 83
  CORE_HEAD=`expr $L_CORE_STOP - 1`
  CORE_TAIL=`expr $L_CORE_STOP - $L_CORE_START - 1`
84
  CLOG_TAIL=`expr $L_TOTAL - $L_CHANGELOG - 1`
85 86

  DESCRIPTION=`head -n $DESC_HEAD $CVS_SPEC_FILE | tail -n $DESC_TAIL`
87
  SPEC_CORE=`head -n $CORE_HEAD $CVS_SPEC_FILE | tail -n $CORE_TAIL`
88 89 90 91
  CHANGELOG=`tail -n $CLOG_TAIL $CVS_SPEC_FILE`

  TODAY=`env LC_TIME=en date +"%a %b %d %Y"`

92 93 94 95 96 97 98 99 100 101
  # Increase the rpm release number if needed
  PREVIOUS_VERSION=`grep "^%define version*" $CVS_SPEC_FILE | awk '{print $3}'`
  PREVIOUS_REL=`grep "^%define release*" $CVS_SPEC_FILE | awk '{print $3}'`
  if test "x$VERSION" = "x$PREVIOUS_VERSION"; then
    RELEASE=`expr $PREVIOUS_REL + 1`
  else
    RELEASE="1"
  fi
  MKREL=`rpm --with unstable --eval "%mkrel $RELEASE"`

Kevin Deldycke's avatar
Kevin Deldycke committed
102

103 104 105 106
  ####################
  # Build the spec file using the following template
  ####################

107
  echo "%define product $NAME
108
%define version $VERSION
109
%define release $RELEASE
110 111 112

%define zope_home %{_prefix}/lib/zope
%define software_home %{zope_home}/lib/python
Jean-Paul Smets's avatar
Jean-Paul Smets committed
113

114 115 116 117 118 119 120 121 122 123
$SUMMARY
Name:      zope-%{product}
Version:   %{version}
Release:   %mkrel %{release}
License:   GPL
Group:     System/Servers
URL:       http://www.erp5.org
Source0:   %{product}-%{version}.tar.bz2
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-rootdir
BuildArch: noarch
124
Conflicts: $NAME
125
$REQUIRES
126 127 128 129 130 131

#----------------------------------------------------------------------
%description
$DESCRIPTION

#----------------------------------------------------------------------
132
$SPEC_CORE
133 134 135

#----------------------------------------------------------------------
%changelog
136
* $TODAY $PACKAGER <$EMAIL> $VERSION-$MKREL
137 138
- $LOG_MSG

139
$CHANGELOG" >> $TMP_SPEC
Jean-Paul Smets's avatar
Jean-Paul Smets committed
140 141

  # now we can replace the spec file
142
  rm -f $RPM_PATH/SPECS/$NAME.spec
143
  mv -f $TMP_SPEC $RPM_PATH/SPECS/$NAME.spec
Jean-Paul Smets's avatar
Jean-Paul Smets committed
144

145
  #rpmbuild -ba $RPM_PATH/SPECS/$NAME.spec
Jean-Paul Smets's avatar
Jean-Paul Smets committed
146

147 148 149 150
  echo "-------------"
  echo "Please commit the new $NAME.spec file in the Nexedi repository (http://$REPOSIT)"
  echo "-------------"

151
done
Jean-Paul Smets's avatar
Jean-Paul Smets committed
152 153

exit 0