[690] | 1 | #!/bin/bash
|
---|
[694] | 2 | # build script
|
---|
| 3 | #
|
---|
[675] | 4 | # $Id: dassbuild.sh 755 2009-06-12 14:43:35Z 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:
|
---|
[750] | 18 | # /etc/dassbuild.conf
|
---|
[694] | 19 | # lists the sources for the different distributions
|
---|
| 20 | #
|
---|
| 21 | # the rest is controlled by environment variables
|
---|
| 22 | #
|
---|
[750] | 23 | # dassbuild.sh uses sudo. /etc/sudoers needs a line like:
|
---|
| 24 | # %users ALL=(ALL) NOPASSWD: /usr/bin/dassbuild_wrapper.sh
|
---|
[733] | 25 | # for automatic building (create a symlink or copy the file,
|
---|
| 26 | # see also the Variable BUILDSCRIPT and content of this script)
|
---|
[695] | 27 | #
|
---|
| 28 | # return codes:
|
---|
| 29 | # 0: success
|
---|
| 30 | # 1: skipped (current RPM already in dest dir)
|
---|
| 31 | # >1: error
|
---|
[696] | 32 | #
|
---|
| 33 | # RPM releases are set
|
---|
| 34 | # to the svn version number of the project directory.
|
---|
| 35 | # Modifiers are:
|
---|
| 36 | # m: release + local modifications
|
---|
| 37 | # p: release + submited modifications. svn update project directory is needed
|
---|
[585] | 38 |
|
---|
[695] | 39 |
|
---|
[733] | 40 | # set LANG to default (english)
|
---|
| 41 | # required for SVN
|
---|
| 42 | export LC_ALL=C
|
---|
[696] | 43 |
|
---|
[755] | 44 | CONFIG_FILE=/etc/dassbuild/dassbuild.conf
|
---|
[750] | 45 | BUILDSCRIPT=/usr/bin/dassbuild_wrapper.sh
|
---|
[735] | 46 | BUILD_CMD=/usr/bin/build
|
---|
[744] | 47 |
|
---|
| 48 | #
|
---|
| 49 | # setting build variables
|
---|
| 50 | #
|
---|
[585] | 51 | BUILDUSER=$USER
|
---|
[744] | 52 | [ -z $DEST_DIR ] && DEST_DIR="/tmp/build.$BUILDUSER"
|
---|
| 53 | BUILDTEMP=$DEST_DIR/buildsrc/
|
---|
[585] | 54 |
|
---|
[744] | 55 | [ -z "$BUILD_USES_SVN" ] && BUILD_USES_SVN="yes"
|
---|
[714] | 56 | [ -z "$BUILD_MODE" ] && BUILD_MODE="--clean"
|
---|
[744] | 57 | [ -z "$BUILD_DIST" ] && export BUILD_DIST="sles9-i386"
|
---|
| 58 | [ -z "$BUILD_ROOT" ] && BUILD_ROOT="/var/tmp/buildsystem.$BUILDUSER.$BUILD_DIST"
|
---|
[586] | 59 | [ -z "$BUILD_PREPARE_SPEC" ] && BUILD_PREPARE_SPEC="no"
|
---|
[585] | 60 |
|
---|
[733] | 61 | BUILDVARS=$BUILDTEMP/build.vars
|
---|
[585] | 62 |
|
---|
[744] | 63 | #
|
---|
| 64 | # create source archive file
|
---|
| 65 | #
|
---|
[750] | 66 | dassbuild_prepare.sh $*
|
---|
[744] | 67 | RT=$?
|
---|
| 68 | if [ $RT -eq 1 ]; then
|
---|
| 69 | echo "nothing more to do"
|
---|
| 70 | exit 0
|
---|
| 71 | elif [ $RT -gt 1 ]; then
|
---|
| 72 | echo "error: failed to prepare sources"
|
---|
| 73 | exit 1
|
---|
| 74 | fi
|
---|
[682] | 75 |
|
---|
| 76 |
|
---|
| 77 |
|
---|
[668] | 78 | if [ -r $CONFIG_FILE ]; then
|
---|
| 79 | source $CONFIG_FILE
|
---|
[718] | 80 | MOD_BUILD_DIST=`sed "s/[-+.]/_/g" <<< $BUILD_DIST`
|
---|
| 81 | echo MOD_BUILD_DIST: $MOD_BUILD_DIST
|
---|
| 82 | eval BUILD_RPMS_TEST=\$BUILD_RPMS_$MOD_BUILD_DIST
|
---|
| 83 |
|
---|
[668] | 84 | if [ "$BUILD_RPMS_TEST" ]; then
|
---|
| 85 | if [ "$BUILD_RPMS" ]; then
|
---|
| 86 | BUILD_RPMS=$BUILD_RPMS:$BUILD_RPMS_TEST
|
---|
| 87 | else
|
---|
| 88 | BUILD_RPMS=$BUILD_RPMS_TEST
|
---|
| 89 | fi
|
---|
| 90 | fi
|
---|
| 91 | fi
|
---|
| 92 |
|
---|
| 93 | echo BUILD_RPMS: $BUILD_RPMS
|
---|
| 94 |
|
---|
[619] | 95 | ERROR=0
|
---|
[585] | 96 |
|
---|
[621] | 97 | # Hier gehts los:
|
---|
[620] | 98 |
|
---|
| 99 | if [ -z "$1" ]; then
|
---|
[744] | 100 | # without parameter, we are in source directory
|
---|
| 101 | SPECFILE=$(ls *.spec | awk '{print $1}')
|
---|
| 102 | PACKAGE=$(sed -n -e 's/^Name:\W*//pi' <$SPECFILE)
|
---|
| 103 | # use Version from BUILDSRC,
|
---|
| 104 | # because it has been modified by svn_build_prepare
|
---|
| 105 | BUILDSRC_DIR=${BUILDTEMP}/src/${PACKAGE}
|
---|
| 106 | VERSION=$(sed -n -e 's/^Version:\W*//pi' <$BUILDSRC_DIR/$SPECFILE)
|
---|
[715] | 107 | elif [ -r "$1" ]; then
|
---|
[744] | 108 | # parameter is src.rpm file
|
---|
| 109 | PACKAGE=`rpm -qp --qf "%{NAME}" $1`
|
---|
| 110 | VERSION=`rpm -qp --qf "%{VERSION}" $1`
|
---|
[620] | 111 | fi
|
---|
| 112 |
|
---|
[622] | 113 | echo $PACKAGE $VERSION $BUILD_DIST $BUILD_MODE
|
---|
[585] | 114 |
|
---|
[715] | 115 | if [ -z "$PACKAGE" ]; then
|
---|
| 116 | echo "nothing to build found!"
|
---|
| 117 | exit 1
|
---|
| 118 | fi
|
---|
| 119 |
|
---|
| 120 |
|
---|
| 121 |
|
---|
[733] | 122 | # create file for buildvars (see $BUILDSCRIPT)
|
---|
| 123 | cat > $BUILDVARS <<EOF
|
---|
| 124 | # Variables for build-Prozess (export is needed in buildscript)
|
---|
| 125 | BUILD_ROOT=$BUILD_ROOT
|
---|
| 126 | BUILD_DIST=$BUILD_DIST
|
---|
| 127 | BUILD_RPMS=${DEST_DIR}/${BUILD_DIST}:$BUILD_RPMS
|
---|
| 128 |
|
---|
| 129 | # Variables for execute the build-proggy
|
---|
| 130 | BUILD_MODE="$BUILD_MODE"
|
---|
| 131 | BUILD_PLACE=${BUILDTEMP}/src/${PACKAGE}
|
---|
| 132 | EXTRA_RPMS="$EXTRA_RPMS"
|
---|
[585] | 133 | EOF
|
---|
[681] | 134 |
|
---|
[734] | 135 | # starting Suse build (as root)
|
---|
[733] | 136 | sudo $BUILDSCRIPT $BUILDVARS
|
---|
| 137 | #rm -f $BUILDVARS
|
---|
[668] | 138 |
|
---|
[733] | 139 |
|
---|
| 140 |
|
---|
[585] | 141 | mkdir -p ${DEST_DIR}/src
|
---|
[620] | 142 | # delete all old versions of this package
|
---|
[695] | 143 | for i in ${DEST_DIR}/src/${PACKAGE}-*.src.rpm; do
|
---|
| 144 | if [ -f $i -a ${PACKAGE} = "`rpm -qp --qf "%{NAME}\n" $i`" ]; then
|
---|
| 145 | rm $i
|
---|
| 146 | fi
|
---|
| 147 | done
|
---|
[682] | 148 |
|
---|
[668] | 149 | if !(cp -a ${BUILD_ROOT}/usr/src/packages/SRPMS/${PACKAGE}-${VERSION}-*.src.rpm ${DEST_DIR}/src 2> /dev/null); then
|
---|
[695] | 150 | ERROR=4
|
---|
[619] | 151 | fi
|
---|
[585] | 152 |
|
---|
[619] | 153 | mkdir -p ${DEST_DIR}/${BUILD_DIST}
|
---|
[620] | 154 | # delete all old versions of this package
|
---|
[695] | 155 | for i in ${DEST_DIR}/${BUILD_DIST}/${PACKAGE}-*.rpm; do
|
---|
| 156 | if [ -f $i -a ${PACKAGE} = "`rpm -qp --qf "%{NAME}\n" $i`" ]; then
|
---|
| 157 | rm $i
|
---|
| 158 | fi
|
---|
| 159 | done
|
---|
[682] | 160 |
|
---|
[692] | 161 | if !(cp -a ${BUILD_ROOT}/usr/src/packages/RPMS/*/${PACKAGE}*${VERSION}-*.*.rpm ${DEST_DIR}/${BUILD_DIST} ); then
|
---|
[695] | 162 | ERROR=8
|
---|
[591] | 163 | fi
|
---|
| 164 |
|
---|
[694] | 165 | echo
|
---|
[619] | 166 | if [ $ERROR -ne 0 ]; then
|
---|
[694] | 167 |
|
---|
| 168 | echo "ERROR while building packet $PACKAGE";
|
---|
[619] | 169 | else
|
---|
[694] | 170 | echo "Build of \"${PACKAGE}\" completed!"
|
---|
[619] | 171 | echo "Packages can be found in ${DEST_DIR}"
|
---|
[591] | 172 | fi
|
---|
[694] | 173 | echo
|
---|
[585] | 174 |
|
---|
[619] | 175 | exit $ERROR
|
---|