2017-08-29 17:17:25 +02:00
#!/bin/bash
2018-05-03 02:33:47 +02:00
readonly THISSCRIPT=$0
readonly DISTRIB=$1
readonly BRANCH=$2
readonly FOLDER=$3
2017-08-29 17:17:25 +02:00
2017-08-30 05:51:28 +02:00
source /home/vinaigrette/config/config
2018-07-01 00:59:14 +02:00
source /home/vinaigrette/scripts/common.sh
2017-08-29 17:17:25 +02:00
export DEBSIGN_KEYID
export DEBFULLNAME
export DEBEMAIL
2020-05-07 17:11:46 +02:00
readonly IMG="${PBUILDER_CHROOTS}/${DISTRIB}-amd64.tgz"
2018-05-03 02:33:47 +02:00
# ##### #
# Usage #
# ##### #
function usage()
2017-08-29 17:17:25 +02:00
{
2018-05-03 02:33:47 +02:00
cat << EOF
Usage:
$THISSCRIPT <distrib> <branch> <folder>
Arguments:
2020-02-07 23:24:00 +01:00
<distrib> stretch or buster
2018-05-03 02:33:47 +02:00
<branch> stable, testing, or unstable
<folder> the folder in which to build...
2017-08-29 17:17:25 +02:00
EOF
}
2018-05-03 02:33:47 +02:00
function main()
{
2018-05-03 03:21:34 +02:00
validate_arguments
2018-05-03 02:33:47 +02:00
retrieve_package_info
build_sources
add_to_reprepro
2018-07-01 00:59:14 +02:00
success "Build will start soon. See 'rebuildd-job list | tail'"
2020-06-04 21:35:28 +02:00
sendxmpppy "➕ Added build for ${PACKAGE}/${VERSION} for ${DISTRIB}/${BRANCH} ..."
2018-05-03 02:33:47 +02:00
}
# ################# #
# Check user inputs #
# ################# #
function validate_arguments()
{
2020-02-07 23:24:00 +01:00
[[ $DISTRIB =~ ^stretch|buster$ ]] || critical "Invalid distribution $DISTRIB"
2018-07-01 00:59:14 +02:00
[[ $BRANCH =~ ^testing|stable|unstable$ ]] || critical "Invalid branch $BRANCH"
[[ ! -z "$FOLDER" ]] || critical "Need a folder in which to build"
2018-05-03 02:33:47 +02:00
}
function retrieve_package_info()
{
readonly PKG_DIR=$(readlink -fn $FOLDER)
readonly ROOT_DIR=$(readlink -fn ${PKG_DIR}/../)
cd $PKG_DIR
readonly PACKAGE=$(dpkg-parsechangelog | awk '/^Source: / {print $2}')
readonly VERSION=$(dpkg-parsechangelog | awk '/^Version: / {print $2}')
readonly CHANGES_FILE=${ROOT_DIR}/${PACKAGE}_${VERSION}_source.changes
}
# ######################################## #
# Invoke pbuilder to build the sources ... #
# ######################################## #
function build_sources()
{
2018-07-01 00:59:14 +02:00
boxed "Building source package of ${PACKAGE} ${VERSION} ..."
2018-05-03 02:33:47 +02:00
2019-01-30 19:50:30 +01:00
pbuilder execute --bindmounts ${ROOT_DIR} --basetgz ${IMG} -- ${BUILD_SOURCES} $PKG_DIR \
2020-06-04 21:35:28 +02:00
|| { sendxmpppy "❌ Failed to build source package for $PACKAGE"; critical "An error occured while building source package"; }
2018-05-03 02:33:47 +02:00
2020-06-04 21:35:28 +02:00
[[ -f ${CHANGES_FILE} ]] || { sendxmpppy "❌ Failed to build source package for $PACKAGE"; critical "An error occured while building source package (no change file available)"; }
2018-05-03 02:33:47 +02:00
}
function add_to_reprepro()
{
2018-07-01 00:59:14 +02:00
boxed "Adding ${PACKAGE}_${VERSION} to ${DISTRIB}/${BRANCH}..."
2020-06-04 21:35:28 +02:00
$INCLUDE_CHANGES $DISTRIB $BRANCH $CHANGES_FILE || { sendxmpppy "❌ Failed to include changes for source package $PACKAGE"; critical "An error occured while including source package"; }
2018-05-03 02:33:47 +02:00
}
2018-07-01 00:59:14 +02:00
[[ "$1" =~ ^-h|--help$ ]] && (usage; exit 0) || main