source: dassbuild/trunk/usr/bin/dassbuild_prepare.sh@ 1267

Last change on this file since 1267 was 1198, checked in by joergs, on Oct 13, 2015 at 5:04:59 PM

dsc file in root or debian subdirectory

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 9.0 KB
RevLine 
[720]1#!/bin/bash
2
3# build prepare script
4
5# $Id: dassbuild_prepare.sh 1198 2015-10-13 15:04:59Z joergs $
6
[724]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
[726]12# TODO:
[739]13# needs force parameter for tar.gz creation
[726]14
[730]15
[731]16filesize()
17{
18 stat --format='%s' $*
19}
20
21md5()
22{
23 md5sum $* | cut -f 1 -d ' '
24}
25
26export LANG=C
27
[720]28BUILDUSER=$USER
29[ -z $DEST_DIR ] && DEST_DIR="/tmp/build.$BUILDUSER"
30BUILDTEMP=$DEST_DIR/buildsrc/
31
[721]32[ -z "$BUILD_USES_SVN" ] && BUILD_USES_SVN="yes"
[951]33[ -z "$BUILD_MODIFIES_SPEC" ] && BUILD_MODIFIES_SPEC="yes"
[720]34
35if [ -z "$1" ]; then
36 # without parameter, we are in source directory
37 SPECFILE=$(ls *.spec | awk '{print $1}')
38 PACKAGE=$(sed -n -e 's/^Name:\W*//pi' <$SPECFILE)
39 VERSION=$(sed -n -e 's/^Version:\W*//pi' <$SPECFILE)
40elif [ -r "$1" ]; then
41 # parameter is src.rpm file
[721]42 PACKAGE=`rpm -qp --qf "%{NAME}" $1`
43 VERSION=`rpm -qp --qf "%{VERSION}" $1`
[951]44 unset BUILD_MODIFIES_SPEC
[720]45fi
46
47
48if [ -z "$PACKAGE" ]; then
[740]49 echo "nothing to build found"
[724]50 exit 255
[720]51fi
52
53
54
55if [ "$1" ]; then
56 EXPECTED_DEST_RPM_FILENAME=${DEST_DIR}/${BUILD_DIST}/`echo $1 | sed 's/\.src\./.*./'`
[736]57 if [ -f "$EXPECTED_DEST_RPM_FILENAME" ]; then
[720]58 echo
59 echo "Build of \"${PACKAGE}\" unnecessary. Current RPM already at " $EXPECTED_DEST_RPM_FILENAME
60 echo
61 exit 1
62 else
[724]63 rm -rf ${BUILDTEMP}/src/${PACKAGE}
64 mkdir -p ${BUILDTEMP}/src/${PACKAGE}
[720]65 cp -a "$1" ${BUILDTEMP}/src/${PACKAGE}
66 cd ${BUILDTEMP}/src/${PACKAGE}; rpm2cpio $1 | cpio -i
[736]67 fi
[720]68else
69 # uses Subversion (svn) to generate more information for the RPM
70 if [ "$BUILD_USES_SVN" = "yes" ]; then
71 echo "receiving subversion information ..."
72 # set RELEASE number (last modification in this directory)
73 # requires subversion (but connection to server isn't neccessary)
74 SVN_BUILD_RELEASE=$(unset LANG; svn info . | sed -n 's/^Last Changed Rev: \([0-9]*\)/\1/p')
75 # in case of local modification a "m" is added to the release number
76 SVN_BUILD_MODIFIED=$(svn status -v | grep "^ *M" | wc -l)
77 # checks if a file is commited,
78 # but update on its directory is not performed
79 SVN_LAST_MODIFICATION=$(svn status -v | sed -n 's/^ *[0-9]* *\([0-9]*\) .*/\1/p' | sort -n | tail -1)
80 if [ $SVN_BUILD_MODIFIED -gt 0 ]; then
81 SVN_BUILD_RELEASE=${SVN_BUILD_RELEASE}m
[723]82 REBUILD="yes"
[720]83 elif [ $SVN_LAST_MODIFICATION -ne $SVN_BUILD_RELEASE ]; then
84 SVN_BUILD_RELEASE=${SVN_BUILD_RELEASE}p
[723]85 REBUILD="yes"
[720]86 fi
[726]87
[720]88 if [ "$SVN_BUILD_RELEASE" ]; then
[721]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
[720]93 fi
94 echo "SVN_BUILD_RELEASE: $SVN_BUILD_RELEASE"
[743]95 echo "VERSION: $VERSION"
96
97 #
98 # check, if RPM should be build again
99 #
100 if [ -z "$REBUILD" ]; then
101 # check if RPM has been built already
102 # TODO: is this useful for OpenSUSE Build Service?
103 EXPECTED_DEST_RPM_FILENAME=${DEST_DIR}/${BUILD_DIST}/${PACKAGE}-${VERSION}-*.*.rpm
104 echo "EXPECTED_DEST_RPM_FILENAME: $EXPECTED_DEST_RPM_FILENAME"
105 if find $EXPECTED_DEST_RPM_FILENAME ; then
106 echo
107 echo "Build of \"${PACKAGE}\" unnecessary."
108 echo "Current RPM already at " $EXPECTED_DEST_RPM_FILENAME
109 echo
110 exit 1
111 fi
112 fi
113
[721]114 printf "adding subversion changelog: "
[720]115 # changelog header
[946]116 echo "-------------------------------------------------------------------" > Changes
117 DATE=`unset LANG; date +"%a %b %d %T UTC %Y"`
118 echo -e "$DATE - svn_build@localhost\n" >> Changes
[720]119 echo "- Subversion status:" >> Changes
120 # additional infos for the Changes file (see if everything is checked in)
121 svn status -v | grep -v '^? ' >> Changes
122 echo >> Changes
123 echo "- ChangeLog:" >> Changes
124 # requires connection to the subversion server
125 svn log -v . > ChangeLog.new && mv ChangeLog.new ChangeLog
[946]126 # indent all svn revisions by "- ", to form a changelog entry,
127 # changelog format uses * at the start of the line to determine new entry,
128 # therefore replace our * by -
129 # % may be treated as a macro, there replaced by %%
130 sed -r -e 's/^(r[0-9]+ \|)/- \1/' -e 's/(^[\*]+)/-/g' -e 's/%/%%/g' ChangeLog >> Changes
131 mv Changes $PACKAGE.changes
[721]132 printf "done\n"
[720]133 fi
[731]134
[720]135 # if "SOURCES" file exist, create tar file on the fly
136 if [ -r "SOURCES" ]; then
137 # create a tar file from the sources
[761]138 SOURCE_ARCHIVE="${PACKAGE}_${VERSION}.orig.tar.gz"
[739]139 printf "creating $SOURCE_ARCHIVE: "
[724]140
[739]141 if [ "$REBUILD" -o ! -r ${BUILDTEMP}/src/${PACKAGE}/$SOURCE_ARCHIVE ]; then
[724]142 rm -rf ${BUILDTEMP}/src/${PACKAGE}
143 mkdir -p ${BUILDTEMP}/src/${PACKAGE}
[739]144 tar cvzf ${BUILDTEMP}/src/${PACKAGE}/$SOURCE_ARCHIVE --files-from SOURCES --exclude .svn --exclude "*~"
[724]145 else
146 printf "already exists. Skipped\n"
[739]147 printf " (${BUILDTEMP}/src/${PACKAGE}/$SOURCE_ARCHIVE)\n"
[741]148 # exit, but without error, so that the calling script will continue
149 exit 0
[724]150 fi
[720]151 elif [ -r "SPECSOURCES" ]; then
152 # SPECSOURCES has to list the files
153 # that are referenced in the .spec file
154 # these files are copied to the build environment
[724]155 rm -rf ${BUILDTEMP}/src/${PACKAGE}
156 mkdir -p ${BUILDTEMP}/src/${PACKAGE}
[720]157 cp -av `cat SPECSOURCES` ${BUILDTEMP}/src/${PACKAGE}
[951]158
159 # do not modify SPEC-file
160 unset BUILD_MODIFIES_SPEC
[1173]161
162 else
[724]163 printf "error: neither SOURCES nor SPECSOURCES file found. One of these is required. Exiting\n"
164 exit 255
[720]165 fi
[726]166
[761]167 # copy orig SPEC-file (may be modified later)
[1173]168 cp -p $SPECFILE ${BUILDTEMP}/src/${PACKAGE}/
[946]169 test -r ${PACKAGE}.changes && cp -a ${PACKAGE}.changes ${BUILDTEMP}/src/${PACKAGE}/
[761]170
[726]171 echo $SVN_BUILD_RELEASE
[951]172 if [ "$BUILD_MODIFIES_SPEC" = "yes" ]; then
173 if [ "$SVN_BUILD_RELEASE" ]; then
174 # Release will be overwritten bei OpenSUSE build service,
175 # therefore we add SVN_BUILD_RELEASE to Version
176 #sed "s/^Release:.*/Release: $SVN_BUILD_RELEASE/ig" $SPECFILE > ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
177 #sed -r "s/^(Version:\s*\S*)/\1.$SVN_BUILD_RELEASE/ig" $SPECFILE > ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
178 sed -i "s/^Version:.*/Version: $VERSION/ig" ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
179 fi
[726]180
[951]181 if [ "$SOURCE_ARCHIVE" ]; then
182 sed -i "s/^Source:.*/Source: $SOURCE_ARCHIVE/ig" ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
183 fi
[761]184 fi
185
[726]186 # if there is no changelog section in the spec file,
187 # also append the Changes there
[946]188 # if ! grep -q -i "%changelog" $SPECFILE ; then
189 # # paste "Changes" into SPEC file.
190 # echo "%changelog" >> ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
191 # # without trailing *, except for the initial
192 # echo -n "*" >> ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
193 # cat Changes | sed 's/\(^[\*]\+\)//g' >> ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
194 # fi
[726]195
[729]196 # if there is a directory named "debian", prepare the
197 # necessary files to build a debian package on OpenSUSE build service
[731]198 if [ -d debian ]; then
[729]199
200 # create a changelog file
[728]201 (echo "${PACKAGE} (${VERSION}-1) unstable; urgency=low"
202 echo
203 echo " * generated from SVN revision ${SVN_BUILD_RELEASE}"
204 echo
205 echo -n " -- dass IT GmbH <info@dass-it.de> "; date +"%a, %e %b %Y %X %z"
206 echo
[731]207 )>debian/changelog
208
209 tar cvzf ${BUILDTEMP}/src/${PACKAGE}/${PACKAGE}_${VERSION}.orig.tar.gz --files-from SOURCES --exclude .svn --exclude "*~"
210
211 # create DSC file from template
212 # replace version number in the description file
[1198]213 if [ -r "${PACKAGE}.dsc" ]; then
214 DSC="${PACKAGE}.dsc"
215 elif [ -r "debian/${PACKAGE}.dsc" ]; then
216 DSC="debian/${PACKAGE}.dsc"
217 else
218 echo "failed: debian directory exists, but ${PACKAGE}.dsc not found."
219 exit 1
220 fi
221 sed -e "s/^Version:.*/Version: $VERSION-1/ig" -e "/^Files:/,$ d" "$DSC" >${BUILDTEMP}/src/${PACKAGE}/${PACKAGE}_${VERSION}-1.dsc
[731]222
223 # update the file list in the description file
224 files="${PACKAGE}_${VERSION}.orig.tar.gz"
225 echo "Files: " >> ${BUILDTEMP}/src/${PACKAGE}/${PACKAGE}_${VERSION}-1.dsc
226 for filename in $files; do
227 path=${BUILDTEMP}/src/${PACKAGE}/$filename
228 printf ' %s %s %s\n' `md5 $path` `filesize $path` $filename >> ${BUILDTEMP}/src/${PACKAGE}/${PACKAGE}_${VERSION}-1.dsc
229 done
230
[728]231 fi
[731]232
[978]233 if [ -r "EXTRASOURCES" ]; then
234 # EXTRASOURCES has to list the files
235 # that are used to control the buildprocess of
236 # obs. rpmlintrc is such an example
237 # these files are copied to the build environment
238 mkdir -p ${BUILDTEMP}/src/${PACKAGE}
239 cp -av `cat EXTRASOURCES` ${BUILDTEMP}/src/${PACKAGE}
240 fi
[720]241fi
[730]242exit 0
Note: See TracBrowser for help on using the repository browser.