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
case "$option" in
c)
CODENAME=$OPTARG
;;
d)
DISTRIBUTION=$OPTARG
;;
l)
BUILD_SRC_LOCALLY=true
;;
h)
usage
;;
:)
echo "Option -$OPTARG requires an argument"
exit 1
;;
\?)
echo "-$OPTARG: invalid option"
exit 1
;;
esac
done
shift $((OPTIND-1)) function main()
{
validate_argument
retrieve_package_info
build_sources
add_to_reprepro
# Parse DIR argument echo "Build will start soon. See 'rebuildd-job list | tail'"
if [ $# -ne 1 ]; then sendxmpppy "Launched build ${PACKAGE}/${VERSION} for ${DISTRIB}/${BRANCH} ..."
echo -e "Error: Missing DIR argument\n" }
usage
fi
PKG_DIR=$(readlink -fn $1)
ROOT_DIR=$(readlink -fn ${PKG_DIR}/../)
# Retrieve package info # ################# #
cd $PKG_DIR # Check user inputs #
package=$(dpkg-parsechangelog | awk '/^Source: / {print $2}') # ################# #
version=$(dpkg-parsechangelog | awk '/^Version: / {print $2}')
distribution=$(dpkg-parsechangelog | awk '/^Distribution: / {print $2}')
# Set and validate codename & distribution function validate_arguments()
if [ -z "$CODENAME" ]; then {
CODENAME=$DEFAULT_CODENAME # Distribution
elif ! [[ $AVAILABLE_CODENAMES =~ ^(.* |)$CODENAME( .*|)$ ]]; then if [[ ! $DISTRIB =~ ^stretch$ ]]; then
echo "Unmanaged codename '$CODENAME'" echo "Invalid distribution $DISTRIB"
exit 1 usage
fi exit 1
if [ -z "$DISTRIBUTION" ]; then fi
extract_codename_distribution $distribution || exit 1
fi
changes_file=${ROOT_DIR}/${package}_${version}_source.changes ## Branch
if [[ ! $BRANCH =~ ^testing|stable|unstable$ ]]; then
echo "Invalid branch $BRANCH"
usage
exit 2
fi
echo "Building source package of ${package}_${version}..." # Folder
if $BUILD_SRC_LOCALLY; then if [ -z "$FOLDER" ]; then
debuild -S -sa > /dev/null echo "Need a folder in which to build"
else usage
img="${PBUILDER_IMAGES}/${CODENAME}-amd64.tgz" exit 3
sudo pbuilder execute --bindmounts ${ROOT_DIR} \ fi
--basetgz ${img} -- ${BUILD_SOURCES} $PKG_DIR }
fi
if [ $? -ne 0 ] || [ ! -f ${changes_file} ]; then
echo "An error occured while building source package"
exit 1
fi
echo "Adding ${package}_${version} to ${CODENAME}/${DISTRIBUTION}..." function retrieve_package_info()
$INCLUDE_CHANGES $CODENAME $DISTRIBUTION $changes_file {
if [ $? -ne 0 ]; then readonly PKG_DIR=$(readlink -fn $FOLDER)
echo "An error occured while including source package" readonly ROOT_DIR=$(readlink -fn ${PKG_DIR}/../)
exit 1 cd $PKG_DIR
fi
#echo "Process incoming in repository..." readonly PACKAGE=$(dpkg-parsechangelog | awk '/^Source: / {print $2}')
#sudo reprepro -V -b $REPO_DIR processincoming incoming readonly VERSION=$(dpkg-parsechangelog | awk '/^Version: / {print $2}')
#if [ $? -ne 0 ]; then readonly CHANGES_FILE=${ROOT_DIR}/${PACKAGE}_${VERSION}_source.changes
# echo "An error occured while processing incoming" }
# exit 1
#fi
echo "Build will start soon. See http://$REPO_URL" # ######################################## #
# Invoke pbuilder to build the sources ... #
# ######################################## #
sendxmpppy "Launched build ${package}/${version} for ${CODENAME}/${DISTRIBUTION} ..." function build_sources()
{
echo "Building source package of ${PACKAGE}_${VERSION}..."
echo "---------------------------------------------------"
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"
exit 1
fi
}
function add_to_reprepro()
{
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"
exit 1
fi
}
main

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 .
} }