[690] | 1 | #!/bin/bash
|
---|
[694] | 2 | # build script
|
---|
| 3 | #
|
---|
[675] | 4 | # $Id: build.sh 717 2007-09-11 08:28:07Z joergs $
|
---|
[585] | 5 | #
|
---|
[694] | 6 | # builds RPM in an clean chroot build environment.
|
---|
| 7 | # uses the Suse build script.
|
---|
[682] | 8 | #
|
---|
[694] | 9 | # without parameter, it checks the directory for the files
|
---|
| 10 | # SOURCES or SPECSOURCES.
|
---|
| 11 | # The files definied in there are copied to the
|
---|
| 12 | # build system.
|
---|
| 13 | #
|
---|
| 14 | # when used with parameter,
|
---|
| 15 | # this parameter is expected to be a source rpm
|
---|
| 16 | #
|
---|
| 17 | # config file:
|
---|
| 18 | # /usr/local/etc/build
|
---|
| 19 | # lists the sources for the different distributions
|
---|
| 20 | #
|
---|
| 21 | # the rest is controlled by environment variables
|
---|
| 22 | #
|
---|
| 23 | # build.sh uses sudo su. /etc/sudoers needs a line like:
|
---|
| 24 | # %users ALL=(ALL) NOPASSWD: /bin/su
|
---|
| 25 | # for automatic building
|
---|
[695] | 26 | #
|
---|
| 27 | # return codes:
|
---|
| 28 | # 0: success
|
---|
| 29 | # 1: skipped (current RPM already in dest dir)
|
---|
| 30 | # >1: error
|
---|
[696] | 31 | #
|
---|
| 32 | # RPM releases are set
|
---|
| 33 | # to the svn version number of the project directory.
|
---|
| 34 | # Modifiers are:
|
---|
| 35 | # m: release + local modifications
|
---|
| 36 | # p: release + submited modifications. svn update project directory is needed
|
---|
[585] | 37 |
|
---|
[695] | 38 |
|
---|
[696] | 39 |
|
---|
| 40 |
|
---|
[668] | 41 | CONFIG_FILE=/usr/local/etc/build
|
---|
[677] | 42 | BUILD_CMD=build
|
---|
[585] | 43 | BUILDUSER=$USER
|
---|
| 44 |
|
---|
[714] | 45 | [ -z "$BUILD_MODE" ] && BUILD_MODE="--clean"
|
---|
[700] | 46 | [ -z "$BUILD_DIST" ] && BUILD_DIST="sles9-i386"
|
---|
[668] | 47 | [ -z "$BUILD_ROOT" ] && BUILD_ROOT="/var/tmp/buildsystem.$USER.$BUILD_DIST"
|
---|
[586] | 48 | [ -z "$BUILD_PREPARE_SPEC" ] && BUILD_PREPARE_SPEC="no"
|
---|
[585] | 49 |
|
---|
[668] | 50 | [ -z $DEST_DIR ] && DEST_DIR="/tmp/build.$BUILDUSER"
|
---|
[694] | 51 | BUILDTEMP=$DEST_DIR/buildsrc/
|
---|
| 52 | BUILDSCRIPT=$BUILDTEMP/buildscript.$$
|
---|
[585] | 53 |
|
---|
[682] | 54 | [ -z "$BUILD_USES_SVN" ] && BUILD_USES_SVN="yes"
|
---|
| 55 |
|
---|
| 56 |
|
---|
| 57 |
|
---|
[668] | 58 | if [ -r $CONFIG_FILE ]; then
|
---|
| 59 | source $CONFIG_FILE
|
---|
| 60 | MOD_BUILD_DIST=`echo $BUILD_DIST | sed "s/[-+.]/_/g"`
|
---|
| 61 | #echo MOD_BUILD_DIST: $MOD_BUILD_DIST
|
---|
| 62 | #RPMS_PATHS=$[BUILD_RPMS_$MOD_BUILD_DIST]
|
---|
| 63 | #echo RPMS_PATHS: $RPM_PATHS
|
---|
| 64 | #if [ -n "$[BUILD_RPMS_$MOD_BUILD_DIST]" ]; then
|
---|
| 65 | # BUILD_RPMS=$[BUILD_RPMS_$MOD_BUILD_DIST]
|
---|
| 66 | #fi
|
---|
| 67 | #echo OUTPUT: $[BUILD_RPMS_$MOD_BUILD_DIST]
|
---|
| 68 | #:$BUILD_RPMS
|
---|
| 69 | case "$BUILD_DIST" in
|
---|
| 70 | "9.0-i386")
|
---|
| 71 | BUILD_RPMS_TEST=$BUILD_RPMS_9_0_i386 ;;
|
---|
| 72 | "sles8-i386")
|
---|
| 73 | BUILD_RPMS_TEST=$BUILD_RPMS_sles8_i386 ;;
|
---|
| 74 | "sles8-i386+update")
|
---|
| 75 | BUILD_RPMS_TEST=$BUILD_RPMS_sles8_i386_update ;;
|
---|
[679] | 76 | "9.1-i386")
|
---|
| 77 | BUILD_RPMS_TEST=$BUILD_RPMS_9_1_i386 ;;
|
---|
[681] | 78 | "sles9-i386")
|
---|
| 79 | BUILD_RPMS_TEST=$BUILD_RPMS_sles9_i386 ;;
|
---|
[705] | 80 | "9.2-i386")
|
---|
| 81 | BUILD_RPMS_TEST=$BUILD_RPMS_9_2_i386 ;;
|
---|
[709] | 82 | "9.3-i386")
|
---|
| 83 | BUILD_RPMS_TEST=$BUILD_RPMS_9_3_i386 ;;
|
---|
[712] | 84 | "10.0-i386")
|
---|
[717] | 85 | BUILD_RPMS_TEST=$BUILD_RPMS_10_0_i386 ;;
|
---|
| 86 | "10.2-i386")
|
---|
| 87 | BUILD_RPMS_TEST=$BUILD_RPMS_10_2_i386 ;;
|
---|
[668] | 88 | esac
|
---|
| 89 | if [ "$BUILD_RPMS_TEST" ]; then
|
---|
| 90 | if [ "$BUILD_RPMS" ]; then
|
---|
| 91 | BUILD_RPMS=$BUILD_RPMS:$BUILD_RPMS_TEST
|
---|
| 92 | else
|
---|
| 93 | BUILD_RPMS=$BUILD_RPMS_TEST
|
---|
| 94 | fi
|
---|
| 95 | fi
|
---|
| 96 | fi
|
---|
| 97 |
|
---|
| 98 | echo BUILD_RPMS: $BUILD_RPMS
|
---|
| 99 |
|
---|
[619] | 100 | ERROR=0
|
---|
[585] | 101 |
|
---|
[621] | 102 | # Hier gehts los:
|
---|
[620] | 103 |
|
---|
| 104 | if [ -z "$1" ]; then
|
---|
| 105 | # without parameter, we are in source directory
|
---|
| 106 | SPECFILE=$(ls *.spec | awk '{print $1}')
|
---|
[716] | 107 | PACKAGE=$(sed -n -e 's/^Name:\W*//pi' <$SPECFILE)
|
---|
| 108 | VERSION=$(sed -n -e 's/^Version:\W*//pi' <$SPECFILE)
|
---|
[715] | 109 | elif [ -r "$1" ]; then
|
---|
[620] | 110 | # parameter is src.rpm file
|
---|
[715] | 111 | PACKAGE=`rpm -qp --qf "%{NAME}" $1`
|
---|
| 112 | VERSION=`rpm -qp --qf "%{VERSION}" $1`
|
---|
[620] | 113 | fi
|
---|
| 114 |
|
---|
[622] | 115 | echo $PACKAGE $VERSION $BUILD_DIST $BUILD_MODE
|
---|
[585] | 116 |
|
---|
[715] | 117 | if [ -z "$PACKAGE" ]; then
|
---|
| 118 | echo "nothing to build found!"
|
---|
| 119 | exit 1
|
---|
| 120 | fi
|
---|
| 121 |
|
---|
| 122 |
|
---|
| 123 |
|
---|
[682] | 124 | rm -rf ${BUILDTEMP}/src/${PACKAGE};
|
---|
[694] | 125 | mkdir -p ${BUILDTEMP}/src/${PACKAGE}
|
---|
| 126 | # ${BUILDTEMP}/${BUILD_DIST};
|
---|
[585] | 127 |
|
---|
[620] | 128 | if [ "$1" ]; then
|
---|
[695] | 129 | EXPECTED_DEST_RPM_FILENAME=${DEST_DIR}/${BUILD_DIST}/`echo $1 | sed 's/\.src\./.*./'`
|
---|
| 130 | if [ -f $EXPECTED_DEST_RPM_FILENAME ]; then
|
---|
| 131 | echo
|
---|
| 132 | echo "Build of \"${PACKAGE}\" unnecessary. Current RPM already at " $EXPECTED_DEST_RPM_FILENAME
|
---|
| 133 | echo
|
---|
| 134 | exit 1
|
---|
| 135 | else
|
---|
| 136 | cp -a "$1" ${BUILDTEMP}/src/${PACKAGE}
|
---|
| 137 | cd ${BUILDTEMP}/src/${PACKAGE}; rpm2cpio $1 | cpio -i
|
---|
| 138 | fi
|
---|
[682] | 139 | else
|
---|
| 140 | cp -a $SPECFILE ${BUILDTEMP}/src/${PACKAGE}
|
---|
| 141 |
|
---|
| 142 | # uses Subversion (svn) to generate more information for the RPM
|
---|
| 143 | if [ "$BUILD_USES_SVN" = "yes" ]; then
|
---|
| 144 | echo "receiving subversion information ..."
|
---|
| 145 | # set RELEASE number (last modification in this directory)
|
---|
| 146 | # requires subversion (but connection to server isn't neccessary)
|
---|
[712] | 147 | SVN_BUILD_RELEASE=$(unset LANG; svn info . | sed -n 's/^Last Changed Rev: \([0-9]*\)/\1/p')
|
---|
[694] | 148 | # in case of local modification a "m" is added to the release number
|
---|
| 149 | SVN_BUILD_MODIFIED=$(svn status -v | grep "^ *M" | wc -l)
|
---|
[695] | 150 | # checks if a file is commited,
|
---|
| 151 | # but update on its directory is not performed
|
---|
| 152 | SVN_LAST_MODIFICATION=$(svn status -v | sed -n 's/^ *[0-9]* *\([0-9]*\) .*/\1/p' | sort -n | tail -1)
|
---|
| 153 | if [ $SVN_BUILD_MODIFIED -gt 0 ]; then
|
---|
[694] | 154 | SVN_BUILD_RELEASE=${SVN_BUILD_RELEASE}m
|
---|
[695] | 155 | elif [ $SVN_LAST_MODIFICATION -ne $SVN_BUILD_RELEASE ]; then
|
---|
| 156 | SVN_BUILD_RELEASE=${SVN_BUILD_RELEASE}p
|
---|
[694] | 157 | else # check if RPM has been build already
|
---|
| 158 | EXPECTED_DEST_RPM_FILENAME=${DEST_DIR}/${BUILD_DIST}/${PACKAGE}-${VERSION}-${SVN_BUILD_RELEASE}.*.rpm
|
---|
| 159 | if [ -f $EXPECTED_DEST_RPM_FILENAME ]; then
|
---|
| 160 | echo
|
---|
| 161 | echo "Build of \"${PACKAGE}\" unnecessary. Current RPM already at " $EXPECTED_DEST_RPM_FILENAME
|
---|
| 162 | echo
|
---|
[695] | 163 | exit 1
|
---|
[694] | 164 | fi
|
---|
| 165 | fi
|
---|
[682] | 166 | if [ "$SVN_BUILD_RELEASE" ]; then
|
---|
[716] | 167 | sed "s/^Release:.*/Release: $SVN_BUILD_RELEASE/ig" $SPECFILE > ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
|
---|
[682] | 168 | fi
|
---|
[710] | 169 | echo "SVN_BUILD_RELEASE: $SVN_BUILD_RELEASE"
|
---|
| 170 |
|
---|
[683] | 171 | # changelog header
|
---|
| 172 | DATE=`unset LANG; date +"%a %b %d %Y"`
|
---|
| 173 | echo -e "* $DATE -\n" > Changes
|
---|
| 174 | echo "- Subversion status:" >> Changes
|
---|
[682] | 175 | # additional infos for the Changes file (see if everything is checked in)
|
---|
| 176 | svn status -v | grep -v '^? ' >> Changes
|
---|
| 177 | echo >> Changes
|
---|
[683] | 178 | echo "- ChangeLog:" >> Changes
|
---|
[682] | 179 | # requires connection to the subversion server
|
---|
| 180 | svn log -v . > ChangeLog.new && mv ChangeLog.new ChangeLog
|
---|
| 181 | cat ChangeLog >> Changes
|
---|
[684] | 182 |
|
---|
| 183 | # if there is no changelog section in the spec file,
|
---|
| 184 | # also append the Changes there
|
---|
| 185 | if ! grep -q "%changelog" $SPECFILE ; then
|
---|
| 186 | # paste "Changes" into SPEC file.
|
---|
| 187 | echo "%changelog" >> ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
|
---|
| 188 | # without trailing *, except for the initial
|
---|
| 189 | echo -n "*" >> ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
|
---|
| 190 | cat Changes | sed 's/\(^[\*]\+\)//g' >> ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
|
---|
| 191 | fi
|
---|
[682] | 192 | fi
|
---|
| 193 | # just make sure, that the Changes file exist
|
---|
| 194 | touch Changes
|
---|
| 195 |
|
---|
| 196 | # if "SOURCES" file exist, create tar file on the fly
|
---|
| 197 | if [ -r "SOURCES" ]; then
|
---|
| 198 | # create a tar file from the sources
|
---|
[701] | 199 | tar cvjf ${BUILDTEMP}/src/${PACKAGE}/$PACKAGE-$VERSION.tar.bz2 --files-from SOURCES --exclude .svn --exclude "*~"
|
---|
[690] | 200 |
|
---|
| 201 | elif [ -r "SPECSOURCES" ]; then
|
---|
[701] | 202 | # SPECSOURCES has to list the files
|
---|
| 203 | # that are referenced in the .spec file
|
---|
| 204 | # these files are copied to the build environment
|
---|
[690] | 205 | cp -av `cat SPECSOURCES` ${BUILDTEMP}/src/${PACKAGE}
|
---|
| 206 |
|
---|
[682] | 207 | else
|
---|
| 208 | # legacy method:
|
---|
[701] | 209 | # call the existing Makefile
|
---|
| 210 | # to generate a tar file
|
---|
[682] | 211 | test -e Makefile && make
|
---|
| 212 | TARFILE=$(ls *.tar.[gb]z*| awk '{print $1}')
|
---|
[690] | 213 | cp -av $TARFILE ${BUILDTEMP}/src/${PACKAGE}
|
---|
[682] | 214 | fi
|
---|
[620] | 215 | fi
|
---|
| 216 |
|
---|
[585] | 217 | # create buildscript
|
---|
[668] | 218 | cat > $BUILDSCRIPT <<EOF
|
---|
[585] | 219 | #!/bin/bash
|
---|
| 220 | # local buildscript
|
---|
| 221 | export BUILD_ROOT=$BUILD_ROOT
|
---|
| 222 | export BUILD_DIST=$BUILD_DIST
|
---|
[694] | 223 | export BUILD_RPMS=${DEST_DIR}/${BUILD_DIST}:$BUILD_RPMS
|
---|
[586] | 224 | export BUILD_PREPARE_SPEC=$BUILD_PREPARE_SPEC
|
---|
| 225 |
|
---|
[668] | 226 | cd ${BUILDTEMP}/src/${PACKAGE}
|
---|
[677] | 227 | $BUILD_CMD $BUILD_MODE
|
---|
[585] | 228 | EOF
|
---|
[681] | 229 |
|
---|
[668] | 230 | chmod a+x $BUILDSCRIPT
|
---|
| 231 | sudo su -c $BUILDSCRIPT
|
---|
| 232 | rm -f $BUILDSCRIPT
|
---|
| 233 |
|
---|
[585] | 234 | mkdir -p ${DEST_DIR}/src
|
---|
[620] | 235 | # delete all old versions of this package
|
---|
[695] | 236 | for i in ${DEST_DIR}/src/${PACKAGE}-*.src.rpm; do
|
---|
| 237 | if [ -f $i -a ${PACKAGE} = "`rpm -qp --qf "%{NAME}\n" $i`" ]; then
|
---|
| 238 | rm $i
|
---|
| 239 | fi
|
---|
| 240 | done
|
---|
| 241 | #rm -f ${DEST_DIR}/src/${PACKAGE}-*.src.rpm
|
---|
[682] | 242 |
|
---|
[668] | 243 | if !(cp -a ${BUILD_ROOT}/usr/src/packages/SRPMS/${PACKAGE}-${VERSION}-*.src.rpm ${DEST_DIR}/src 2> /dev/null); then
|
---|
[695] | 244 | ERROR=4
|
---|
[619] | 245 | fi
|
---|
[585] | 246 |
|
---|
[619] | 247 | mkdir -p ${DEST_DIR}/${BUILD_DIST}
|
---|
[620] | 248 | # delete all old versions of this package
|
---|
[695] | 249 | for i in ${DEST_DIR}/${BUILD_DIST}/${PACKAGE}-*.rpm; do
|
---|
| 250 | if [ -f $i -a ${PACKAGE} = "`rpm -qp --qf "%{NAME}\n" $i`" ]; then
|
---|
| 251 | rm $i
|
---|
| 252 | fi
|
---|
| 253 | done
|
---|
| 254 | #rm -f ${DEST_DIR}/${BUILD_DIST}/${PACKAGE}-*.rpm
|
---|
[682] | 255 |
|
---|
[692] | 256 | if !(cp -a ${BUILD_ROOT}/usr/src/packages/RPMS/*/${PACKAGE}*${VERSION}-*.*.rpm ${DEST_DIR}/${BUILD_DIST} ); then
|
---|
[695] | 257 | ERROR=8
|
---|
[591] | 258 | fi
|
---|
| 259 |
|
---|
[694] | 260 | echo
|
---|
[619] | 261 | if [ $ERROR -ne 0 ]; then
|
---|
[694] | 262 |
|
---|
| 263 | echo "ERROR while building packet $PACKAGE";
|
---|
[619] | 264 | else
|
---|
[694] | 265 | echo "Build of \"${PACKAGE}\" completed!"
|
---|
[619] | 266 | echo "Packages can be found in ${DEST_DIR}"
|
---|
[591] | 267 | fi
|
---|
[694] | 268 | echo
|
---|
[585] | 269 |
|
---|
[619] | 270 | exit $ERROR
|
---|