build-spec 4.24 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 9 10 11 12 13 14 15 16 17 18
CVS_PATH="/home/$USER/cvs"
RPM_PATH="/home/$USER/rpm"

# TODO: The spec repository should be moved from /ERP5/spec to /spec in the CVS
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
19

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

# Because we get the CVS version, we have to include the date in the revision number
CVSDATE=`date +'%Y%m%d'`
Jean-Paul Smets's avatar
Jean-Paul Smets committed
29

30
while test $# -gt 0; do
Jean-Paul Smets's avatar
Jean-Paul Smets committed
31
  NAME=$1
32 33
  shift
  echo Starting Building $NAME
34 35
  # Retrieve the version in the source code as anonymous user to be sure we get published code only
  cd $CVS_PATH && cvs -d:pserver:anonymous@cvs.erp5.org:/cvsroot checkout $NAME && cd -
Jean-Paul Smets's avatar
Jean-Paul Smets committed
36
  VERSION=`awk '{print $2}' $CVS_PATH/$NAME/VERSION.txt`
37
  VERSION=$VERSION.$CVSDATE
Jean-Paul Smets's avatar
Jean-Paul Smets committed
38 39
  echo Building --$NAME-- Version --$VERSION--
  rm -rf $CVS_PATH/$NAME-$VERSION/
40
  mkdir -p $CVS_PATH/$NAME-$VERSION
Jean-Paul Smets's avatar
Jean-Paul Smets committed
41
  cp -a $CVS_PATH/$NAME $CVS_PATH/$NAME-$VERSION
42 43 44 45 46 47
  # Remove CVS extra files
  find $CVS_PATH/$NAME-$VERSION/* -name "CVS" | xargs rm -rf
  # Create the archive
  cd $CVS_PATH/$NAME-$VERSION && tar jcvf $NAME-$VERSION.tar.bz2 $NAME && cd -
  mv $CVS_PATH/$NAME-$VERSION/$NAME-$VERSION.tar.bz2 $CVS_PATH/
  # Remove because this does not remove files
48
  rm -f $RPM_PATH/SOURCES/$NAME-$VERSION.tar.bz2
49
  cp $CVS_PATH/$NAME-$VERSION.tar.bz2 $RPM_PATH/SOURCES/$NAME-$VERSION.tar.bz2
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77

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

  # 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
  cd $CVS_PATH && cvs -d:pserver:anonymous@cvs.erp5.org:/cvsroot checkout $SPEC_REPOSITORY/$NAME.spec
  CVS_SPEC_FILE="$CVS_PATH/$SPEC_REPOSITORY/$NAME.spec"

  # Get sumary, description and changelog from the previous spec file
  SUMMARY=`grep "^Summary*" $CVS_SPEC_FILE`

  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}'`
  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`
  CLOG_TAIL=`expr $L_TOTAL - $L_CHANGELOG - 2`

  DESCRIPTION=`head -n $DESC_HEAD $CVS_SPEC_FILE | tail -n $DESC_TAIL`
  CHANGELOG=`tail -n $CLOG_TAIL $CVS_SPEC_FILE`

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

  # Generate the spec file
78
  echo "%define product $NAME
79 80 81 82 83 84
%define version $VERSION
# If we get the code from the CVS, the release will be always the first
%define release 1

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

86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
$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
Requires:  zope-erp5

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

#----------------------------------------------------------------------
%prep
%setup -c

%build


%install
%{__rm} -rf %{buildroot}
%{__mkdir_p} %{buildroot}/%{software_home}/Products
%{__cp} -a * %{buildroot}%{software_home}/Products/


%clean
%{__rm} -rf %{buildroot}

%post
if [ \"\`%{_prefix}/bin/zopectl status\`\" != \"daemon manager not running\" ] ; then
  service zope restart
fi

%postun
if [ -f \"%{_prefix}/bin/zopectl\" ] && [ \"\`%{_prefix}/bin/zopectl status\`\" != \"daemon manager not running\" ] ; then
  service zope restart
fi

%files
%defattr(0644, root, root, 0755)
%doc VERSION.txt
%{software_home}/Products/*

#----------------------------------------------------------------------
%changelog
* $TODAY $PACKAGER <$EMAIL> $VERSION-1mdk
- $LOG_MSG

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

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

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

146
done
Jean-Paul Smets's avatar
Jean-Paul Smets committed
147 148

exit 0