Refactor build_deb because too much madness

This commit is contained in:
Alexandre Aubin 2018-05-03 02:33:47 +02:00
parent b50e2a4fdc
commit 436bae2b94
4 changed files with 92 additions and 99 deletions

View file

@ -103,7 +103,7 @@ function build()
# Build Debian package # Build Debian package
echo "> Starting build ..." echo "> Starting build ..."
cd $TMP_FOLDER cd $TMP_FOLDER
$BUILD_DEB -d $BRANCH_NIGHTLY -c $DISTRIB . $BUILD_DEB $DISTRIB $BRANCH_NIGHTLY .
} }
main main

View file

@ -1,120 +1,112 @@
#!/bin/bash #!/bin/bash
# Default options values readonly THISSCRIPT=$0
## Either building source in a chroot env or not readonly DISTRIB=$1
BUILD_SRC_LOCALLY=false readonly BRANCH=$2
readonly FOLDER=$3
## Debian distribution to use
CODENAME=
DISTRIBUTION=
# Global and environment variables
source /home/vinaigrette/config/config source /home/vinaigrette/config/config
export DEBSIGN_KEYID export DEBSIGN_KEYID
export DEBFULLNAME export DEBFULLNAME
export DEBEMAIL export DEBEMAIL
usage() IMG="${PBUILDER_IMAGES}/${DISTRIB}-amd64.tgz"
# ##### #
# Usage #
# ##### #
function usage()
{ {
cat << EOF cat << EOF
Usage: `basename $0` [options] DIR
ARGUMENTS: Usage:
DIR Root directory of the package to build $THISSCRIPT <distrib> <branch> <folder>
OPTIONS: Arguments:
-c CODENAME Debian codename target <distrib> stretch (can only build for stretch, no jessie)
(one of: $AVAILABLE_CODENAMES) <branch> stable, testing, or unstable
-d COMPONENT Repository component to put package in <folder> the folder in which to build...
(one of: $AVAILABLE_COMPONENTS)
-l Build sources locally (without pbuilder)
-h Print this help
EOF EOF
exit
} }
# Parse options
while getopts :c:d:lh option; do function main()
case "$option" in {
c) validate_argument
CODENAME=$OPTARG retrieve_package_info
;; build_sources
d) add_to_reprepro
DISTRIBUTION=$OPTARG
;; echo "Build will start soon. See 'rebuildd-job list | tail'"
l) sendxmpppy "Launched build ${PACKAGE}/${VERSION} for ${DISTRIB}/${BRANCH} ..."
BUILD_SRC_LOCALLY=true }
;;
h) # ################# #
# Check user inputs #
# ################# #
function validate_arguments()
{
# Distribution
if [[ ! $DISTRIB =~ ^stretch$ ]]; then
echo "Invalid distribution $DISTRIB"
usage usage
;;
:)
echo "Option -$OPTARG requires an argument"
exit 1 exit 1
;; fi
\?)
echo "-$OPTARG: invalid option"
exit 1
;;
esac
done
shift $((OPTIND-1)) ## Branch
if [[ ! $BRANCH =~ ^testing|stable|unstable$ ]]; then
# Parse DIR argument echo "Invalid branch $BRANCH"
if [ $# -ne 1 ]; then
echo -e "Error: Missing DIR argument\n"
usage usage
fi exit 2
PKG_DIR=$(readlink -fn $1) fi
ROOT_DIR=$(readlink -fn ${PKG_DIR}/../)
# Retrieve package info # Folder
cd $PKG_DIR if [ -z "$FOLDER" ]; then
package=$(dpkg-parsechangelog | awk '/^Source: / {print $2}') echo "Need a folder in which to build"
version=$(dpkg-parsechangelog | awk '/^Version: / {print $2}') usage
distribution=$(dpkg-parsechangelog | awk '/^Distribution: / {print $2}') exit 3
fi
}
# Set and validate codename & distribution function retrieve_package_info()
if [ -z "$CODENAME" ]; then {
CODENAME=$DEFAULT_CODENAME readonly PKG_DIR=$(readlink -fn $FOLDER)
elif ! [[ $AVAILABLE_CODENAMES =~ ^(.* |)$CODENAME( .*|)$ ]]; then readonly ROOT_DIR=$(readlink -fn ${PKG_DIR}/../)
echo "Unmanaged codename '$CODENAME'" cd $PKG_DIR
exit 1
fi
if [ -z "$DISTRIBUTION" ]; then
extract_codename_distribution $distribution || exit 1
fi
changes_file=${ROOT_DIR}/${package}_${version}_source.changes 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
}
echo "Building source package of ${package}_${version}..." # ######################################## #
if $BUILD_SRC_LOCALLY; then # Invoke pbuilder to build the sources ... #
debuild -S -sa > /dev/null # ######################################## #
else
img="${PBUILDER_IMAGES}/${CODENAME}-amd64.tgz" function build_sources()
sudo pbuilder execute --bindmounts ${ROOT_DIR} \ {
--basetgz ${img} -- ${BUILD_SOURCES} $PKG_DIR echo "Building source package of ${PACKAGE}_${VERSION}..."
fi echo "---------------------------------------------------"
if [ $? -ne 0 ] || [ ! -f ${changes_file} ]; then
sudo pbuilder execute --bindmounts ${ROOT_DIR} --basetgz ${IMG} -- ${BUILD_SOURCES} $PKG_DIR
if [ $? -ne 0 ] || [ ! -f ${CHANGES_FILE} ]; then
echo "An error occured while building source package" echo "An error occured while building source package"
exit 1 exit 1
fi fi
}
echo "Adding ${package}_${version} to ${CODENAME}/${DISTRIBUTION}..." function add_to_reprepro()
$INCLUDE_CHANGES $CODENAME $DISTRIBUTION $changes_file {
if [ $? -ne 0 ]; then echo "Adding ${PACKAGE}_${VERSION} to ${DISTRIB}/${BRANCH}..."
echo "---------------------------------------------------"
$INCLUDE_CHANGES $DISTRIB $BRANCH $CHANGES_FILE
if [ $? -ne 0 ]; then
echo "An error occured while including source package" echo "An error occured while including source package"
exit 1 exit 1
fi fi
}
#echo "Process incoming in repository..." main
#sudo reprepro -V -b $REPO_DIR processincoming incoming
#if [ $? -ne 0 ]; then
# echo "An error occured while processing incoming"
# exit 1
#fi
echo "Build will start soon. See http://$REPO_URL"
sendxmpppy "Launched build ${package}/${version} for ${CODENAME}/${DISTRIBUTION} ..."

View file

@ -93,8 +93,9 @@ function build()
# Build Debian package # Build Debian package
echo "> Starting build ..." echo "> Starting build ..."
cd $TMP_FOLDER cd $TMP_FOLDER
$BUILD_DEB -d $BRANCH -c $DISTRIB . # Restore changelog $BUILD_DEB $DISTRIB $BRANCH .
# Restore changelog
echo "> Restoring previous changelog" echo "> Restoring previous changelog"
cd $GIT_REPOS/$PACKAGE cd $GIT_REPOS/$PACKAGE
cp debian/changelog.old debian/changelog cp debian/changelog.old debian/changelog

View file

@ -122,7 +122,7 @@ function build()
echo "# Building Debian package ... #" echo "# Building Debian package ... #"
echo "###############################" echo "###############################"
cd $TMP_FOLDER cd $TMP_FOLDER
$BUILD_DEB -d $BRANCH -c $DISTRIB . $BUILD_DEB $DISTRIB $BRANCH .
} }