[720] | 1 | #!/bin/bash
|
---|
| 2 |
|
---|
| 3 | # build prepare script
|
---|
| 4 |
|
---|
| 5 | # $Id: dassbuild_prepare.sh 762 2009-06-12 16:24:00Z 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] | 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 |
|
---|
[720] | 28 | BUILDUSER=$USER
|
---|
| 29 | [ -z $DEST_DIR ] && DEST_DIR="/tmp/build.$BUILDUSER"
|
---|
| 30 | BUILDTEMP=$DEST_DIR/buildsrc/
|
---|
| 31 |
|
---|
[721] | 32 | [ -z "$BUILD_USES_SVN" ] && BUILD_USES_SVN="yes"
|
---|
[720] | 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
|
---|
[721] | 41 | PACKAGE=`rpm -qp --qf "%{NAME}" $1`
|
---|
| 42 | VERSION=`rpm -qp --qf "%{VERSION}" $1`
|
---|
[720] | 43 | fi
|
---|
| 44 |
|
---|
| 45 |
|
---|
| 46 | if [ -z "$PACKAGE" ]; then
|
---|
[740] | 47 | echo "nothing to build found"
|
---|
[724] | 48 | exit 255
|
---|
[720] | 49 | fi
|
---|
| 50 |
|
---|
| 51 |
|
---|
| 52 |
|
---|
| 53 | if [ "$1" ]; then
|
---|
| 54 | EXPECTED_DEST_RPM_FILENAME=${DEST_DIR}/${BUILD_DIST}/`echo $1 | sed 's/\.src\./.*./'`
|
---|
[736] | 55 | if [ -f "$EXPECTED_DEST_RPM_FILENAME" ]; then
|
---|
[720] | 56 | echo
|
---|
| 57 | echo "Build of \"${PACKAGE}\" unnecessary. Current RPM already at " $EXPECTED_DEST_RPM_FILENAME
|
---|
| 58 | echo
|
---|
| 59 | exit 1
|
---|
| 60 | else
|
---|
[724] | 61 | rm -rf ${BUILDTEMP}/src/${PACKAGE}
|
---|
| 62 | mkdir -p ${BUILDTEMP}/src/${PACKAGE}
|
---|
[720] | 63 | cp -a "$1" ${BUILDTEMP}/src/${PACKAGE}
|
---|
| 64 | cd ${BUILDTEMP}/src/${PACKAGE}; rpm2cpio $1 | cpio -i
|
---|
[736] | 65 | fi
|
---|
[720] | 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
|
---|
[723] | 80 | REBUILD="yes"
|
---|
[720] | 81 | elif [ $SVN_LAST_MODIFICATION -ne $SVN_BUILD_RELEASE ]; then
|
---|
| 82 | SVN_BUILD_RELEASE=${SVN_BUILD_RELEASE}p
|
---|
[723] | 83 | REBUILD="yes"
|
---|
[720] | 84 | fi
|
---|
[726] | 85 |
|
---|
[720] | 86 | if [ "$SVN_BUILD_RELEASE" ]; then
|
---|
[721] | 87 | # Release will be overwritten bei OpenSUSE build service,
|
---|
| 88 | # therefore we add SVN_BUILD_RELEASE to Version
|
---|
| 89 | VERSION_ORIG=$VERSION
|
---|
| 90 | VERSION=$VERSION.$SVN_BUILD_RELEASE
|
---|
[720] | 91 | fi
|
---|
| 92 | echo "SVN_BUILD_RELEASE: $SVN_BUILD_RELEASE"
|
---|
[743] | 93 | echo "VERSION: $VERSION"
|
---|
| 94 |
|
---|
| 95 | #
|
---|
| 96 | # check, if RPM should be build again
|
---|
| 97 | #
|
---|
| 98 | if [ -z "$REBUILD" ]; then
|
---|
| 99 | # check if RPM has been built already
|
---|
| 100 | # TODO: is this useful for OpenSUSE Build Service?
|
---|
| 101 | EXPECTED_DEST_RPM_FILENAME=${DEST_DIR}/${BUILD_DIST}/${PACKAGE}-${VERSION}-*.*.rpm
|
---|
| 102 | echo "EXPECTED_DEST_RPM_FILENAME: $EXPECTED_DEST_RPM_FILENAME"
|
---|
| 103 | if find $EXPECTED_DEST_RPM_FILENAME ; then
|
---|
| 104 | echo
|
---|
| 105 | echo "Build of \"${PACKAGE}\" unnecessary."
|
---|
| 106 | echo "Current RPM already at " $EXPECTED_DEST_RPM_FILENAME
|
---|
| 107 | echo
|
---|
| 108 | exit 1
|
---|
| 109 | fi
|
---|
| 110 | fi
|
---|
| 111 |
|
---|
[721] | 112 | printf "adding subversion changelog: "
|
---|
[720] | 113 | # changelog header
|
---|
| 114 | DATE=`unset LANG; date +"%a %b %d %Y"`
|
---|
[727] | 115 | echo -e "* $DATE - svn_build\n" > Changes
|
---|
[720] | 116 | echo "- Subversion status:" >> Changes
|
---|
| 117 | # additional infos for the Changes file (see if everything is checked in)
|
---|
| 118 | svn status -v | grep -v '^? ' >> Changes
|
---|
| 119 | echo >> Changes
|
---|
| 120 | echo "- ChangeLog:" >> Changes
|
---|
| 121 | # requires connection to the subversion server
|
---|
| 122 | svn log -v . > ChangeLog.new && mv ChangeLog.new ChangeLog
|
---|
| 123 | cat ChangeLog >> Changes
|
---|
[761] | 124 |
|
---|
[721] | 125 | printf "done\n"
|
---|
[720] | 126 | fi
|
---|
[731] | 127 |
|
---|
[728] | 128 | # just make sure, that the Changes file exists
|
---|
[720] | 129 | touch Changes
|
---|
[731] | 130 |
|
---|
[720] | 131 | # if "SOURCES" file exist, create tar file on the fly
|
---|
| 132 | if [ -r "SOURCES" ]; then
|
---|
| 133 | # create a tar file from the sources
|
---|
[761] | 134 | SOURCE_ARCHIVE="${PACKAGE}_${VERSION}.orig.tar.gz"
|
---|
[739] | 135 | printf "creating $SOURCE_ARCHIVE: "
|
---|
[724] | 136 |
|
---|
[739] | 137 | if [ "$REBUILD" -o ! -r ${BUILDTEMP}/src/${PACKAGE}/$SOURCE_ARCHIVE ]; then
|
---|
[724] | 138 | rm -rf ${BUILDTEMP}/src/${PACKAGE}
|
---|
| 139 | mkdir -p ${BUILDTEMP}/src/${PACKAGE}
|
---|
[739] | 140 | tar cvzf ${BUILDTEMP}/src/${PACKAGE}/$SOURCE_ARCHIVE --files-from SOURCES --exclude .svn --exclude "*~"
|
---|
[724] | 141 | else
|
---|
| 142 | printf "already exists. Skipped\n"
|
---|
[739] | 143 | printf " (${BUILDTEMP}/src/${PACKAGE}/$SOURCE_ARCHIVE)\n"
|
---|
[741] | 144 | # exit, but without error, so that the calling script will continue
|
---|
| 145 | exit 0
|
---|
[724] | 146 | fi
|
---|
[720] | 147 | elif [ -r "SPECSOURCES" ]; then
|
---|
| 148 | # SPECSOURCES has to list the files
|
---|
| 149 | # that are referenced in the .spec file
|
---|
| 150 | # these files are copied to the build environment
|
---|
[724] | 151 | rm -rf ${BUILDTEMP}/src/${PACKAGE}
|
---|
| 152 | mkdir -p ${BUILDTEMP}/src/${PACKAGE}
|
---|
[720] | 153 | cp -av `cat SPECSOURCES` ${BUILDTEMP}/src/${PACKAGE}
|
---|
| 154 |
|
---|
| 155 | else
|
---|
[724] | 156 | printf "error: neither SOURCES nor SPECSOURCES file found. One of these is required. Exiting\n"
|
---|
| 157 | exit 255
|
---|
[720] | 158 | fi
|
---|
[726] | 159 |
|
---|
[761] | 160 | # copy orig SPEC-file (may be modified later)
|
---|
| 161 | cp -a $SPECFILE ${BUILDTEMP}/src/${PACKAGE}
|
---|
| 162 |
|
---|
[726] | 163 | echo $SVN_BUILD_RELEASE
|
---|
| 164 | if [ "$SVN_BUILD_RELEASE" ]; then
|
---|
| 165 | # Release will be overwritten bei OpenSUSE build service,
|
---|
| 166 | # therefore we add SVN_BUILD_RELEASE to Version
|
---|
| 167 | #sed "s/^Release:.*/Release: $SVN_BUILD_RELEASE/ig" $SPECFILE > ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
|
---|
| 168 | #sed -r "s/^(Version:\s*\S*)/\1.$SVN_BUILD_RELEASE/ig" $SPECFILE > ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
|
---|
[761] | 169 | sed -i "s/^Version:.*/Version: $VERSION/ig" ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
|
---|
[726] | 170 | fi
|
---|
| 171 |
|
---|
[761] | 172 | if [ "$SOURCE_ARCHIVE" ]; then
|
---|
| 173 | sed -i "s/^Source:.*/Source: $SOURCE_ARCHIVE/ig" ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
|
---|
| 174 | fi
|
---|
| 175 |
|
---|
[726] | 176 | # if there is no changelog section in the spec file,
|
---|
| 177 | # also append the Changes there
|
---|
| 178 | if ! grep -q -i "%changelog" $SPECFILE ; then
|
---|
| 179 | # paste "Changes" into SPEC file.
|
---|
| 180 | echo "%changelog" >> ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
|
---|
| 181 | # without trailing *, except for the initial
|
---|
| 182 | echo -n "*" >> ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
|
---|
| 183 | cat Changes | sed 's/\(^[\*]\+\)//g' >> ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
|
---|
| 184 | fi
|
---|
| 185 |
|
---|
[729] | 186 | # if there is a directory named "debian", prepare the
|
---|
| 187 | # necessary files to build a debian package on OpenSUSE build service
|
---|
[731] | 188 | if [ -d debian ]; then
|
---|
[729] | 189 |
|
---|
| 190 | # create a changelog file
|
---|
[728] | 191 | (echo "${PACKAGE} (${VERSION}-1) unstable; urgency=low"
|
---|
| 192 | echo
|
---|
| 193 | echo " * generated from SVN revision ${SVN_BUILD_RELEASE}"
|
---|
| 194 | echo
|
---|
| 195 | echo -n " -- dass IT GmbH <info@dass-it.de> "; date +"%a, %e %b %Y %X %z"
|
---|
| 196 | echo
|
---|
[731] | 197 | )>debian/changelog
|
---|
| 198 |
|
---|
| 199 | tar cvzf ${BUILDTEMP}/src/${PACKAGE}/${PACKAGE}_${VERSION}.orig.tar.gz --files-from SOURCES --exclude .svn --exclude "*~"
|
---|
| 200 |
|
---|
| 201 | # create DSC file from template
|
---|
| 202 | # replace version number in the description file
|
---|
| 203 | sed -e "s/^Version:.*/Version: $VERSION-1/ig" -e "/^Files:/,$ d" debian/${PACKAGE}.dsc >${BUILDTEMP}/src/${PACKAGE}/${PACKAGE}_${VERSION}-1.dsc
|
---|
| 204 |
|
---|
| 205 | # update the file list in the description file
|
---|
| 206 | files="${PACKAGE}_${VERSION}.orig.tar.gz"
|
---|
| 207 | echo "Files: " >> ${BUILDTEMP}/src/${PACKAGE}/${PACKAGE}_${VERSION}-1.dsc
|
---|
| 208 | for filename in $files; do
|
---|
| 209 | path=${BUILDTEMP}/src/${PACKAGE}/$filename
|
---|
| 210 | printf ' %s %s %s\n' `md5 $path` `filesize $path` $filename >> ${BUILDTEMP}/src/${PACKAGE}/${PACKAGE}_${VERSION}-1.dsc
|
---|
| 211 | done
|
---|
| 212 |
|
---|
[728] | 213 | fi
|
---|
[731] | 214 |
|
---|
| 215 |
|
---|
[720] | 216 | fi
|
---|
[730] | 217 | exit 0
|
---|