1 | #!/bin/bash
|
---|
2 | # Remote build script (iboernig@suse.de)
|
---|
3 | # $Id: build.sh 683 2004-08-13 17:14:33Z joergs $
|
---|
4 | #
|
---|
5 | # Kurze Featuritis:
|
---|
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
|
---|
10 | # ein tar-Archiv, bertr�t dieses nach Oldwotan und baut es dort
|
---|
11 | # - mit Parameter geht das Skript davon aus,
|
---|
12 | # dass der Parameter ein SRPM Paket ist.
|
---|
13 | # Dieses wird entpackt und dann gebaut.
|
---|
14 | # Wichtige Einstellungen:
|
---|
15 | # - Standardm�ig baut build.sh mit --clean, wenns schnell gehen soll, die
|
---|
16 | # Umgebungsvariable BUILD_MODE="--no-init" exportieren
|
---|
17 | # - BUILD_DIST ist standard sles7-i386, kann auch durch entsprechenden Export
|
---|
18 | # berschrieben werden.
|
---|
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
|
---|
22 |
|
---|
23 | CONFIG_FILE=/usr/local/etc/build
|
---|
24 | BUILD_CMD=build
|
---|
25 | #SSH_VERSION="1"
|
---|
26 | #BUILDHOST="oldwotan"
|
---|
27 | #FQBUILDHOST="$BUILDHOST.suse.de"
|
---|
28 | #BUILDTEMP=abuildtmp
|
---|
29 | BUILDUSER=$USER
|
---|
30 | BUILDTEMP=/tmp/abuildtmp/$BUILDUSER
|
---|
31 |
|
---|
32 | BUILDSCRIPT=$BUILDTEMP/buildscript.$$
|
---|
33 |
|
---|
34 | [ -z "$BUILD_MODE" ] && BUILD_MODE="--verify"
|
---|
35 | [ -z "$BUILD_DIST" ] && BUILD_DIST="sles8-i386+update"
|
---|
36 | [ -z "$BUILD_ROOT" ] && BUILD_ROOT="/var/tmp/buildsystem.$USER.$BUILD_DIST"
|
---|
37 | [ -z "$BUILD_PREPARE_SPEC" ] && BUILD_PREPARE_SPEC="no"
|
---|
38 |
|
---|
39 | [ -z $DEST_DIR ] && DEST_DIR="/tmp/build.$BUILDUSER"
|
---|
40 |
|
---|
41 | [ -z "$BUILD_USES_SVN" ] && BUILD_USES_SVN="yes"
|
---|
42 |
|
---|
43 |
|
---|
44 |
|
---|
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 ;;
|
---|
63 | "9.1-i386")
|
---|
64 | BUILD_RPMS_TEST=$BUILD_RPMS_9_1_i386 ;;
|
---|
65 | "sles9-i386")
|
---|
66 | BUILD_RPMS_TEST=$BUILD_RPMS_sles9_i386 ;;
|
---|
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 |
|
---|
79 | ERROR=0
|
---|
80 |
|
---|
81 | # Hier gehts los:
|
---|
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 |
|
---|
94 | echo $PACKAGE $VERSION $BUILD_DIST $BUILD_MODE
|
---|
95 |
|
---|
96 | rm -rf ${BUILDTEMP}/src/${PACKAGE};
|
---|
97 | mkdir -p ${BUILDTEMP}/src/${PACKAGE} ${BUILDTEMP}/${BUILD_DIST};
|
---|
98 |
|
---|
99 | if [ "$1" ]; then
|
---|
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
|
---|
114 | # changelog header
|
---|
115 | DATE=`unset LANG; date +"%a %b %d %Y"`
|
---|
116 | echo -e "* $DATE -\n" > Changes
|
---|
117 | echo "- Subversion status:" >> Changes
|
---|
118 | # additional infos for the Changes file (see if everything is checked in)
|
---|
119 | svn status -v | grep -v '^? ' >> Changes
|
---|
120 | echo >> Changes
|
---|
121 | echo "- ChangeLog:" >> Changes
|
---|
122 | # requires connection to the subversion server
|
---|
123 | svn log -v . > ChangeLog.new && mv ChangeLog.new ChangeLog
|
---|
124 | cat ChangeLog >> Changes
|
---|
125 | cat Changes >> ${BUILDTEMP}/src/${PACKAGE}/$SPECFILE
|
---|
126 | fi
|
---|
127 | # just make sure, that the Changes file exist
|
---|
128 | touch Changes
|
---|
129 |
|
---|
130 | # if "SOURCES" file exist, create tar file on the fly
|
---|
131 | if [ -r "SOURCES" ]; then
|
---|
132 | # create a tar file from the sources
|
---|
133 | tar cvjf ${BUILDTEMP}/src/${PACKAGE}/$PACKAGE-$VERSION.tar.bz2 --files-from SOURCES
|
---|
134 | else
|
---|
135 | # legacy method:
|
---|
136 | # call the existing makefile to generate a tar file
|
---|
137 | test -e Makefile && make
|
---|
138 | TARFILE=$(ls *.tar.[gb]z*| awk '{print $1}')
|
---|
139 | cp -a $TARFILE ${BUILDTEMP}/src/${PACKAGE}
|
---|
140 | fi
|
---|
141 | fi
|
---|
142 |
|
---|
143 | # create buildscript
|
---|
144 | cat > $BUILDSCRIPT <<EOF
|
---|
145 | #!/bin/bash
|
---|
146 | # local buildscript
|
---|
147 | #. /work/src/bin/.profile
|
---|
148 | export BUILD_ROOT=$BUILD_ROOT
|
---|
149 | export BUILD_DIST=$BUILD_DIST
|
---|
150 | export BUILD_RPMS=${BUILDTEMP}/${BUILD_DIST}:$BUILD_RPMS
|
---|
151 | export BUILD_PREPARE_SPEC=$BUILD_PREPARE_SPEC
|
---|
152 |
|
---|
153 | cd ${BUILDTEMP}/src/${PACKAGE}
|
---|
154 | #build $BUILD_MODE --prefer-rpms ${BUILDTEMP}/${BUILD_DIST}
|
---|
155 | #build $BUILD_MODE
|
---|
156 | $BUILD_CMD $BUILD_MODE
|
---|
157 | EOF
|
---|
158 |
|
---|
159 | chmod a+x $BUILDSCRIPT
|
---|
160 | sudo su -c $BUILDSCRIPT
|
---|
161 | rm -f $BUILDSCRIPT
|
---|
162 |
|
---|
163 | rm -f ${BUILDTEMP}/${BUILD_DIST}/${PACKAGE}-*.*.rpm
|
---|
164 | cp -a ${BUILD_ROOT}/usr/src/packages/RPMS/*/${PACKAGE}-${VERSION}-*.*.rpm ${BUILDTEMP}/${BUILD_DIST}
|
---|
165 |
|
---|
166 | mkdir -p ${DEST_DIR}/src
|
---|
167 | # delete all old versions of this package
|
---|
168 | rm -f ${DEST_DIR}/src/${PACKAGE}-*.src.rpm
|
---|
169 |
|
---|
170 | if !(cp -a ${BUILD_ROOT}/usr/src/packages/SRPMS/${PACKAGE}-${VERSION}-*.src.rpm ${DEST_DIR}/src 2> /dev/null); then
|
---|
171 | ERROR=1
|
---|
172 | fi
|
---|
173 |
|
---|
174 | mkdir -p ${DEST_DIR}/${BUILD_DIST}
|
---|
175 | # delete all old versions of this package
|
---|
176 | rm -f ${DEST_DIR}/${BUILD_DIST}/${PACKAGE}-*.rpm
|
---|
177 |
|
---|
178 | if !(cp -a ${BUILD_ROOT}/usr/src/packages/RPMS/*/${PACKAGE}-${VERSION}-*.*.rpm ${DEST_DIR}/${BUILD_DIST} ); then
|
---|
179 | ERROR=2
|
---|
180 | fi
|
---|
181 |
|
---|
182 | if [ $ERROR -ne 0 ]; then
|
---|
183 | echo "ERROR while building packet $PACKAGE";
|
---|
184 | for i in `seq 5`; do
|
---|
185 | echo -n "";
|
---|
186 | done
|
---|
187 | else
|
---|
188 | echo "Build of ${PACKAGE} completed!"
|
---|
189 | echo "Packages can be found in ${DEST_DIR}"
|
---|
190 | fi
|
---|
191 |
|
---|
192 | exit $ERROR
|
---|