source: trunk/technical/common/build/svn_build_prepare.sh@ 725

Last change on this file since 725 was 724, checked in by joergs, on Oct 2, 2008 at 6:19:22 PM

in case of SOURCES, checks if tar.bz2 really has to be recreated. If not, exit 1. Removed legacy TAR creating method by Makefile, because this isn't used for quite a while

  • Property svn:executable set to *
File size: 5.7 KB
Line 
1#!/bin/bash
2
3# build prepare script
4
5# $Id$
6
7# Exitcodes:
8# 0 normal end. Has created build directory
9# 1 build directory already up-to-date. Nothing to do.
10# 255 error
11
12BUILDUSER=$USER
13[ -z $DEST_DIR ] && DEST_DIR="/tmp/build.$BUILDUSER"
14BUILDTEMP=$DEST_DIR/buildsrc/
15
16[ -z "$BUILD_USES_SVN" ] && BUILD_USES_SVN="yes"
17
18if [ -z "$1" ]; then
19 # without parameter, we are in source directory
20 SPECFILE=$(ls *.spec | awk '{print $1}')
21 PACKAGE=$(sed -n -e 's/^Name:\W*//pi' <$SPECFILE)
22 VERSION=$(sed -n -e 's/^Version:\W*//pi' <$SPECFILE)
23elif [ -r "$1" ]; then
24 # parameter is src.rpm file
25 PACKAGE=`rpm -qp --qf "%{NAME}" $1`
26 VERSION=`rpm -qp --qf "%{VERSION}" $1`
27fi
28
29
30if [ -z "$PACKAGE" ]; then
31 echo "nothing to build found!"
32 exit 255
33fi
34
35
36
37if [ "$1" ]; then
38 EXPECTED_DEST_RPM_FILENAME=${DEST_DIR}/${BUILD_DIST}/`echo $1 | sed 's/\.src\./.*./'`
39 if [ -f $EXPECTED_DEST_RPM_FILENAME ]; then
40 echo
41 echo "Build of \"${PACKAGE}\" unnecessary. Current RPM already at " $EXPECTED_DEST_RPM_FILENAME
42 echo
43 exit 1
44 else
45 rm -rf ${BUILDTEMP}/src/${PACKAGE}
46 mkdir -p ${BUILDTEMP}/src/${PACKAGE}
47 cp -a "$1" ${BUILDTEMP}/src/${PACKAGE}
48 cd ${BUILDTEMP}/src/${PACKAGE}; rpm2cpio $1 | cpio -i
49 fi
50else
51 cp -a $SPECFILE ${BUILDTEMP}/src/${PACKAGE}
52
53 # uses Subversion (svn) to generate more information for the RPM
54 if [ "$BUILD_USES_SVN" = "yes" ]; then
55 echo "receiving subversion information ..."
56 # set RELEASE number (last modification in this directory)
57 # requires subversion (but connection to server isn't neccessary)
58 SVN_BUILD_RELEASE=$(unset LANG; svn info . | sed -n 's/^Last Changed Rev: \([0-9]*\)/\1/p')
59 # in case of local modification a "m" is added to the release number
60 SVN_BUILD_MODIFIED=$(svn status -v | grep "^ *M" | wc -l)
61 # checks if a file is commited,
62 # but update on its directory is not performed
63 SVN_LAST_MODIFICATION=$(svn status -v | sed -n 's/^ *[0-9]* *\([0-9]*\) .*/\1/p' | sort -n | tail -1)
64 if [ $SVN_BUILD_MODIFIED -gt 0 ]; then
65 SVN_BUILD_RELEASE=${SVN_BUILD_RELEASE}m
66 REBUILD="yes"
67 elif [ $SVN_LAST_MODIFICATION -ne $SVN_BUILD_RELEASE ]; then
68 SVN_BUILD_RELEASE=${SVN_BUILD_RELEASE}p
69 REBUILD="yes"
70 else # check if RPM has been build already
71 # TODO: this check is broken for OpenSUSE build service,
72 # because version is changed later on
73 EXPECTED_DEST_RPM_FILENAME=${DEST_DIR}/${BUILD_DIST}/${PACKAGE}-${VERSION}-${SVN_BUILD_RELEASE}.*.rpm
74 if [ -f $EXPECTED_DEST_RPM_FILENAME ]; then
75 echo
76 echo "Build of \"${PACKAGE}\" unnecessary. Current RPM already at " $EXPECTED_DEST_RPM_FILENAME
77 echo
78 exit 1
79 fi
80 fi
81 if [ "$SVN_BUILD_RELEASE" ]; then
82 # Release will be overwritten bei OpenSUSE build service,
83 # therefore we add SVN_BUILD_RELEASE to Version
84 VERSION_ORIG=$VERSION
85 VERSION=$VERSION.$SVN_BUILD_RELEASE
86 #sed "s/^Release:.*/Release: $SVN_BUILD_RELEASE/ig" $SPECFILE > ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
87 #sed -r "s/^(Version:\s*\S*)/\1.$SVN_BUILD_RELEASE/ig" $SPECFILE > ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
88 sed "s/^Version:.*/Version: $VERSION/ig" $SPECFILE > ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
89 fi
90 echo "SVN_BUILD_RELEASE: $SVN_BUILD_RELEASE"
91
92 printf "adding subversion changelog: "
93 # changelog header
94 DATE=`unset LANG; date +"%a %b %d %Y"`
95 echo -e "* $DATE -\n" > Changes
96 echo "- Subversion status:" >> Changes
97 # additional infos for the Changes file (see if everything is checked in)
98 svn status -v | grep -v '^? ' >> Changes
99 echo >> Changes
100 echo "- ChangeLog:" >> Changes
101 # requires connection to the subversion server
102 svn log -v . > ChangeLog.new && mv ChangeLog.new ChangeLog
103 cat ChangeLog >> Changes
104
105 # if there is no changelog section in the spec file,
106 # also append the Changes there
107 if ! grep -q -i "%changelog" $SPECFILE ; then
108 # paste "Changes" into SPEC file.
109 echo "%changelog" >> ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
110 # without trailing *, except for the initial
111 echo -n "*" >> ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
112 cat Changes | sed 's/\(^[\*]\+\)//g' >> ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
113 fi
114 printf "done\n"
115 fi
116 # just make sure, that the Changes file exist
117 touch Changes
118
119 # if "SOURCES" file exist, create tar file on the fly
120 if [ -r "SOURCES" ]; then
121 # create a tar file from the sources
122 printf "creating $PACKAGE-$VERSION.tar.bz2: "
123
124 if [ "$REBUILD" -o ! -r ${BUILDTEMP}/src/${PACKAGE}/$PACKAGE-$VERSION.tar.bz2 ]; then
125 rm -rf ${BUILDTEMP}/src/${PACKAGE}
126 mkdir -p ${BUILDTEMP}/src/${PACKAGE}
127 tar cvjf ${BUILDTEMP}/src/${PACKAGE}/$PACKAGE-$VERSION.tar.bz2 --files-from SOURCES --exclude .svn --exclude "*~"
128 else
129 printf "already exists. Skipped\n"
130 exit 1
131 fi
132 elif [ -r "SPECSOURCES" ]; then
133 # SPECSOURCES has to list the files
134 # that are referenced in the .spec file
135 # these files are copied to the build environment
136 rm -rf ${BUILDTEMP}/src/${PACKAGE}
137 mkdir -p ${BUILDTEMP}/src/${PACKAGE}
138 cp -av `cat SPECSOURCES` ${BUILDTEMP}/src/${PACKAGE}
139
140 else
141 printf "error: neither SOURCES nor SPECSOURCES file found. One of these is required. Exiting\n"
142 exit 255
143 fi
144fi
Note: See TracBrowser for help on using the repository browser.