[668] | 1 |
|
---|
[585] | 2 | #!/bin/bash
|
---|
| 3 | # Remote build script (iboernig@suse.de)
|
---|
[675] | 4 | # $Id: build.sh 675 2004-05-15 08:26:56Z 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
|
---|
| 27 | #SSH_VERSION="1"
|
---|
| 28 | #BUILDHOST="oldwotan"
|
---|
| 29 | #FQBUILDHOST="$BUILDHOST.suse.de"
|
---|
| 30 | #BUILDTEMP=abuildtmp
|
---|
[585] | 31 | BUILDUSER=$USER
|
---|
[668] | 32 | BUILDTEMP=/tmp/abuildtmp/$BUILDUSER
|
---|
[585] | 33 |
|
---|
[668] | 34 | BUILDSCRIPT=$BUILDTEMP/buildscript.$$
|
---|
| 35 |
|
---|
[619] | 36 | [ -z "$BUILD_MODE" ] && BUILD_MODE="--verify"
|
---|
[668] | 37 | [ -z "$BUILD_DIST" ] && BUILD_DIST="sles8-i386+update"
|
---|
| 38 | [ -z "$BUILD_ROOT" ] && BUILD_ROOT="/var/tmp/buildsystem.$USER.$BUILD_DIST"
|
---|
[586] | 39 | [ -z "$BUILD_PREPARE_SPEC" ] && BUILD_PREPARE_SPEC="no"
|
---|
[585] | 40 |
|
---|
[668] | 41 | [ -z $DEST_DIR ] && DEST_DIR="/tmp/build.$BUILDUSER"
|
---|
[585] | 42 |
|
---|
[668] | 43 | if [ -r $CONFIG_FILE ]; then
|
---|
| 44 | source $CONFIG_FILE
|
---|
| 45 | MOD_BUILD_DIST=`echo $BUILD_DIST | sed "s/[-+.]/_/g"`
|
---|
| 46 | #echo MOD_BUILD_DIST: $MOD_BUILD_DIST
|
---|
| 47 | #RPMS_PATHS=$[BUILD_RPMS_$MOD_BUILD_DIST]
|
---|
| 48 | #echo RPMS_PATHS: $RPM_PATHS
|
---|
| 49 | #if [ -n "$[BUILD_RPMS_$MOD_BUILD_DIST]" ]; then
|
---|
| 50 | # BUILD_RPMS=$[BUILD_RPMS_$MOD_BUILD_DIST]
|
---|
| 51 | #fi
|
---|
| 52 | #echo OUTPUT: $[BUILD_RPMS_$MOD_BUILD_DIST]
|
---|
| 53 | #:$BUILD_RPMS
|
---|
| 54 | case "$BUILD_DIST" in
|
---|
| 55 | "9.0-i386")
|
---|
| 56 | BUILD_RPMS_TEST=$BUILD_RPMS_9_0_i386 ;;
|
---|
| 57 | "sles8-i386")
|
---|
| 58 | BUILD_RPMS_TEST=$BUILD_RPMS_sles8_i386 ;;
|
---|
| 59 | "sles8-i386+update")
|
---|
| 60 | BUILD_RPMS_TEST=$BUILD_RPMS_sles8_i386_update ;;
|
---|
| 61 | esac
|
---|
| 62 | if [ "$BUILD_RPMS_TEST" ]; then
|
---|
| 63 | if [ "$BUILD_RPMS" ]; then
|
---|
| 64 | BUILD_RPMS=$BUILD_RPMS:$BUILD_RPMS_TEST
|
---|
| 65 | else
|
---|
| 66 | BUILD_RPMS=$BUILD_RPMS_TEST
|
---|
| 67 | fi
|
---|
| 68 | fi
|
---|
| 69 | fi
|
---|
| 70 |
|
---|
| 71 | echo BUILD_RPMS: $BUILD_RPMS
|
---|
| 72 |
|
---|
[619] | 73 | ERROR=0
|
---|
[585] | 74 |
|
---|
[621] | 75 | # Hier gehts los:
|
---|
[620] | 76 |
|
---|
| 77 | if [ -z "$1" ]; then
|
---|
| 78 | # without parameter, we are in source directory
|
---|
| 79 | test -e Makefile && make
|
---|
| 80 | SPECFILE=$(ls *.spec | awk '{print $1}')
|
---|
| 81 | TARFILE=$(ls *.tar.[gb]z*| awk '{print $1}')
|
---|
| 82 | PACKAGE=$(awk '/^Name:/ {print $2}' <$SPECFILE)
|
---|
| 83 | VERSION=$(awk '/^Version:/ {print $2}' <$SPECFILE)
|
---|
| 84 | SRC_FILES="$SPECFILE $TARFILE"
|
---|
| 85 | else
|
---|
| 86 | # parameter is src.rpm file
|
---|
| 87 | PACKAGE=`echo $1 | sed 's/-[0-9]*\..*.src.rpm//'`
|
---|
| 88 | VERSION=`echo $1 | sed 's/.*-\([0-9]*\..*\)-.*.src.rpm/\1/'`
|
---|
| 89 | SRC_FILES="$1"
|
---|
| 90 | fi
|
---|
| 91 |
|
---|
[622] | 92 | echo $PACKAGE $VERSION $BUILD_DIST $BUILD_MODE
|
---|
[585] | 93 |
|
---|
| 94 | # Cleaning up and install tempdir
|
---|
[668] | 95 | #ssh -${SSH_VERSION} ${FQBUILDHOST} "\
|
---|
| 96 | rm -rf ${BUILDTEMP}/src/${PACKAGE}; \
|
---|
| 97 | mkdir -p ${BUILDTEMP}/src/${PACKAGE} ${BUILDTEMP}/${BUILD_DIST};
|
---|
[585] | 98 |
|
---|
[668] | 99 | #scp -oProtocol=$SSH_VERSION $SRC_FILES ${FQBUILDHOST}:${BUILDTEMP}/src/${PACKAGE}
|
---|
| 100 | cp -a $SRC_FILES ${BUILDTEMP}/src/${PACKAGE}
|
---|
[585] | 101 |
|
---|
[620] | 102 | if [ "$1" ]; then
|
---|
[668] | 103 | # extract RPM in a tempoary directory
|
---|
| 104 | #ssh -${SSH_VERSION} ${FQBUILDHOST} "\
|
---|
| 105 | cd ${BUILDTEMP}/src/${PACKAGE}; rpm2cpio $1 | cpio -i
|
---|
[620] | 106 | fi
|
---|
| 107 |
|
---|
[585] | 108 | # create buildscript
|
---|
| 109 |
|
---|
[668] | 110 | cat > $BUILDSCRIPT <<EOF
|
---|
[585] | 111 | #!/bin/bash
|
---|
| 112 | # local buildscript
|
---|
[668] | 113 | #. /work/src/bin/.profile
|
---|
[585] | 114 | export BUILD_ROOT=$BUILD_ROOT
|
---|
| 115 | export BUILD_DIST=$BUILD_DIST
|
---|
[668] | 116 | export BUILD_RPMS=${BUILDTEMP}/${BUILD_DIST}:$BUILD_RPMS
|
---|
[586] | 117 | export BUILD_PREPARE_SPEC=$BUILD_PREPARE_SPEC
|
---|
| 118 |
|
---|
[668] | 119 | cd ${BUILDTEMP}/src/${PACKAGE}
|
---|
| 120 | #build $BUILD_MODE --prefer-rpms ${BUILDTEMP}/${BUILD_DIST}
|
---|
| 121 | build $BUILD_MODE
|
---|
[585] | 122 | EOF
|
---|
[668] | 123 | chmod a+x $BUILDSCRIPT
|
---|
[585] | 124 |
|
---|
[621] | 125 | #cat /tmp/tmpscript.$$
|
---|
[585] | 126 |
|
---|
[668] | 127 | #scp -oProtocol=$SSH_VERSION /tmp/tmpscript.$$ ${FQBUILDHOST}:${BUILDTEMP}/src/${PACKAGE}/buildscript
|
---|
| 128 | #rm /tmp/tmpscript.$$
|
---|
[585] | 129 |
|
---|
| 130 | # build and file rpms
|
---|
[668] | 131 | #ssh -oProtocol=$SSH_VERSION root@${FQBUILDHOST} \
|
---|
| 132 | # . ~$BUILDUSER/${BUILDTEMP}/src/${PACKAGE}/buildscript
|
---|
[585] | 133 |
|
---|
[668] | 134 | sudo su -c $BUILDSCRIPT
|
---|
| 135 | rm -f $BUILDSCRIPT
|
---|
| 136 |
|
---|
| 137 | #ssh -oProtocol=$SSH_VERSION ${FQBUILDHOST} \
|
---|
| 138 | rm -f ${BUILDTEMP}/${BUILD_DIST}/${PACKAGE}-*.*.rpm
|
---|
| 139 | cp -a ${BUILD_ROOT}/usr/src/packages/RPMS/*/${PACKAGE}-${VERSION}-*.*.rpm ${BUILDTEMP}/${BUILD_DIST}
|
---|
| 140 |
|
---|
[585] | 141 | mkdir -p ${DEST_DIR}/src
|
---|
[620] | 142 | # delete all old versions of this package
|
---|
| 143 | rm -f ${DEST_DIR}/src/${PACKAGE}-*.src.rpm
|
---|
[668] | 144 | #if !(scp -oProtocol=$SSH_VERSION root@${FQBUILDHOST}:${BUILD_ROOT}/usr/src/packages/SRPMS/${PACKAGE}-${VERSION}-*.src.rpm ${DEST_DIR}/src ); then
|
---|
| 145 | #ERROR=1
|
---|
| 146 | #fi
|
---|
| 147 | if !(cp -a ${BUILD_ROOT}/usr/src/packages/SRPMS/${PACKAGE}-${VERSION}-*.src.rpm ${DEST_DIR}/src 2> /dev/null); then
|
---|
[619] | 148 | ERROR=1
|
---|
| 149 | fi
|
---|
[585] | 150 |
|
---|
[619] | 151 | mkdir -p ${DEST_DIR}/${BUILD_DIST}
|
---|
[620] | 152 | # delete all old versions of this package
|
---|
| 153 | rm -f ${DEST_DIR}/${BUILD_DIST}/${PACKAGE}-*.rpm
|
---|
[668] | 154 | #if !(scp -oProtocol=$SSH_VERSION #root@${FQBUILDHOST}:${BUILD_ROOT}/usr/src/packages/RPMS/*/${PACKAGE}-${VERSION}-*.*.rpm ${DEST_DIR}/${BUILD_DIST} ); then
|
---|
| 155 | # ERROR=2
|
---|
| 156 | #fi
|
---|
| 157 | if !(cp -a ${BUILD_ROOT}/usr/src/packages/RPMS/*/${PACKAGE}-${VERSION}-*.*.rpm ${DEST_DIR}/${BUILD_DIST} ); then
|
---|
[619] | 158 | ERROR=2
|
---|
[591] | 159 | fi
|
---|
| 160 |
|
---|
[619] | 161 | if [ $ERROR -ne 0 ]; then
|
---|
[591] | 162 | echo "ERROR while building packet $PACKAGE";
|
---|
[619] | 163 | for i in `seq 5`; do
|
---|
[625] | 164 | echo -n "";
|
---|
[619] | 165 | done
|
---|
| 166 | else
|
---|
| 167 | echo "Build of ${PACKAGE} completed!"
|
---|
| 168 | echo "Packages can be found in ${DEST_DIR}"
|
---|
[591] | 169 | fi
|
---|
[585] | 170 |
|
---|
[619] | 171 | exit $ERROR
|
---|