[585] | 1 | #!/bin/bash
|
---|
| 2 | # Remote build script (iboernig@suse.de)
|
---|
[675] | 3 | # $Id: build.sh 684 2004-08-14 13:57:44Z joergs $
|
---|
[585] | 4 | #
|
---|
| 5 | # Kurze Featuritis:
|
---|
[621] | 6 | # - build.sh sollte im Pfad liegen.
|
---|
| 7 | # Ein Link von ~/bin/build.sh ist eine gute Wahl ;)
|
---|
| 8 | # - ohne Parameter aufgerufen,
|
---|
| 9 | # erzeugt build.sh mit Hilfe des Makefiles in aktuellen Verzeichnis
|
---|
[679] | 10 | # ein tar-Archiv, bertr�t dieses nach Oldwotan und baut es dort
|
---|
[621] | 11 | # - mit Parameter geht das Skript davon aus,
|
---|
| 12 | # dass der Parameter ein SRPM Paket ist.
|
---|
[682] | 13 | # Dieses wird entpackt und dann gebaut.
|
---|
[585] | 14 | # Wichtige Einstellungen:
|
---|
[679] | 15 | # - Standardm�ig baut build.sh mit --clean, wenns schnell gehen soll, die
|
---|
[585] | 16 | # Umgebungsvariable BUILD_MODE="--no-init" exportieren
|
---|
| 17 | # - BUILD_DIST ist standard sles7-i386, kann auch durch entsprechenden Export
|
---|
[679] | 18 | # berschrieben werden.
|
---|
[682] | 19 | # - die fertigen Pakete werden nach DEST_DIR (kann durch env gesetzt werden) # in die vorgegebene Hierarchie (src, i386/sles/7) auf den lokalen Rechner # kopiert.
|
---|
| 20 | #
|
---|
| 21 | # nutzt sudo
|
---|
[585] | 22 |
|
---|
[668] | 23 | CONFIG_FILE=/usr/local/etc/build
|
---|
[677] | 24 | BUILD_CMD=build
|
---|
[668] | 25 | #SSH_VERSION="1"
|
---|
| 26 | #BUILDHOST="oldwotan"
|
---|
| 27 | #FQBUILDHOST="$BUILDHOST.suse.de"
|
---|
| 28 | #BUILDTEMP=abuildtmp
|
---|
[585] | 29 | BUILDUSER=$USER
|
---|
[668] | 30 | BUILDTEMP=/tmp/abuildtmp/$BUILDUSER
|
---|
[585] | 31 |
|
---|
[668] | 32 | BUILDSCRIPT=$BUILDTEMP/buildscript.$$
|
---|
| 33 |
|
---|
[619] | 34 | [ -z "$BUILD_MODE" ] && BUILD_MODE="--verify"
|
---|
[684] | 35 | [ -z "$BUILD_DIST" ] && BUILD_DIST="9.1-i386"
|
---|
[668] | 36 | [ -z "$BUILD_ROOT" ] && BUILD_ROOT="/var/tmp/buildsystem.$USER.$BUILD_DIST"
|
---|
[586] | 37 | [ -z "$BUILD_PREPARE_SPEC" ] && BUILD_PREPARE_SPEC="no"
|
---|
[585] | 38 |
|
---|
[668] | 39 | [ -z $DEST_DIR ] && DEST_DIR="/tmp/build.$BUILDUSER"
|
---|
[585] | 40 |
|
---|
[682] | 41 | [ -z "$BUILD_USES_SVN" ] && BUILD_USES_SVN="yes"
|
---|
| 42 |
|
---|
| 43 |
|
---|
| 44 |
|
---|
[668] | 45 | if [ -r $CONFIG_FILE ]; then
|
---|
| 46 | source $CONFIG_FILE
|
---|
| 47 | MOD_BUILD_DIST=`echo $BUILD_DIST | sed "s/[-+.]/_/g"`
|
---|
| 48 | #echo MOD_BUILD_DIST: $MOD_BUILD_DIST
|
---|
| 49 | #RPMS_PATHS=$[BUILD_RPMS_$MOD_BUILD_DIST]
|
---|
| 50 | #echo RPMS_PATHS: $RPM_PATHS
|
---|
| 51 | #if [ -n "$[BUILD_RPMS_$MOD_BUILD_DIST]" ]; then
|
---|
| 52 | # BUILD_RPMS=$[BUILD_RPMS_$MOD_BUILD_DIST]
|
---|
| 53 | #fi
|
---|
| 54 | #echo OUTPUT: $[BUILD_RPMS_$MOD_BUILD_DIST]
|
---|
| 55 | #:$BUILD_RPMS
|
---|
| 56 | case "$BUILD_DIST" in
|
---|
| 57 | "9.0-i386")
|
---|
| 58 | BUILD_RPMS_TEST=$BUILD_RPMS_9_0_i386 ;;
|
---|
| 59 | "sles8-i386")
|
---|
| 60 | BUILD_RPMS_TEST=$BUILD_RPMS_sles8_i386 ;;
|
---|
| 61 | "sles8-i386+update")
|
---|
| 62 | BUILD_RPMS_TEST=$BUILD_RPMS_sles8_i386_update ;;
|
---|
[679] | 63 | "9.1-i386")
|
---|
| 64 | BUILD_RPMS_TEST=$BUILD_RPMS_9_1_i386 ;;
|
---|
[681] | 65 | "sles9-i386")
|
---|
| 66 | BUILD_RPMS_TEST=$BUILD_RPMS_sles9_i386 ;;
|
---|
[668] | 67 | esac
|
---|
| 68 | if [ "$BUILD_RPMS_TEST" ]; then
|
---|
| 69 | if [ "$BUILD_RPMS" ]; then
|
---|
| 70 | BUILD_RPMS=$BUILD_RPMS:$BUILD_RPMS_TEST
|
---|
| 71 | else
|
---|
| 72 | BUILD_RPMS=$BUILD_RPMS_TEST
|
---|
| 73 | fi
|
---|
| 74 | fi
|
---|
| 75 | fi
|
---|
| 76 |
|
---|
| 77 | echo BUILD_RPMS: $BUILD_RPMS
|
---|
| 78 |
|
---|
[619] | 79 | ERROR=0
|
---|
[585] | 80 |
|
---|
[621] | 81 | # Hier gehts los:
|
---|
[620] | 82 |
|
---|
| 83 | if [ -z "$1" ]; then
|
---|
| 84 | # without parameter, we are in source directory
|
---|
| 85 | SPECFILE=$(ls *.spec | awk '{print $1}')
|
---|
| 86 | PACKAGE=$(awk '/^Name:/ {print $2}' <$SPECFILE)
|
---|
| 87 | VERSION=$(awk '/^Version:/ {print $2}' <$SPECFILE)
|
---|
| 88 | else
|
---|
| 89 | # parameter is src.rpm file
|
---|
| 90 | PACKAGE=`echo $1 | sed 's/-[0-9]*\..*.src.rpm//'`
|
---|
| 91 | VERSION=`echo $1 | sed 's/.*-\([0-9]*\..*\)-.*.src.rpm/\1/'`
|
---|
| 92 | fi
|
---|
| 93 |
|
---|
[622] | 94 | echo $PACKAGE $VERSION $BUILD_DIST $BUILD_MODE
|
---|
[585] | 95 |
|
---|
[682] | 96 | rm -rf ${BUILDTEMP}/src/${PACKAGE};
|
---|
| 97 | mkdir -p ${BUILDTEMP}/src/${PACKAGE} ${BUILDTEMP}/${BUILD_DIST};
|
---|
[585] | 98 |
|
---|
[620] | 99 | if [ "$1" ]; then
|
---|
[682] | 100 | cp -a "$1" ${BUILDTEMP}/src/${PACKAGE}
|
---|
| 101 | cd ${BUILDTEMP}/src/${PACKAGE}; rpm2cpio $1 | cpio -i
|
---|
| 102 | else
|
---|
| 103 | cp -a $SPECFILE ${BUILDTEMP}/src/${PACKAGE}
|
---|
| 104 |
|
---|
| 105 | # uses Subversion (svn) to generate more information for the RPM
|
---|
| 106 | if [ "$BUILD_USES_SVN" = "yes" ]; then
|
---|
| 107 | echo "receiving subversion information ..."
|
---|
| 108 | # set RELEASE number (last modification in this directory)
|
---|
| 109 | # requires subversion (but connection to server isn't neccessary)
|
---|
| 110 | SVN_BUILD_RELEASE=$(svn info . | sed -n 's/^Last Changed Rev: \([0-9]*\)/\1/p')
|
---|
| 111 | if [ "$SVN_BUILD_RELEASE" ]; then
|
---|
| 112 | sed "s/^Release:.*/Release: $SVN_BUILD_RELEASE/g" $SPECFILE > ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
|
---|
| 113 | fi
|
---|
[683] | 114 | # changelog header
|
---|
| 115 | DATE=`unset LANG; date +"%a %b %d %Y"`
|
---|
| 116 | echo -e "* $DATE -\n" > Changes
|
---|
| 117 | echo "- Subversion status:" >> Changes
|
---|
[682] | 118 | # additional infos for the Changes file (see if everything is checked in)
|
---|
| 119 | svn status -v | grep -v '^? ' >> Changes
|
---|
| 120 | echo >> Changes
|
---|
[683] | 121 | echo "- ChangeLog:" >> Changes
|
---|
[682] | 122 | # requires connection to the subversion server
|
---|
| 123 | svn log -v . > ChangeLog.new && mv ChangeLog.new ChangeLog
|
---|
| 124 | cat ChangeLog >> Changes
|
---|
[684] | 125 |
|
---|
| 126 | # if there is no changelog section in the spec file,
|
---|
| 127 | # also append the Changes there
|
---|
| 128 | if ! grep -q "%changelog" $SPECFILE ; then
|
---|
| 129 | # paste "Changes" into SPEC file.
|
---|
| 130 | echo "%changelog" >> ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
|
---|
| 131 | # without trailing *, except for the initial
|
---|
| 132 | echo -n "*" >> ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
|
---|
| 133 | cat Changes | sed 's/\(^[\*]\+\)//g' >> ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
|
---|
| 134 | fi
|
---|
[682] | 135 | fi
|
---|
| 136 | # just make sure, that the Changes file exist
|
---|
| 137 | touch Changes
|
---|
| 138 |
|
---|
| 139 | # if "SOURCES" file exist, create tar file on the fly
|
---|
| 140 | if [ -r "SOURCES" ]; then
|
---|
| 141 | # create a tar file from the sources
|
---|
| 142 | tar cvjf ${BUILDTEMP}/src/${PACKAGE}/$PACKAGE-$VERSION.tar.bz2 --files-from SOURCES
|
---|
| 143 | else
|
---|
| 144 | # legacy method:
|
---|
| 145 | # call the existing makefile to generate a tar file
|
---|
| 146 | test -e Makefile && make
|
---|
| 147 | TARFILE=$(ls *.tar.[gb]z*| awk '{print $1}')
|
---|
| 148 | cp -a $TARFILE ${BUILDTEMP}/src/${PACKAGE}
|
---|
| 149 | fi
|
---|
[620] | 150 | fi
|
---|
| 151 |
|
---|
[585] | 152 | # create buildscript
|
---|
[668] | 153 | cat > $BUILDSCRIPT <<EOF
|
---|
[585] | 154 | #!/bin/bash
|
---|
| 155 | # local buildscript
|
---|
[668] | 156 | #. /work/src/bin/.profile
|
---|
[585] | 157 | export BUILD_ROOT=$BUILD_ROOT
|
---|
| 158 | export BUILD_DIST=$BUILD_DIST
|
---|
[668] | 159 | export BUILD_RPMS=${BUILDTEMP}/${BUILD_DIST}:$BUILD_RPMS
|
---|
[586] | 160 | export BUILD_PREPARE_SPEC=$BUILD_PREPARE_SPEC
|
---|
| 161 |
|
---|
[668] | 162 | cd ${BUILDTEMP}/src/${PACKAGE}
|
---|
| 163 | #build $BUILD_MODE --prefer-rpms ${BUILDTEMP}/${BUILD_DIST}
|
---|
[677] | 164 | #build $BUILD_MODE
|
---|
| 165 | $BUILD_CMD $BUILD_MODE
|
---|
[585] | 166 | EOF
|
---|
[681] | 167 |
|
---|
[668] | 168 | chmod a+x $BUILDSCRIPT
|
---|
| 169 | sudo su -c $BUILDSCRIPT
|
---|
| 170 | rm -f $BUILDSCRIPT
|
---|
| 171 |
|
---|
[682] | 172 | rm -f ${BUILDTEMP}/${BUILD_DIST}/${PACKAGE}-*.*.rpm
|
---|
| 173 | cp -a ${BUILD_ROOT}/usr/src/packages/RPMS/*/${PACKAGE}-${VERSION}-*.*.rpm ${BUILDTEMP}/${BUILD_DIST}
|
---|
[668] | 174 |
|
---|
[585] | 175 | mkdir -p ${DEST_DIR}/src
|
---|
[620] | 176 | # delete all old versions of this package
|
---|
| 177 | rm -f ${DEST_DIR}/src/${PACKAGE}-*.src.rpm
|
---|
[682] | 178 |
|
---|
[668] | 179 | if !(cp -a ${BUILD_ROOT}/usr/src/packages/SRPMS/${PACKAGE}-${VERSION}-*.src.rpm ${DEST_DIR}/src 2> /dev/null); then
|
---|
[619] | 180 | ERROR=1
|
---|
| 181 | fi
|
---|
[585] | 182 |
|
---|
[619] | 183 | mkdir -p ${DEST_DIR}/${BUILD_DIST}
|
---|
[620] | 184 | # delete all old versions of this package
|
---|
| 185 | rm -f ${DEST_DIR}/${BUILD_DIST}/${PACKAGE}-*.rpm
|
---|
[682] | 186 |
|
---|
[668] | 187 | if !(cp -a ${BUILD_ROOT}/usr/src/packages/RPMS/*/${PACKAGE}-${VERSION}-*.*.rpm ${DEST_DIR}/${BUILD_DIST} ); then
|
---|
[619] | 188 | ERROR=2
|
---|
[591] | 189 | fi
|
---|
| 190 |
|
---|
[619] | 191 | if [ $ERROR -ne 0 ]; then
|
---|
[591] | 192 | echo "ERROR while building packet $PACKAGE";
|
---|
[619] | 193 | for i in `seq 5`; do
|
---|
[625] | 194 | echo -n "";
|
---|
[619] | 195 | done
|
---|
| 196 | else
|
---|
| 197 | echo "Build of ${PACKAGE} completed!"
|
---|
| 198 | echo "Packages can be found in ${DEST_DIR}"
|
---|
[591] | 199 | fi
|
---|
[585] | 200 |
|
---|
[619] | 201 | exit $ERROR
|
---|