|
| 1 | +#!/bin/sh |
| 2 | +# PMP package build script |
| 3 | +# |
| 4 | +# Required packages: rpm-build dpkg fakeroot php perl-Time-HiRes |
| 5 | + |
| 6 | +set -e |
| 7 | + |
| 8 | +TARGET=/opt/PKGS |
| 9 | +WORK_DIR=/tmp/pkgbuild-`date +%s` |
| 10 | + |
| 11 | +if [ -n "${JOB_NAME}${BUILD_NUMBER}${WORKSPACE}" ]; then |
| 12 | + # Build from Jenkins |
| 13 | + SOURCE=$WORKSPACE |
| 14 | + RELEASE=$BUILD_NUMBER |
| 15 | +elif [ "$#" = 2 ]; then |
| 16 | + # Manual build |
| 17 | + SOURCE=$1 |
| 18 | + RELEASE=$2 |
| 19 | +else |
| 20 | + echo "USAGE: use Jenkins or give args: sh build.sh <source_path> <build_number>" |
| 21 | + exit 1 |
| 22 | +fi |
| 23 | + |
| 24 | +# Prepare the source code and docs |
| 25 | +mkdir -p $WORK_DIR $TARGET |
| 26 | +cp -pr $SOURCE $WORK_DIR/source_code |
| 27 | +cd $WORK_DIR/source_code |
| 28 | +./make.sh nodocs > /dev/null |
| 29 | +VERSION="$(cat VERSION)" |
| 30 | +FINAL_CODE=source_code/release/percona-monitoring-plugins-$VERSION |
| 31 | +mv release/percona-monitoring-plugins-$VERSION.tar.gz $TARGET |
| 32 | +echo "Tarball created: $TARGET/percona-monitoring-plugins-$VERSION.tar.gz" |
| 33 | + |
| 34 | +build_rpm() { |
| 35 | + PROJECT=$1 |
| 36 | + NAME=$PROJECT-$VERSION |
| 37 | + ARCH=noarch |
| 38 | + |
| 39 | + mkdir -p $WORK_DIR/rpm/{BUILD,BUILDROOT,RPMS,SOURCES,SRPMS} |
| 40 | + cp -r $WORK_DIR/$FINAL_CODE $WORK_DIR/rpm/SOURCES/$NAME |
| 41 | + cd $WORK_DIR/rpm/SOURCES/ |
| 42 | + tar czf $NAME.tar.gz $NAME/ |
| 43 | + cd .. |
| 44 | + |
| 45 | + rpmbuild --quiet -ba $SOURCE/build/rpm/$PROJECT.spec \ |
| 46 | + --define "_topdir $WORK_DIR/rpm" \ |
| 47 | + --define "version $VERSION" \ |
| 48 | + --define "release $RELEASE" |
| 49 | + PKG=$NAME-$RELEASE.$ARCH.rpm |
| 50 | + mv RPMS/$ARCH/$PKG $TARGET |
| 51 | + rm -rf $WORK_DIR/rpm |
| 52 | + |
| 53 | + if [ "$DEBUG" = 1 ]; then |
| 54 | + rpm -qpil $TARGET/$PKG |
| 55 | + echo |
| 56 | + fi |
| 57 | + echo "Package created: $TARGET/$PKG" |
| 58 | +} |
| 59 | + |
| 60 | +build_deb() { |
| 61 | + PROJECT=$1 |
| 62 | + NAME=${PROJECT}_$VERSION |
| 63 | + ARCH=all |
| 64 | + |
| 65 | + mkdir -p $WORK_DIR/deb/$NAME/DEBIAN |
| 66 | + cd $WORK_DIR/deb |
| 67 | + cp $SOURCE/build/deb/$PROJECT/* $WORK_DIR/deb/$NAME/DEBIAN/ |
| 68 | + sed -i "s/%{version}/$VERSION-$RELEASE/" $WORK_DIR/deb/$NAME/DEBIAN/control |
| 69 | + $SOURCE/build/deb/$PROJECT/files $WORK_DIR/$FINAL_CODE $WORK_DIR/deb/$NAME |
| 70 | + |
| 71 | + fakeroot dpkg --build $NAME > /dev/null |
| 72 | + PKG=${NAME}-${RELEASE}_${ARCH}.deb |
| 73 | + mv $NAME.deb $TARGET/$PKG |
| 74 | + rm -rf $WORK_DIR/deb |
| 75 | + |
| 76 | + if [ "$DEBUG" = 1 ]; then |
| 77 | + echo |
| 78 | + dpkg -I $TARGET/$PKG |
| 79 | + dpkg -c $TARGET/$PKG |
| 80 | + echo |
| 81 | + fi |
| 82 | + echo "Package created: $TARGET/$PKG" |
| 83 | +} |
| 84 | + |
| 85 | +build_rpm percona-nagios-plugins |
| 86 | +build_rpm percona-cacti-templates |
| 87 | +build_deb percona-nagios-plugins |
| 88 | +build_deb percona-cacti-templates |
| 89 | + |
| 90 | +rm -rf $WORK_DIR |
| 91 | +exit 0 |
0 commit comments