[668] | 1 |
|
---|
[585] | 2 | #!/bin/bash
|
---|
| 3 | # Remote build script (iboernig@suse.de)
|
---|
[675] | 4 | # $Id: build.sh 677 2004-07-14 12:02:30Z joergs $
|
---|
[585] | 5 | #
|
---|
| 6 | # Kurze Featuritis:
|
---|
[621] | 7 | # - build.sh sollte im Pfad liegen.
|
---|
| 8 | # Ein Link von ~/bin/build.sh ist eine gute Wahl ;)
|
---|
| 9 | # - ohne Parameter aufgerufen,
|
---|
| 10 | # erzeugt build.sh mit Hilfe des Makefiles in aktuellen Verzeichnis
|
---|
[585] | 11 | # ein tar-Archiv, überträgt dieses nach Oldwotan und baut es dort
|
---|
[621] | 12 | # - mit Parameter geht das Skript davon aus,
|
---|
| 13 | # dass der Parameter ein SRPM Paket ist.
|
---|
| 14 | # Dieses wird nach oldwotan kopiert, dort entpackt und dann gebaut.
|
---|
[585] | 15 | # - Dazu muss ein ssh-pubkey in oldwotans /root/.ssh/authorized_keys gelegt
|
---|
| 16 | # werden (build.sh verwendet ssh)
|
---|
| 17 | # Wichtige Einstellungen:
|
---|
| 18 | # - Standardmäßig baut build.sh mit --clean, wenns schnell gehen soll, die
|
---|
| 19 | # Umgebungsvariable BUILD_MODE="--no-init" exportieren
|
---|
| 20 | # - BUILD_DIST ist standard sles7-i386, kann auch durch entsprechenden Export
|
---|
| 21 | # überschrieben werden.
|
---|
| 22 | # - die fertigen Pakete werden nach DEST_DIR (kann durch env gesetzt werden)
|
---|
| 23 | # in die vorgegebene Hierarchie (src, i386/sles/7) auf den lokalen Rechner
|
---|
| 24 | # kopiert. Vorgabe ist /tmp/smartclient_build
|
---|
| 25 |
|
---|
[668] | 26 | CONFIG_FILE=/usr/local/etc/build
|
---|
[677] | 27 | BUILD_CMD=build
|
---|
[668] | 28 | #SSH_VERSION="1"
|
---|
| 29 | #BUILDHOST="oldwotan"
|
---|
| 30 | #FQBUILDHOST="$BUILDHOST.suse.de"
|
---|
| 31 | #BUILDTEMP=abuildtmp
|
---|
[585] | 32 | BUILDUSER=$USER
|
---|
[668] | 33 | BUILDTEMP=/tmp/abuildtmp/$BUILDUSER
|
---|
[585] | 34 |
|
---|
[668] | 35 | BUILDSCRIPT=$BUILDTEMP/buildscript.$$
|
---|
| 36 |
|
---|
[619] | 37 | [ -z "$BUILD_MODE" ] && BUILD_MODE="--verify"
|
---|
[668] | 38 | [ -z "$BUILD_DIST" ] && BUILD_DIST="sles8-i386+update"
|
---|
| 39 | [ -z "$BUILD_ROOT" ] && BUILD_ROOT="/var/tmp/buildsystem.$USER.$BUILD_DIST"
|
---|
[586] | 40 | [ -z "$BUILD_PREPARE_SPEC" ] && BUILD_PREPARE_SPEC="no"
|
---|
[585] | 41 |
|
---|
[668] | 42 | [ -z $DEST_DIR ] && DEST_DIR="/tmp/build.$BUILDUSER"
|
---|
[585] | 43 |
|
---|
[668] | 44 | if [ -r $CONFIG_FILE ]; then
|
---|
| 45 | source $CONFIG_FILE
|
---|
| 46 | MOD_BUILD_DIST=`echo $BUILD_DIST | sed "s/[-+.]/_/g"`
|
---|
| 47 | #echo MOD_BUILD_DIST: $MOD_BUILD_DIST
|
---|
| 48 | #RPMS_PATHS=$[BUILD_RPMS_$MOD_BUILD_DIST]
|
---|
| 49 | #echo RPMS_PATHS: $RPM_PATHS
|
---|
| 50 | #if [ -n "$[BUILD_RPMS_$MOD_BUILD_DIST]" ]; then
|
---|
| 51 | # BUILD_RPMS=$[BUILD_RPMS_$MOD_BUILD_DIST]
|
---|
| 52 | #fi
|
---|
| 53 | #echo OUTPUT: $[BUILD_RPMS_$MOD_BUILD_DIST]
|
---|
| 54 | #:$BUILD_RPMS
|
---|
| 55 | case "$BUILD_DIST" in
|
---|
| 56 | "9.0-i386")
|
---|
| 57 | BUILD_RPMS_TEST=$BUILD_RPMS_9_0_i386 ;;
|
---|
| 58 | "sles8-i386")
|
---|
| 59 | BUILD_RPMS_TEST=$BUILD_RPMS_sles8_i386 ;;
|
---|
| 60 | "sles8-i386+update")
|
---|
| 61 | BUILD_RPMS_TEST=$BUILD_RPMS_sles8_i386_update ;;
|
---|
| 62 | esac
|
---|
| 63 | if [ "$BUILD_RPMS_TEST" ]; then
|
---|
| 64 | if [ "$BUILD_RPMS" ]; then
|
---|
| 65 | BUILD_RPMS=$BUILD_RPMS:$BUILD_RPMS_TEST
|
---|
| 66 | else
|
---|
| 67 | BUILD_RPMS=$BUILD_RPMS_TEST
|
---|
| 68 | fi
|
---|
| 69 | fi
|
---|
| 70 | fi
|
---|
| 71 |
|
---|
| 72 | echo BUILD_RPMS: $BUILD_RPMS
|
---|
| 73 |
|
---|
[619] | 74 | ERROR=0
|
---|
[585] | 75 |
|
---|
[621] | 76 | # Hier gehts los:
|
---|
[620] | 77 |
|
---|
| 78 | if [ -z "$1" ]; then
|
---|
| 79 | # without parameter, we are in source directory
|
---|
| 80 | test -e Makefile && make
|
---|
| 81 | SPECFILE=$(ls *.spec | awk '{print $1}')
|
---|
| 82 | TARFILE=$(ls *.tar.[gb]z*| awk '{print $1}')
|
---|
| 83 | PACKAGE=$(awk '/^Name:/ {print $2}' <$SPECFILE)
|
---|
| 84 | VERSION=$(awk '/^Version:/ {print $2}' <$SPECFILE)
|
---|
| 85 | SRC_FILES="$SPECFILE $TARFILE"
|
---|
| 86 | else
|
---|
| 87 | # parameter is src.rpm file
|
---|
| 88 | PACKAGE=`echo $1 | sed 's/-[0-9]*\..*.src.rpm//'`
|
---|
| 89 | VERSION=`echo $1 | sed 's/.*-\([0-9]*\..*\)-.*.src.rpm/\1/'`
|
---|
| 90 | SRC_FILES="$1"
|
---|
| 91 | fi
|
---|
| 92 |
|
---|
[622] | 93 | echo $PACKAGE $VERSION $BUILD_DIST $BUILD_MODE
|
---|
[585] | 94 |
|
---|
| 95 | # Cleaning up and install tempdir
|
---|
[668] | 96 | #ssh -${SSH_VERSION} ${FQBUILDHOST} "\
|
---|
| 97 | rm -rf ${BUILDTEMP}/src/${PACKAGE}; \
|
---|
| 98 | mkdir -p ${BUILDTEMP}/src/${PACKAGE} ${BUILDTEMP}/${BUILD_DIST};
|
---|
[585] | 99 |
|
---|
[668] | 100 | #scp -oProtocol=$SSH_VERSION $SRC_FILES ${FQBUILDHOST}:${BUILDTEMP}/src/${PACKAGE}
|
---|
| 101 | cp -a $SRC_FILES ${BUILDTEMP}/src/${PACKAGE}
|
---|
[585] | 102 |
|
---|
[620] | 103 | if [ "$1" ]; then
|
---|
[668] | 104 | # extract RPM in a tempoary directory
|
---|
| 105 | #ssh -${SSH_VERSION} ${FQBUILDHOST} "\
|
---|
| 106 | cd ${BUILDTEMP}/src/${PACKAGE}; rpm2cpio $1 | cpio -i
|
---|
[620] | 107 | fi
|
---|
| 108 |
|
---|
[585] | 109 | # create buildscript
|
---|
| 110 |
|
---|
[668] | 111 | cat > $BUILDSCRIPT <<EOF
|
---|
[585] | 112 | #!/bin/bash
|
---|
| 113 | # local buildscript
|
---|
[668] | 114 | #. /work/src/bin/.profile
|
---|
[585] | 115 | export BUILD_ROOT=$BUILD_ROOT
|
---|
| 116 | export BUILD_DIST=$BUILD_DIST
|
---|
[668] | 117 | export BUILD_RPMS=${BUILDTEMP}/${BUILD_DIST}:$BUILD_RPMS
|
---|
[586] | 118 | export BUILD_PREPARE_SPEC=$BUILD_PREPARE_SPEC
|
---|
| 119 |
|
---|
[668] | 120 | cd ${BUILDTEMP}/src/${PACKAGE}
|
---|
| 121 | #build $BUILD_MODE --prefer-rpms ${BUILDTEMP}/${BUILD_DIST}
|
---|
[677] | 122 | #build $BUILD_MODE
|
---|
| 123 | $BUILD_CMD $BUILD_MODE
|
---|
[585] | 124 | EOF
|
---|
[668] | 125 | chmod a+x $BUILDSCRIPT
|
---|
[585] | 126 |
|
---|
[621] | 127 | #cat /tmp/tmpscript.$$
|
---|
[585] | 128 |
|
---|
[668] | 129 | #scp -oProtocol=$SSH_VERSION /tmp/tmpscript.$$ ${FQBUILDHOST}:${BUILDTEMP}/src/${PACKAGE}/buildscript
|
---|
| 130 | #rm /tmp/tmpscript.$$
|
---|
[585] | 131 |
|
---|
| 132 | # build and file rpms
|
---|
[668] | 133 | #ssh -oProtocol=$SSH_VERSION root@${FQBUILDHOST} \
|
---|
| 134 | # . ~$BUILDUSER/${BUILDTEMP}/src/${PACKAGE}/buildscript
|
---|
[585] | 135 |
|
---|
[668] | 136 | sudo su -c $BUILDSCRIPT
|
---|
| 137 | rm -f $BUILDSCRIPT
|
---|
| 138 |
|
---|
| 139 | #ssh -oProtocol=$SSH_VERSION ${FQBUILDHOST} \
|
---|
| 140 | rm -f ${BUILDTEMP}/${BUILD_DIST}/${PACKAGE}-*.*.rpm
|
---|
| 141 | cp -a ${BUILD_ROOT}/usr/src/packages/RPMS/*/${PACKAGE}-${VERSION}-*.*.rpm ${BUILDTEMP}/${BUILD_DIST}
|
---|
| 142 |
|
---|
[585] | 143 | mkdir -p ${DEST_DIR}/src
|
---|
[620] | 144 | # delete all old versions of this package
|
---|
| 145 | rm -f ${DEST_DIR}/src/${PACKAGE}-*.src.rpm
|
---|
[668] | 146 | #if !(scp -oProtocol=$SSH_VERSION root@${FQBUILDHOST}:${BUILD_ROOT}/usr/src/packages/SRPMS/${PACKAGE}-${VERSION}-*.src.rpm ${DEST_DIR}/src ); then
|
---|
| 147 | #ERROR=1
|
---|
| 148 | #fi
|
---|
| 149 | if !(cp -a ${BUILD_ROOT}/usr/src/packages/SRPMS/${PACKAGE}-${VERSION}-*.src.rpm ${DEST_DIR}/src 2> /dev/null); then
|
---|
[619] | 150 | ERROR=1
|
---|
| 151 | fi
|
---|
[585] | 152 |
|
---|
[619] | 153 | mkdir -p ${DEST_DIR}/${BUILD_DIST}
|
---|
[620] | 154 | # delete all old versions of this package
|
---|
| 155 | rm -f ${DEST_DIR}/${BUILD_DIST}/${PACKAGE}-*.rpm
|
---|
[668] | 156 | #if !(scp -oProtocol=$SSH_VERSION #root@${FQBUILDHOST}:${BUILD_ROOT}/usr/src/packages/RPMS/*/${PACKAGE}-${VERSION}-*.*.rpm ${DEST_DIR}/${BUILD_DIST} ); then
|
---|
| 157 | # ERROR=2
|
---|
| 158 | #fi
|
---|
| 159 | if !(cp -a ${BUILD_ROOT}/usr/src/packages/RPMS/*/${PACKAGE}-${VERSION}-*.*.rpm ${DEST_DIR}/${BUILD_DIST} ); then
|
---|
[619] | 160 | ERROR=2
|
---|
[591] | 161 | fi
|
---|
| 162 |
|
---|
[619] | 163 | if [ $ERROR -ne 0 ]; then
|
---|
[591] | 164 | echo "ERROR while building packet $PACKAGE";
|
---|
[619] | 165 | for i in `seq 5`; do
|
---|
[625] | 166 | echo -n "";
|
---|
[619] | 167 | done
|
---|
| 168 | else
|
---|
| 169 | echo "Build of ${PACKAGE} completed!"
|
---|
| 170 | echo "Packages can be found in ${DEST_DIR}"
|
---|
[591] | 171 | fi
|
---|
[585] | 172 |
|
---|
[619] | 173 | exit $ERROR
|
---|