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