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

PARAMS=1

# Where we can find the RPM directory
6 7
# and where we want to store the source code from svn
SVN_PATH="/home/$USER/svn"
8
RPM_PATH="/home/$USER/rpm"
9
REPOSIT="https://svn.erp5.org/repos/public/erp5/trunk/products"
10

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


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

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
  # Build the archive from the svn files
33 34
  ####################

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 41
  cd $SVN_PATH && svn checkout $REPOSIT/$NAME && cd -
  VERSION=`awk '{print $2}' $SVN_PATH/$NAME/VERSION.txt`
Jean-Paul Smets's avatar
Jean-Paul Smets committed
42
  echo Building --$NAME-- Version --$VERSION--
43 44 45 46 47
  rm -rf $SVN_PATH/$NAME-$VERSION/
  mkdir -p $SVN_PATH/$NAME-$VERSION
  cp -a $SVN_PATH/$NAME $SVN_PATH/$NAME-$VERSION
  # Remove SVN extra files
  find $SVN_PATH/$NAME-$VERSION/* -name ".svn" | xargs rm -rf
48

49
  # Create the archive
50 51 52
  cd $SVN_PATH/$NAME-$VERSION && tar jcvf $NAME-$VERSION.tar.bz2 $NAME && cd -
  mv -f $SVN_PATH/$NAME-$VERSION/$NAME-$VERSION.tar.bz2 $RPM_PATH/SOURCES/$NAME-$VERSION.tar.bz2
  rm -rf $SVN_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
  # Get data from the previous spec file commited in the SVN repository
61 62
  ####################

63
  # Now we will regenerate a spec file skeleton based on the one stored in the SVN.
64
  # This spec file need to be modified by hand to get
65 66 67 68
  cd $SVN_PATH
  rm -rf $NAME.spec
  wget --no-check-certificate $REPOSIT/$SPEC_REPOSITORY/$NAME.spec
  SVN_SPEC_FILE="$NAME.spec"
69

70
  # Get summary and required packages
71 72
  SUMMARY=`grep "^Summary*" $SVN_SPEC_FILE`
  REQUIRES=`grep "^Requires*" $SVN_SPEC_FILE`
73 74

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

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

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

94
  # Increase the rpm release number if needed
95 96
  PREVIOUS_VERSION=`grep "^%define version*" $SVN_SPEC_FILE | awk '{print $3}'`
  PREVIOUS_REL=`grep "^%define release*" $SVN_SPEC_FILE | awk '{print $3}'`
97 98 99 100 101 102 103
  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
104

105 106 107 108
  ####################
  # Build the spec file using the following template
  ####################

109
  echo "%define product $NAME
110
%define version $VERSION
111
%define release $RELEASE
112 113 114

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

116 117 118 119 120 121 122 123 124 125
$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
126
Conflicts: $NAME
127
$REQUIRES
128 129 130 131 132 133

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

#----------------------------------------------------------------------
134
$SPEC_CORE
135 136 137

#----------------------------------------------------------------------
%changelog
138
* $TODAY $PACKAGER <$EMAIL> $VERSION-$MKREL
139
$LOG_MSG
140

141
$CHANGELOG" >> $TMP_SPEC
Jean-Paul Smets's avatar
Jean-Paul Smets committed
142 143

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

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

149
  echo "-------------"
150
  echo "Please commit the new $NAME.spec file in the Nexedi repository ($REPOSIT)"
151 152
  echo "-------------"

153
done
Jean-Paul Smets's avatar
Jean-Paul Smets committed
154 155

exit 0