1 |
|
---|
2 | #!/bin/bash
|
---|
3 | # Remote build script (iboernig@suse.de)
|
---|
4 | # $Id: build.sh 675 2004-05-15 08:26:56Z 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ägt 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 | #SSH_VERSION="1"
|
---|
28 | #BUILDHOST="oldwotan"
|
---|
29 | #FQBUILDHOST="$BUILDHOST.suse.de"
|
---|
30 | #BUILDTEMP=abuildtmp
|
---|
31 | BUILDUSER=$USER
|
---|
32 | BUILDTEMP=/tmp/abuildtmp/$BUILDUSER
|
---|
33 |
|
---|
34 | BUILDSCRIPT=$BUILDTEMP/buildscript.$$
|
---|
35 |
|
---|
36 | [ -z "$BUILD_MODE" ] && BUILD_MODE="--verify"
|
---|
37 | [ -z "$BUILD_DIST" ] && BUILD_DIST="sles8-i386+update"
|
---|
38 | [ -z "$BUILD_ROOT" ] && BUILD_ROOT="/var/tmp/buildsystem.$USER.$BUILD_DIST"
|
---|
39 | [ -z "$BUILD_PREPARE_SPEC" ] && BUILD_PREPARE_SPEC="no"
|
---|
40 |
|
---|
41 | [ -z $DEST_DIR ] && DEST_DIR="/tmp/build.$BUILDUSER"
|
---|
42 |
|
---|
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 |
|
---|
73 | ERROR=0
|
---|
74 |
|
---|
75 | # Hier gehts los:
|
---|
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 |
|
---|
92 | echo $PACKAGE $VERSION $BUILD_DIST $BUILD_MODE
|
---|
93 |
|
---|
94 | # Cleaning up and install tempdir
|
---|
95 | #ssh -${SSH_VERSION} ${FQBUILDHOST} "\
|
---|
96 | rm -rf ${BUILDTEMP}/src/${PACKAGE}; \
|
---|
97 | mkdir -p ${BUILDTEMP}/src/${PACKAGE} ${BUILDTEMP}/${BUILD_DIST};
|
---|
98 |
|
---|
99 | #scp -oProtocol=$SSH_VERSION $SRC_FILES ${FQBUILDHOST}:${BUILDTEMP}/src/${PACKAGE}
|
---|
100 | cp -a $SRC_FILES ${BUILDTEMP}/src/${PACKAGE}
|
---|
101 |
|
---|
102 | if [ "$1" ]; then
|
---|
103 | # extract RPM in a tempoary directory
|
---|
104 | #ssh -${SSH_VERSION} ${FQBUILDHOST} "\
|
---|
105 | cd ${BUILDTEMP}/src/${PACKAGE}; rpm2cpio $1 | cpio -i
|
---|
106 | fi
|
---|
107 |
|
---|
108 | # create buildscript
|
---|
109 |
|
---|
110 | cat > $BUILDSCRIPT <<EOF
|
---|
111 | #!/bin/bash
|
---|
112 | # local buildscript
|
---|
113 | #. /work/src/bin/.profile
|
---|
114 | export BUILD_ROOT=$BUILD_ROOT
|
---|
115 | export BUILD_DIST=$BUILD_DIST
|
---|
116 | export BUILD_RPMS=${BUILDTEMP}/${BUILD_DIST}:$BUILD_RPMS
|
---|
117 | export BUILD_PREPARE_SPEC=$BUILD_PREPARE_SPEC
|
---|
118 |
|
---|
119 | cd ${BUILDTEMP}/src/${PACKAGE}
|
---|
120 | #build $BUILD_MODE --prefer-rpms ${BUILDTEMP}/${BUILD_DIST}
|
---|
121 | build $BUILD_MODE
|
---|
122 | EOF
|
---|
123 | chmod a+x $BUILDSCRIPT
|
---|
124 |
|
---|
125 | #cat /tmp/tmpscript.$$
|
---|
126 |
|
---|
127 | #scp -oProtocol=$SSH_VERSION /tmp/tmpscript.$$ ${FQBUILDHOST}:${BUILDTEMP}/src/${PACKAGE}/buildscript
|
---|
128 | #rm /tmp/tmpscript.$$
|
---|
129 |
|
---|
130 | # build and file rpms
|
---|
131 | #ssh -oProtocol=$SSH_VERSION root@${FQBUILDHOST} \
|
---|
132 | # . ~$BUILDUSER/${BUILDTEMP}/src/${PACKAGE}/buildscript
|
---|
133 |
|
---|
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 |
|
---|
141 | mkdir -p ${DEST_DIR}/src
|
---|
142 | # delete all old versions of this package
|
---|
143 | rm -f ${DEST_DIR}/src/${PACKAGE}-*.src.rpm
|
---|
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
|
---|
148 | ERROR=1
|
---|
149 | fi
|
---|
150 |
|
---|
151 | mkdir -p ${DEST_DIR}/${BUILD_DIST}
|
---|
152 | # delete all old versions of this package
|
---|
153 | rm -f ${DEST_DIR}/${BUILD_DIST}/${PACKAGE}-*.rpm
|
---|
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
|
---|
158 | ERROR=2
|
---|
159 | fi
|
---|
160 |
|
---|
161 | if [ $ERROR -ne 0 ]; then
|
---|
162 | echo "ERROR while building packet $PACKAGE";
|
---|
163 | for i in `seq 5`; do
|
---|
164 | echo -n "";
|
---|
165 | done
|
---|
166 | else
|
---|
167 | echo "Build of ${PACKAGE} completed!"
|
---|
168 | echo "Packages can be found in ${DEST_DIR}"
|
---|
169 | fi
|
---|
170 |
|
---|
171 | exit $ERROR
|
---|