Misc cleaning / simplification / cosmetic improvement in build scripts

This commit is contained in:
Alexandre Aubin 2018-06-30 22:59:14 +00:00
parent 45df3b78f2
commit 9641e58a3d
5 changed files with 131 additions and 155 deletions

View file

@ -2,6 +2,7 @@
apt-get install nginx pbuilder reprepro rebuildd gawk sendxmpp -y
apt-get install qemu-system-arm debootstrap cdebootstrap qemu-user-static -y
apt-get install python-virtualenv python3-pip -y
apt-get install boxes -y
# Fix the damn pbuilder-satistydepends (aptitude causes segfault on ARM)
cd /usr/lib/pbuilder

View file

@ -6,11 +6,13 @@ readonly BRANCH=$2
readonly FOLDER=$3
source /home/vinaigrette/config/config
source /home/vinaigrette/scripts/common.sh
export DEBSIGN_KEYID
export DEBFULLNAME
export DEBEMAIL
IMG="${PBUILDER_IMAGES}/${DISTRIB}-amd64.tgz"
readonly IMG="${PBUILDER_IMAGES}/${DISTRIB}-amd64.tgz"
# ##### #
# Usage #
@ -38,7 +40,7 @@ function main()
build_sources
add_to_reprepro
echo "Build will start soon. See 'rebuildd-job list | tail'"
success "Build will start soon. See 'rebuildd-job list | tail'"
sendxmpppy "Added builds for ${PACKAGE}/${VERSION} in branch ${BRANCH} ..."
}
@ -48,26 +50,9 @@ function main()
function validate_arguments()
{
# Distribution
if [[ ! $DISTRIB =~ ^stretch$ ]]; then
echo "Invalid distribution $DISTRIB"
usage
exit 1
fi
## Branch
if [[ ! $BRANCH =~ ^testing|stable|unstable$ ]]; then
echo "Invalid branch $BRANCH"
usage
exit 2
fi
# Folder
if [ -z "$FOLDER" ]; then
echo "Need a folder in which to build"
usage
exit 3
fi
[[ $DISTRIB =~ ^stretch$ ]] || critical "Invalid distribution $DISTRIB"
[[ $BRANCH =~ ^testing|stable|unstable$ ]] || critical "Invalid branch $BRANCH"
[[ ! -z "$FOLDER" ]] || critical "Need a folder in which to build"
}
function retrieve_package_info()
@ -87,28 +72,19 @@ function retrieve_package_info()
function build_sources()
{
echo "---------------------------------------------------"
echo "Building source package of ${PACKAGE}_${VERSION}..."
echo "---------------------------------------------------"
boxed "Building source package of ${PACKAGE} ${VERSION} ..."
sudo pbuilder execute --bindmounts ${ROOT_DIR} --basetgz ${IMG} -- ${BUILD_SOURCES} $PKG_DIR
sudo pbuilder execute --bindmounts ${ROOT_DIR} --basetgz ${IMG} -- ${BUILD_SOURCES} $PKG_DIR \
|| critical "An error occured while building source package"
if [ $? -ne 0 ] || [ ! -f ${CHANGES_FILE} ]; then
echo "An error occured while building source package"
exit 1
fi
[[ -f ${CHANGES_FILE} ]] || critical "An error occured while building source package (no change file available)"
}
function add_to_reprepro()
{
echo "---------------------------------------------------"
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
boxed "Adding ${PACKAGE}_${VERSION} to ${DISTRIB}/${BRANCH}..."
$INCLUDE_CHANGES $DISTRIB $BRANCH $CHANGES_FILE || critical "An error occured while including source package"
}
main
[[ "$1" =~ ^-h|--help$ ]] && (usage; exit 0) || main

48
scripts/common.sh Normal file
View file

@ -0,0 +1,48 @@
readonly NORMAL=$(printf '\033[0m')
readonly BOLD=$(printf '\033[1m')
readonly faint=$(printf '\033[2m')
readonly UNDERLINE=$(printf '\033[4m')
readonly NEGATIVE=$(printf '\033[7m')
readonly RED=$(printf '\033[31m')
readonly GREEN=$(printf '\033[32m')
readonly ORANGE=$(printf '\033[33m')
readonly BLUE=$(printf '\033[34m')
readonly YELLOW=$(printf '\033[93m')
readonly WHITE=$(printf '\033[39m')
function success()
{
local msg=${1}
echo "[${BOLD}${GREEN} OK ${NORMAL}] ${msg}"
}
function info()
{
local msg=${1}
echo "[${BOLD}${BLUE}INFO${NORMAL}] ${msg}"
}
function boxed()
{
local msg=${1}
echo "$msg" | boxes -d stone
}
function warn()
{
local msg=${1}
echo "[${BOLD}${ORANGE}WARN${NORMAL}] ${msg}" 2>&1
}
function error()
{
local msg=${1}
echo "[${BOLD}${RED}FAIL${NORMAL}] ${msg}" 2>&1
}
function critical()
{
local msg=${1}
echo "[${BOLD}${RED}CRIT${NORMAL}] ${msg}" 2>&1
exit 1
}

View file

@ -1,88 +1,100 @@
#!/bin/bash
readonly THISSCRIPT=$0
readonly BRANCH="testing"
readonly PACKAGE=$1
readonly BRANCH=$2
readonly DISTRIB="stretch"
readonly DEBIAN_BRANCH="testing"
readonly BUILD_MESSAGE="YunoHost custom build."
source /home/vinaigrette/config/config
source /home/vinaigrette/scripts/common.sh
# ##### #
# Usage #
# ##### #
function usage()
{
cat << EOF
Usage:
$THISSCRIPT <project> <branch> <version>
Arguments:
<project> metronome, rspamd or unscd
<branch> stable, testing or unstable
EOF
}
function main()
{
build_metronome
build_rspamd
build_unscd
validate_arguments
cd $GIT_REPOS/$PACKAGE
tweak_$PACKAGE
build
}
function build_metronome()
# ################# #
# Check user inputs #
# ################# #
function validate_arguments()
{
[[ $PACKAGE =~ ^metronome|rspamd|unscd$ ]] || critical "Invalid package $PACKAGE"
[[ $BRANCH =~ ^testing|stable|unstable$ ]] || critical "Invalid branch $BRANCH"
[[ "$(tty)" != "not a tty" ]] || critical "You aint in a tty (are you in a 'lxc exec' ?) The script can't run because pbuilder won't be happy :|"
}
local PACKAGE="metronome"
cd $GIT_REPOS/$PACKAGE
# ##################### #
# Build recipe / tweaks #
# ##################### #
function tweak_metronome()
{
# For some reason metronome version must include a revision ("-x")
local VERSION="$(dpkg-parsechangelog -S Version 2>/dev/null)+yunohost-1"
build $PACKAGE $VERSION
readonly VERSION="$(dpkg-parsechangelog -S Version 2>/dev/null)+yunohost-1"
}
function build_unscd()
function tweak_unscd()
{
local PACKAGE="unscd"
cd $GIT_REPOS/$PACKAGE
local VERSION="$(dpkg-parsechangelog -S Version 2>/dev/null)+yunohost"
build $PACKAGE $VERSION
readonly VERSION="$(dpkg-parsechangelog -S Version 2>/dev/null)+yunohost"
}
function build_rspamd()
function tweak_rspamd()
{
local PACKAGE="rspamd"
cd $GIT_REPOS/$PACKAGE
git checkout master
git pull origin master
# Get last tag and deduce version number to user...
local LASTTAG=$(git tag --list | grep "^1." | sort -n | tail -n1)
local VERSION="${LASTTAG}+yunohost"
readonly VERSION="${LASTTAG}+yunohost"
git checkout $LASTTAG
build $PACKAGE $VERSION
}
function build()
{
local PACKAGE=$1
local VERSION=$2
# SVERSION is VERSION without the -1 at the end ...
local SVERSION=$(echo $VERSION | tr '-' ' ' | awk '{print $1}')
cd $GIT_REPOS/$PACKAGE
# Tweak the changelog temporarily
echo "> Setting version in changelog to ${VERSION}"
info "Setting version in changelog to ${VERSION}"
rm -f debian/changelog.dch
cp debian/changelog debian/changelog.old
dch --package "${PACKAGE}" \
--force-bad-version \
-v "${VERSION}" \
-D "${DEBIAN_BRANCH}" \
-D "${BRANCH}" \
--force-distribution \
$BUILD_MESSAGE \
"YunoHost custom build." \
> /dev/null 2>&1
# Create temporary folder
TMP_FOLDER=$(mktemp -d)
# Extract git archive a desired tag
echo "> Exporting in $TMP_FOLDER ... "
info "Exporting in $TMP_FOLDER ... "
git ls-files | xargs tar -czf archive.tar.gz
cat archive.tar.gz | tar -xz -C $TMP_FOLDER
# For some reason, these wants archive named
@ -91,15 +103,14 @@ function build()
mv archive.tar.gz $TMP_FOLDER/../${PACKAGE}_${SVERSION}.orig.tar.gz
# Build Debian package
echo "> Starting build ..."
cd $TMP_FOLDER
$BUILD_DEB $DISTRIB $BRANCH .
# Restore changelog
echo "> Restoring previous changelog"
info "Restoring previous changelog"
cd $GIT_REPOS/$PACKAGE
cp debian/changelog.old debian/changelog
rm debian/changelog.old
}
main
[[ "$1" =~ ^-h|--help$ ]] && (usage; exit 0) || main

View file

@ -8,6 +8,7 @@ readonly VERSION=$4
readonly TAG=$(echo "debian/$VERSION" | tr '~' '-')
source /home/vinaigrette/config/config
source /home/vinaigrette/scripts/common.sh
# ##### #
# Usage #
@ -35,42 +36,17 @@ EOF
function validate_arguments()
{
## Project
if [[ ! $PROJECT =~ ^yunohost|yunohost-admin|moulinette|SSOwat$ ]]; then
echo "Invalid project $PROJECT"
usage
exit 1
fi
## Branch
if [[ ! $BRANCH =~ ^testing|stable|unstable$ ]]; then
echo "Invalid branch $BRANCH"
usage
exit 2
fi
# Distribution
if [[ ! $DISTRIB =~ ^stretch$ ]]; then
echo "Invalid distribution $DISTRIB"
usage
exit 3
fi
# Version
if [ -z "$VERSION" ]; then
echo "Invalid version $VERSION"
usage
exit 4
fi
[[ $PROJECT =~ ^yunohost|yunohost-admin|moulinette|SSOwat$ ]] || critical "Invalid project $PROJECT"
[[ $BRANCH =~ ^testing|stable|unstable$ ]] || critical "Invalid branch $BRANCH"
[[ $DISTRIB =~ ^stretch$ ]]; || critical "Invalid distribution $DISTRIB"
[[ ! -z "$VERSION" ]] || critical "Invalid version $VERSION"
[[ "$(tty)" != "not a tty" ]] || critical "You aint in a tty (are you in a 'lxc exec' ?) The script can't run because pbuilder won't be happy :|"
}
function checkout_tag()
{
# Update project's repository
echo ""
echo "> Updating $GIT_REPOS/$PROJECT repository ... "
echo ""
boxed "> Updating $GIT_REPOS/$PROJECT repository ... "
cd $GIT_REPOS/$PROJECT
git fetch --quiet
@ -78,31 +54,18 @@ function checkout_tag()
git checkout $DISTRIB-$BRANCH --quiet
git reset --hard origin/$DISTRIB-$BRANCH --quiet
# Validate constrains for the version number given (is in changelog + has corresponding tag)
LASTVERSIONCHANGELOG=$(dpkg-parsechangelog -S Version 2>/dev/null)
[[ "$VERSION" == "$LASTVERSIONCHANGELOG" ]] || critical "Version $VERSION is not the last version in changelog"
git rev-parse "$TAG" >/dev/null 2>&1 || critical "Invalid version $VERSION (there's no tag $TAG in the git repo !)"
if [[ "$VERSION" != "$LASTVERSIONCHANGELOG" ]]
then
echo "Version $VERSION is not the last version in changelog"
exit
fi
# Check if tag really exists
if ! git rev-parse "$TAG" >/dev/null 2>&1;
then
echo "Invalid version $VERSION (there's no tag $TAG in the git repo !)"
exit
fi
# Get commit for the tag and for HEAD
TAGCOMMIT=$(git rev-parse "$TAG")
HEADCOMMIT=$(git rev-parse "HEAD")
if [[ "$TAGCOMMIT" != "$HEADCOMMIT" ]]
then
echo "Tag $TAG is not the HEAD of the branch :/"
exit
fi
[[ "$TAGCOMMIT" == "$HEADCOMMIT" ]] || critical "Tag $TAG is not the HEAD of the branch :/"
}
function build()
@ -111,15 +74,11 @@ function build()
TMP_FOLDER=$(mktemp -d)
# Extract git archive a desired tag
echo ""
echo "> Exporting in $TMP_FOLDER ... "
echo ""
info "Exporting in $TMP_FOLDER ... "
git archive $TAG --format=tar | tar -x -C $TMP_FOLDER
# Build Debian package
echo "###############################"
echo "# Building Debian package ... #"
echo "###############################"
boxed "Building Debian package ... "
cd $TMP_FOLDER
$BUILD_DEB $DISTRIB $BRANCH .
}
@ -127,32 +86,13 @@ function build()
function main()
{
# If used asked for help, show usage
if [[ $1 == "-h" ]] || [[ $1 == "--help" ]]; then
usage
exit 0
fi
validate_arguments
if [[ "$(tty)" == "not a tty" ]]
then
echo "You aint in a tty (are you in a 'lxc exec' ?)"
echo "The script can't run because pbuilder won't be happy :|"
exit
fi
# Sum up configuration
echo "########################################################"
echo "# Building $PROJECT $BRANCH release - $VERSION version "
echo "########################################################"
boxed "Building $PROJECT $BRANCH release - $VERSION version"
checkout_tag
build
}
main
[[ "$1" =~ ^-h|--help$ ]] && (usage; exit 0) || main