#!/bin/bash -ex usage() { cat <&2 ; exit 1; } OPTS=$(getopt -o b:s:e:o:u:h -l build-target:,source:,ext-repos:,output-dir:,upstream-repo:,help -- "$@") if [ $? != 0 ]; then usage_short exit 1 fi eval set -- "$OPTS" WORKING_DIR=${0%/*} while true ; do case "$1" in -h| --help ) usage ; exit 0;; -b | --build-target ) BUILD_TARGET="$2"; shift; shift;; -s | --source ) BUILD_SOURCE="$2"; shift; shift;; -e | --ext-repos ) EXTRAREPO="$2"; export EXTRAREPO; shift; shift;; -o | --output-dir ) OUTPUT_DIR="$2"; shift; shift;; -u | --upstream-repo ) UPSTREAM_MIRROR="$2"; export UPSTREAM_MIRROR; shift; shift;; -- ) shift; break;; * ) break;; esac done if [[ ${BUILD_SOURCE} = "" ]]; then BUILD_SOURCE=${PWD} fi build_docker_image() { case "$BUILD_TARGET" in centos7) docker build -t mockbuild "${WORKING_DIR}"/docker-builder/mockbuild/ ;; trusty) docker build -t sbuild "${WORKING_DIR}"/docker-builder/sbuild/ ;; esac } create_buildroot() { case "$BUILD_TARGET" in centos7) "${WORKING_DIR}"/docker-builder/create-rpm-chroot.sh ;; trusty) "${WORKING_DIR}"/docker-builder/create-deb-chroot.sh ;; *) die "Unknown build target specified. Currently 'trusty' and 'centos7' are supported" esac } update_buildroot() { case "$BUILD_TARGET" in centos7) "${WORKING_DIR}"/docker-builder/update-rpm-chroot.sh ;; trusty) "${WORKING_DIR}"/docker-builder/update-deb-chroot.sh ;; *) die "Unknown build target specified. Currently 'trusty' and 'centos7' are supported" esac } main () { case "$BUILD_TARGET" in trusty) export DIST="${BUILD_TARGET}" if [[ "$(docker images -q sbuild 2> /dev/null)" == "" ]]; then build_docker_image create_buildroot else if [[ ! -d /var/cache/docker-builder/sbuild/"${BUILD_TARGET}"-amd64 ]]; then create_buildroot else update_buildroot fi fi cd "${BUILD_SOURCE}" bash -ex "${WORKING_DIR}"/docker-builder/build-deb-package.sh local exitstatus=`cat buildresult/exitstatus.sbuild || echo 1` if [[ "${OUTPUT_DIR}" != "" ]]; then mkdir -p "${OUTPUT_DIR}" mv buildresult/* "${OUTPUT_DIR}" rm -rf buildresult fi ;; centos7) export DIST="${BUILD_TARGET}" if [[ "$(docker images -q mockbuild 2> /dev/null)" == "" ]]; then build_docker_image create_buildroot else if [[ ! -d /var/cache/docker-builder/mock/cache/epel-7-x86_64 ]]; then create_buildroot else update_buildroot fi fi cd "${BUILD_SOURCE}" bash -ex "${WORKING_DIR}"/docker-builder/build-rpm-package.sh local exitstatus=`cat build/exitstatus.mock || echo 1` if [[ "${OUTPUT_DIR}" != "" ]]; then mkdir -p "${OUTPUT_DIR}" mv build/* "${OUTPUT_DIR}" rm -rf build fi ;; *) die "Unknown build target specified. Currently 'trusty' and 'centos7' are supported" esac exit "${exitstatus}" } main "${@}"