1 |
|
---|
2 | #!/bin/bash
|
---|
3 | # Remote build script (iboernig@suse.de)
|
---|
4 | # $Id: build.sh 679 2004-08-10 14:05:36Z joergs $
|
---|
5 | #
|
---|
6 | # Kurze Featuritis:
|
---|
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
|
---|
11 | # ein tar-Archiv, bertr�t dieses nach Oldwotan und baut es dort
|
---|
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.
|
---|
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 |
|
---|
26 | CONFIG_FILE=/usr/local/etc/build
|
---|
27 | BUILD_CMD=build
|
---|
28 | #SSH_VERSION="1"
|
---|
29 | #BUILDHOST="oldwotan"
|
---|
30 | #FQBUILDHOST="$BUILDHOST.suse.de"
|
---|
31 | #BUILDTEMP=abuildtmp
|
---|
32 | BUILDUSER=$USER
|
---|
33 | BUILDTEMP=/tmp/abuildtmp/$BUILDUSER
|
---|
34 |
|
---|
35 | BUILDSCRIPT=$BUILDTEMP/buildscript.$$
|
---|
36 |
|
---|
37 | [ -z "$BUILD_MODE" ] && BUILD_MODE="--verify"
|
---|
38 | [ -z "$BUILD_DIST" ] && BUILD_DIST="sles8-i386+update"
|
---|
39 | [ -z "$BUILD_ROOT" ] && BUILD_ROOT="/var/tmp/buildsystem.$USER.$BUILD_DIST"
|
---|
40 | [ -z "$BUILD_PREPARE_SPEC" ] && BUILD_PREPARE_SPEC="no"
|
---|
41 |
|
---|
42 | [ -z $DEST_DIR ] && DEST_DIR="/tmp/build.$BUILDUSER"
|
---|
43 |
|
---|
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 | "9.1-i386")
|
---|
63 | BUILD_RPMS_TEST=$BUILD_RPMS_9_1_i386 ;;
|
---|
64 | esac
|
---|
65 | if [ "$BUILD_RPMS_TEST" ]; then
|
---|
66 | if [ "$BUILD_RPMS" ]; then
|
---|
67 | BUILD_RPMS=$BUILD_RPMS:$BUILD_RPMS_TEST
|
---|
68 | else
|
---|
69 | BUILD_RPMS=$BUILD_RPMS_TEST
|
---|
70 | fi
|
---|
71 | fi
|
---|
72 | fi
|
---|
73 |
|
---|
74 | echo BUILD_RPMS: $BUILD_RPMS
|
---|
75 |
|
---|
76 | ERROR=0
|
---|
77 |
|
---|
78 | # Hier gehts los:
|
---|
79 |
|
---|
80 | if [ -z "$1" ]; then
|
---|
81 | # without parameter, we are in source directory
|
---|
82 | test -e Makefile && make
|
---|
83 | SPECFILE=$(ls *.spec | awk '{print $1}')
|
---|
84 | TARFILE=$(ls *.tar.[gb]z*| awk '{print $1}')
|
---|
85 | PACKAGE=$(awk '/^Name:/ {print $2}' <$SPECFILE)
|
---|
86 | VERSION=$(awk '/^Version:/ {print $2}' <$SPECFILE)
|
---|
87 | SRC_FILES="$SPECFILE $TARFILE"
|
---|
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 | SRC_FILES="$1"
|
---|
93 | fi
|
---|
94 |
|
---|
95 | echo $PACKAGE $VERSION $BUILD_DIST $BUILD_MODE
|
---|
96 |
|
---|
97 | # Cleaning up and install tempdir
|
---|
98 | #ssh -${SSH_VERSION} ${FQBUILDHOST} "\
|
---|
99 | rm -rf ${BUILDTEMP}/src/${PACKAGE}; \
|
---|
100 | mkdir -p ${BUILDTEMP}/src/${PACKAGE} ${BUILDTEMP}/${BUILD_DIST};
|
---|
101 |
|
---|
102 | #scp -oProtocol=$SSH_VERSION $SRC_FILES ${FQBUILDHOST}:${BUILDTEMP}/src/${PACKAGE}
|
---|
103 | cp -a $SRC_FILES ${BUILDTEMP}/src/${PACKAGE}
|
---|
104 |
|
---|
105 | if [ "$1" ]; then
|
---|
106 | # extract RPM in a tempoary directory
|
---|
107 | #ssh -${SSH_VERSION} ${FQBUILDHOST} "\
|
---|
108 | cd ${BUILDTEMP}/src/${PACKAGE}; rpm2cpio $1 | cpio -i
|
---|
109 | fi
|
---|
110 |
|
---|
111 | # create buildscript
|
---|
112 |
|
---|
113 | cat > $BUILDSCRIPT <<EOF
|
---|
114 | #!/bin/bash
|
---|
115 | # local buildscript
|
---|
116 | #. /work/src/bin/.profile
|
---|
117 | export BUILD_ROOT=$BUILD_ROOT
|
---|
118 | export BUILD_DIST=$BUILD_DIST
|
---|
119 | export BUILD_RPMS=${BUILDTEMP}/${BUILD_DIST}:$BUILD_RPMS
|
---|
120 | export BUILD_PREPARE_SPEC=$BUILD_PREPARE_SPEC
|
---|
121 |
|
---|
122 | cd ${BUILDTEMP}/src/${PACKAGE}
|
---|
123 | #build $BUILD_MODE --prefer-rpms ${BUILDTEMP}/${BUILD_DIST}
|
---|
124 | #build $BUILD_MODE
|
---|
125 | $BUILD_CMD $BUILD_MODE
|
---|
126 | EOF
|
---|
127 | chmod a+x $BUILDSCRIPT
|
---|
128 |
|
---|
129 | #cat /tmp/tmpscript.$$
|
---|
130 |
|
---|
131 | #scp -oProtocol=$SSH_VERSION /tmp/tmpscript.$$ ${FQBUILDHOST}:${BUILDTEMP}/src/${PACKAGE}/buildscript
|
---|
132 | #rm /tmp/tmpscript.$$
|
---|
133 |
|
---|
134 | # build and file rpms
|
---|
135 | #ssh -oProtocol=$SSH_VERSION root@${FQBUILDHOST} \
|
---|
136 | # . ~$BUILDUSER/${BUILDTEMP}/src/${PACKAGE}/buildscript
|
---|
137 |
|
---|
138 | sudo su -c $BUILDSCRIPT
|
---|
139 | rm -f $BUILDSCRIPT
|
---|
140 |
|
---|
141 | #ssh -oProtocol=$SSH_VERSION ${FQBUILDHOST} \
|
---|
142 | rm -f ${BUILDTEMP}/${BUILD_DIST}/${PACKAGE}-*.*.rpm
|
---|
143 | cp -a ${BUILD_ROOT}/usr/src/packages/RPMS/*/${PACKAGE}-${VERSION}-*.*.rpm ${BUILDTEMP}/${BUILD_DIST}
|
---|
144 |
|
---|
145 | mkdir -p ${DEST_DIR}/src
|
---|
146 | # delete all old versions of this package
|
---|
147 | rm -f ${DEST_DIR}/src/${PACKAGE}-*.src.rpm
|
---|
148 | #if !(scp -oProtocol=$SSH_VERSION root@${FQBUILDHOST}:${BUILD_ROOT}/usr/src/packages/SRPMS/${PACKAGE}-${VERSION}-*.src.rpm ${DEST_DIR}/src ); then
|
---|
149 | #ERROR=1
|
---|
150 | #fi
|
---|
151 | if !(cp -a ${BUILD_ROOT}/usr/src/packages/SRPMS/${PACKAGE}-${VERSION}-*.src.rpm ${DEST_DIR}/src 2> /dev/null); then
|
---|
152 | ERROR=1
|
---|
153 | fi
|
---|
154 |
|
---|
155 | mkdir -p ${DEST_DIR}/${BUILD_DIST}
|
---|
156 | # delete all old versions of this package
|
---|
157 | rm -f ${DEST_DIR}/${BUILD_DIST}/${PACKAGE}-*.rpm
|
---|
158 | #if !(scp -oProtocol=$SSH_VERSION #root@${FQBUILDHOST}:${BUILD_ROOT}/usr/src/packages/RPMS/*/${PACKAGE}-${VERSION}-*.*.rpm ${DEST_DIR}/${BUILD_DIST} ); then
|
---|
159 | # ERROR=2
|
---|
160 | #fi
|
---|
161 | if !(cp -a ${BUILD_ROOT}/usr/src/packages/RPMS/*/${PACKAGE}-${VERSION}-*.*.rpm ${DEST_DIR}/${BUILD_DIST} ); then
|
---|
162 | ERROR=2
|
---|
163 | fi
|
---|
164 |
|
---|
165 | if [ $ERROR -ne 0 ]; then
|
---|
166 | echo "ERROR while building packet $PACKAGE";
|
---|
167 | for i in `seq 5`; do
|
---|
168 | echo -n "";
|
---|
169 | done
|
---|
170 | else
|
---|
171 | echo "Build of ${PACKAGE} completed!"
|
---|
172 | echo "Packages can be found in ${DEST_DIR}"
|
---|
173 | fi
|
---|
174 |
|
---|
175 | exit $ERROR
|
---|