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

Last change on this file since 1251 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
Line 
1#!/bin/bash
2
3# build prepare script
4
5# $Id: dassbuild_prepare.sh 1198 2015-10-13 15:04:59Z joergs $
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.gz creation
14
15
16filesize()
17{
18 stat --format='%s' $*
19}
20
21md5()
22{
23 md5sum $* | cut -f 1 -d ' '
24}
25
26export LANG=C
27
28BUILDUSER=$USER
29[ -z $DEST_DIR ] && DEST_DIR="/tmp/build.$BUILDUSER"
30BUILDTEMP=$DEST_DIR/buildsrc/
31
32[ -z "$BUILD_USES_SVN" ] && BUILD_USES_SVN="yes"
33[ -z "$BUILD_MODIFIES_SPEC" ] && BUILD_MODIFIES_SPEC="yes"
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
42 PACKAGE=`rpm -qp --qf "%{NAME}" $1`
43 VERSION=`rpm -qp --qf "%{VERSION}" $1`
44 unset BUILD_MODIFIES_SPEC
45fi
46
47
48if [ -z "$PACKAGE" ]; then
49 echo "nothing to build found"
50 exit 255
51fi
52
53
54
55if [ "$1" ]; then
56 EXPECTED_DEST_RPM_FILENAME=${DEST_DIR}/${BUILD_DIST}/`echo $1 | sed 's/\.src\./.*./'`
57 if [ -f "$EXPECTED_DEST_RPM_FILENAME" ]; then
58 echo
59 echo "Build of \"${PACKAGE}\" unnecessary. Current RPM already at " $EXPECTED_DEST_RPM_FILENAME
60 echo
61 exit 1
62 else
63 rm -rf ${BUILDTEMP}/src/${PACKAGE}
64 mkdir -p ${BUILDTEMP}/src/${PACKAGE}
65 cp -a "$1" ${BUILDTEMP}/src/${PACKAGE}
66 cd ${BUILDTEMP}/src/${PACKAGE}; rpm2cpio $1 | cpio -i
67 fi
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
82 REBUILD="yes"
83 elif [ $SVN_LAST_MODIFICATION -ne $SVN_BUILD_RELEASE ]; then
84 SVN_BUILD_RELEASE=${SVN_BUILD_RELEASE}p
85 REBUILD="yes"
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 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
114 printf "adding subversion changelog: "
115 # changelog header
116 echo "-------------------------------------------------------------------" > Changes
117 DATE=`unset LANG; date +"%a %b %d %T UTC %Y"`
118 echo -e "$DATE - svn_build@localhost\n" >> Changes
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
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
132 printf "done\n"
133 fi
134
135 # if "SOURCES" file exist, create tar file on the fly
136 if [ -r "SOURCES" ]; then
137 # create a tar file from the sources
138 SOURCE_ARCHIVE="${PACKAGE}_${VERSION}.orig.tar.gz"
139 printf "creating $SOURCE_ARCHIVE: "
140
141 if [ "$REBUILD" -o ! -r ${BUILDTEMP}/src/${PACKAGE}/$SOURCE_ARCHIVE ]; then
142 rm -rf ${BUILDTEMP}/src/${PACKAGE}
143 mkdir -p ${BUILDTEMP}/src/${PACKAGE}
144 tar cvzf ${BUILDTEMP}/src/${PACKAGE}/$SOURCE_ARCHIVE --files-from SOURCES --exclude .svn --exclude "*~"
145 else
146 printf "already exists. Skipped\n"
147 printf " (${BUILDTEMP}/src/${PACKAGE}/$SOURCE_ARCHIVE)\n"
148 # exit, but without error, so that the calling script will continue
149 exit 0
150 fi
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
155 rm -rf ${BUILDTEMP}/src/${PACKAGE}
156 mkdir -p ${BUILDTEMP}/src/${PACKAGE}
157 cp -av `cat SPECSOURCES` ${BUILDTEMP}/src/${PACKAGE}
158
159 # do not modify SPEC-file
160 unset BUILD_MODIFIES_SPEC
161
162 else
163 printf "error: neither SOURCES nor SPECSOURCES file found. One of these is required. Exiting\n"
164 exit 255
165 fi
166
167 # copy orig SPEC-file (may be modified later)
168 cp -p $SPECFILE ${BUILDTEMP}/src/${PACKAGE}/
169 test -r ${PACKAGE}.changes && cp -a ${PACKAGE}.changes ${BUILDTEMP}/src/${PACKAGE}/
170
171 echo $SVN_BUILD_RELEASE
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
180
181 if [ "$SOURCE_ARCHIVE" ]; then
182 sed -i "s/^Source:.*/Source: $SOURCE_ARCHIVE/ig" ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
183 fi
184 fi
185
186 # if there is no changelog section in the spec file,
187 # also append the Changes there
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
195
196 # if there is a directory named "debian", prepare the
197 # necessary files to build a debian package on OpenSUSE build service
198 if [ -d debian ]; then
199
200 # create a changelog file
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
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
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
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
231 fi
232
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
241fi
242exit 0
Note: See TracBrowser for help on using the repository browser.