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

Last change on this file since 729 was 729, checked in by slederer, on Oct 9, 2008 at 5:35:02 PM

add some comments to the code

  • Property svn:executable set to *
File size: 7.3 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
12# TODO:
13# needs force parameter for tar.bz2 creation
14
15# when building debian packages, which files from the "debian"
16# directory are required (in addition to the package description
17# and changelog)
18debfiles="control rules"
19
20BUILDUSER=$USER
21[ -z $DEST_DIR ] && DEST_DIR="/tmp/build.$BUILDUSER"
22BUILDTEMP=$DEST_DIR/buildsrc/
23
24[ -z "$BUILD_USES_SVN" ] && BUILD_USES_SVN="yes"
25
26if [ -z "$1" ]; then
27 # without parameter, we are in source directory
28 SPECFILE=$(ls *.spec | awk '{print $1}')
29 PACKAGE=$(sed -n -e 's/^Name:\W*//pi' <$SPECFILE)
30 VERSION=$(sed -n -e 's/^Version:\W*//pi' <$SPECFILE)
31elif [ -r "$1" ]; then
32 # parameter is src.rpm file
33 PACKAGE=`rpm -qp --qf "%{NAME}" $1`
34 VERSION=`rpm -qp --qf "%{VERSION}" $1`
35fi
36
37
38if [ -z "$PACKAGE" ]; then
39 echo "nothing to build found!"
40 exit 255
41fi
42
43
44
45if [ "$1" ]; then
46 EXPECTED_DEST_RPM_FILENAME=${DEST_DIR}/${BUILD_DIST}/`echo $1 | sed 's/\.src\./.*./'`
47 if [ -f $EXPECTED_DEST_RPM_FILENAME ]; then
48 echo
49 echo "Build of \"${PACKAGE}\" unnecessary. Current RPM already at " $EXPECTED_DEST_RPM_FILENAME
50 echo
51 exit 1
52 else
53 rm -rf ${BUILDTEMP}/src/${PACKAGE}
54 mkdir -p ${BUILDTEMP}/src/${PACKAGE}
55 cp -a "$1" ${BUILDTEMP}/src/${PACKAGE}
56 cd ${BUILDTEMP}/src/${PACKAGE}; rpm2cpio $1 | cpio -i
57fi
58else
59 # uses Subversion (svn) to generate more information for the RPM
60 if [ "$BUILD_USES_SVN" = "yes" ]; then
61 echo "receiving subversion information ..."
62 # set RELEASE number (last modification in this directory)
63 # requires subversion (but connection to server isn't neccessary)
64 SVN_BUILD_RELEASE=$(unset LANG; svn info . | sed -n 's/^Last Changed Rev: \([0-9]*\)/\1/p')
65 # in case of local modification a "m" is added to the release number
66 SVN_BUILD_MODIFIED=$(svn status -v | grep "^ *M" | wc -l)
67 # checks if a file is commited,
68 # but update on its directory is not performed
69 SVN_LAST_MODIFICATION=$(svn status -v | sed -n 's/^ *[0-9]* *\([0-9]*\) .*/\1/p' | sort -n | tail -1)
70 if [ $SVN_BUILD_MODIFIED -gt 0 ]; then
71 SVN_BUILD_RELEASE=${SVN_BUILD_RELEASE}m
72 REBUILD="yes"
73 elif [ $SVN_LAST_MODIFICATION -ne $SVN_BUILD_RELEASE ]; then
74 SVN_BUILD_RELEASE=${SVN_BUILD_RELEASE}p
75 REBUILD="yes"
76 else # check if RPM has been built already
77 # TODO: this check is broken for OpenSUSE build service,
78 # because version is changed later on
79 EXPECTED_DEST_RPM_FILENAME=${DEST_DIR}/${BUILD_DIST}/${PACKAGE}-${VERSION}-${SVN_BUILD_RELEASE}.*.rpm
80 if [ -f $EXPECTED_DEST_RPM_FILENAME ]; then
81 echo
82 echo "Build of \"${PACKAGE}\" unnecessary. Current RPM already at " $EXPECTED_DEST_RPM_FILENAME
83 echo
84 exit 1
85 fi
86 fi
87
88 if [ "$SVN_BUILD_RELEASE" ]; then
89 # Release will be overwritten bei OpenSUSE build service,
90 # therefore we add SVN_BUILD_RELEASE to Version
91 VERSION_ORIG=$VERSION
92 VERSION=$VERSION.$SVN_BUILD_RELEASE
93 fi
94 echo "SVN_BUILD_RELEASE: $SVN_BUILD_RELEASE"
95
96 printf "adding subversion changelog: "
97 # changelog header
98 DATE=`unset LANG; date +"%a %b %d %Y"`
99 echo -e "* $DATE - svn_build\n" > Changes
100 echo "- Subversion status:" >> Changes
101 # additional infos for the Changes file (see if everything is checked in)
102 svn status -v | grep -v '^? ' >> Changes
103 echo >> Changes
104 echo "- ChangeLog:" >> Changes
105 # requires connection to the subversion server
106 svn log -v . > ChangeLog.new && mv ChangeLog.new ChangeLog
107 cat ChangeLog >> Changes
108
109 printf "done\n"
110 fi
111 # just make sure, that the Changes file exists
112 touch Changes
113
114 # if "SOURCES" file exist, create tar file on the fly
115 if [ -r "SOURCES" ]; then
116 # create a tar file from the sources
117 printf "creating $PACKAGE-$VERSION.tar.bz2: "
118
119 if [ "$REBUILD" -o ! -r ${BUILDTEMP}/src/${PACKAGE}/$PACKAGE-$VERSION.tar.bz2 ]; then
120 rm -rf ${BUILDTEMP}/src/${PACKAGE}
121 mkdir -p ${BUILDTEMP}/src/${PACKAGE}
122 tar cvjf ${BUILDTEMP}/src/${PACKAGE}/$PACKAGE-$VERSION.tar.bz2 --files-from SOURCES --exclude .svn --exclude "*~"
123 else
124 printf "already exists. Skipped\n"
125 exit 1
126 fi
127 elif [ -r "SPECSOURCES" ]; then
128 # SPECSOURCES has to list the files
129 # that are referenced in the .spec file
130 # these files are copied to the build environment
131 rm -rf ${BUILDTEMP}/src/${PACKAGE}
132 mkdir -p ${BUILDTEMP}/src/${PACKAGE}
133 cp -av `cat SPECSOURCES` ${BUILDTEMP}/src/${PACKAGE}
134
135 else
136 printf "error: neither SOURCES nor SPECSOURCES file found. One of these is required. Exiting\n"
137 exit 255
138 fi
139
140
141 echo $SVN_BUILD_RELEASE
142 if [ "$SVN_BUILD_RELEASE" ]; then
143 # Release will be overwritten bei OpenSUSE build service,
144 # therefore we add SVN_BUILD_RELEASE to Version
145 #sed "s/^Release:.*/Release: $SVN_BUILD_RELEASE/ig" $SPECFILE > ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
146 #sed -r "s/^(Version:\s*\S*)/\1.$SVN_BUILD_RELEASE/ig" $SPECFILE > ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
147 sed "s/^Version:.*/Version: $VERSION/ig" $SPECFILE > ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
148 else
149 cp -a $SPECFILE ${BUILDTEMP}/src/${PACKAGE}
150 fi
151
152 # if there is no changelog section in the spec file,
153 # also append the Changes there
154 if ! grep -q -i "%changelog" $SPECFILE ; then
155 # paste "Changes" into SPEC file.
156 echo "%changelog" >> ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
157 # without trailing *, except for the initial
158 echo -n "*" >> ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
159 cat Changes | sed 's/\(^[\*]\+\)//g' >> ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
160 fi
161
162 # if there is a directory named "debian", prepare the
163 # necessary files to build a debian package on OpenSUSE build service
164
165 if [ -d debian ]; then
166 LANG=C;export LANG
167 # replace version number in the description file
168 sed -e "s/^Version:.*/Version: $VERSION-1/ig" -e "/^Files:/,$ d" debian/${PACKAGE} >${BUILDTEMP}/src/${PACKAGE}/${PACKAGE}.dsc
169 # update the file list in the description file
170 (echo "Files: "; echo " 0 0 ${PACKAGE}-${VERSION}.tar.bz2"; echo " 0 0 ${PACKAGE}_${VERSION}-1.diff.gz") >>${BUILDTEMP}/src/${PACKAGE}/${PACKAGE}.dsc
171 # create a changelog file
172 (echo "${PACKAGE} (${VERSION}-1) unstable; urgency=low"
173 echo
174 echo " * generated from SVN revision ${SVN_BUILD_RELEASE}"
175 echo
176 echo -n " -- dass IT GmbH <info@dass-it.de> "; date +"%a, %e %b %Y %X %z"
177 echo
178 )>${BUILDTEMP}/src/${PACKAGE}/debian.changelog
179 # copy files from "debian" directory into the package directory, renaming
180 # them accordingly
181 for f in $debfiles
182 do
183 [ -r "$f" ] && cp "debian/$f" ${BUILDTEMP}/src/${PACKAGE}/debian.$f
184 done
185 fi
186fi
Note: See TracBrowser for help on using the repository browser.