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 nginx pbuilder reprepro rebuildd gawk sendxmpp -y
apt-get install qemu-system-arm debootstrap cdebootstrap qemu-user-static -y apt-get install qemu-system-arm debootstrap cdebootstrap qemu-user-static -y
apt-get install python-virtualenv python3-pip -y apt-get install python-virtualenv python3-pip -y
apt-get install boxes -y
# Fix the damn pbuilder-satistydepends (aptitude causes segfault on ARM) # Fix the damn pbuilder-satistydepends (aptitude causes segfault on ARM)
cd /usr/lib/pbuilder cd /usr/lib/pbuilder

View file

@ -6,11 +6,13 @@ readonly BRANCH=$2
readonly FOLDER=$3 readonly FOLDER=$3
source /home/vinaigrette/config/config source /home/vinaigrette/config/config
source /home/vinaigrette/scripts/common.sh
export DEBSIGN_KEYID export DEBSIGN_KEYID
export DEBFULLNAME export DEBFULLNAME
export DEBEMAIL export DEBEMAIL
IMG="${PBUILDER_IMAGES}/${DISTRIB}-amd64.tgz" readonly IMG="${PBUILDER_IMAGES}/${DISTRIB}-amd64.tgz"
# ##### # # ##### #
# Usage # # Usage #
@ -38,7 +40,7 @@ function main()
build_sources build_sources
add_to_reprepro 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} ..." sendxmpppy "Added builds for ${PACKAGE}/${VERSION} in branch ${BRANCH} ..."
} }
@ -48,26 +50,9 @@ function main()
function validate_arguments() function validate_arguments()
{ {
# Distribution [[ $DISTRIB =~ ^stretch$ ]] || critical "Invalid distribution $DISTRIB"
if [[ ! $DISTRIB =~ ^stretch$ ]]; then [[ $BRANCH =~ ^testing|stable|unstable$ ]] || critical "Invalid branch $BRANCH"
echo "Invalid distribution $DISTRIB" [[ ! -z "$FOLDER" ]] || critical "Need a folder in which to build"
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
} }
function retrieve_package_info() function retrieve_package_info()
@ -87,28 +72,19 @@ function retrieve_package_info()
function build_sources() function build_sources()
{ {
echo "---------------------------------------------------" boxed "Building source package of ${PACKAGE} ${VERSION} ..."
echo "Building source package of ${PACKAGE}_${VERSION}..."
echo "---------------------------------------------------"
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 [[ -f ${CHANGES_FILE} ]] || critical "An error occured while building source package (no change file available)"
echo "An error occured while building source package"
exit 1
fi
} }
function add_to_reprepro() function add_to_reprepro()
{ {
echo "---------------------------------------------------" boxed "Adding ${PACKAGE}_${VERSION} to ${DISTRIB}/${BRANCH}..."
echo "Adding ${PACKAGE}_${VERSION} to ${DISTRIB}/${BRANCH}..."
echo "---------------------------------------------------" $INCLUDE_CHANGES $DISTRIB $BRANCH $CHANGES_FILE || critical "An error occured while including source package"
$INCLUDE_CHANGES $DISTRIB $BRANCH $CHANGES_FILE
if [ $? -ne 0 ]; then
echo "An error occured while including source package"
exit 1
fi
} }
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 #!/bin/bash
readonly THISSCRIPT=$0 readonly THISSCRIPT=$0
readonly BRANCH="testing" readonly PACKAGE=$1
readonly BRANCH=$2
readonly DISTRIB="stretch" readonly DISTRIB="stretch"
readonly DEBIAN_BRANCH="testing"
readonly BUILD_MESSAGE="YunoHost custom build."
source /home/vinaigrette/config/config 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() function main()
{ {
build_metronome validate_arguments
build_rspamd cd $GIT_REPOS/$PACKAGE
build_unscd 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" # ##################### #
# Build recipe / tweaks #
cd $GIT_REPOS/$PACKAGE # ##################### #
function tweak_metronome()
{
# For some reason metronome version must include a revision ("-x") # For some reason metronome version must include a revision ("-x")
local VERSION="$(dpkg-parsechangelog -S Version 2>/dev/null)+yunohost-1" readonly VERSION="$(dpkg-parsechangelog -S Version 2>/dev/null)+yunohost-1"
build $PACKAGE $VERSION
} }
function build_unscd() function tweak_unscd()
{ {
readonly VERSION="$(dpkg-parsechangelog -S Version 2>/dev/null)+yunohost"
local PACKAGE="unscd"
cd $GIT_REPOS/$PACKAGE
local VERSION="$(dpkg-parsechangelog -S Version 2>/dev/null)+yunohost"
build $PACKAGE $VERSION
} }
function build_rspamd() function tweak_rspamd()
{ {
local PACKAGE="rspamd"
cd $GIT_REPOS/$PACKAGE
git checkout master git checkout master
git pull origin master git pull origin master
# Get last tag and deduce version number to user... # Get last tag and deduce version number to user...
local LASTTAG=$(git tag --list | grep "^1." | sort -n | tail -n1) local LASTTAG=$(git tag --list | grep "^1." | sort -n | tail -n1)
local VERSION="${LASTTAG}+yunohost" readonly VERSION="${LASTTAG}+yunohost"
git checkout $LASTTAG git checkout $LASTTAG
build $PACKAGE $VERSION
} }
function build() function build()
{ {
local PACKAGE=$1
local VERSION=$2
# SVERSION is VERSION without the -1 at the end ... # SVERSION is VERSION without the -1 at the end ...
local SVERSION=$(echo $VERSION | tr '-' ' ' | awk '{print $1}') local SVERSION=$(echo $VERSION | tr '-' ' ' | awk '{print $1}')
cd $GIT_REPOS/$PACKAGE cd $GIT_REPOS/$PACKAGE
# Tweak the changelog temporarily # Tweak the changelog temporarily
echo "> Setting version in changelog to ${VERSION}" info "Setting version in changelog to ${VERSION}"
rm -f debian/changelog.dch rm -f debian/changelog.dch
cp debian/changelog debian/changelog.old cp debian/changelog debian/changelog.old
dch --package "${PACKAGE}" \ dch --package "${PACKAGE}" \
--force-bad-version \ --force-bad-version \
-v "${VERSION}" \ -v "${VERSION}" \
-D "${DEBIAN_BRANCH}" \ -D "${BRANCH}" \
--force-distribution \ --force-distribution \
$BUILD_MESSAGE \ "YunoHost custom build." \
> /dev/null 2>&1 > /dev/null 2>&1
# Create temporary folder # Create temporary folder
TMP_FOLDER=$(mktemp -d) TMP_FOLDER=$(mktemp -d)
# Extract git archive a desired tag # 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 git ls-files | xargs tar -czf archive.tar.gz
cat archive.tar.gz | tar -xz -C $TMP_FOLDER cat archive.tar.gz | tar -xz -C $TMP_FOLDER
# For some reason, these wants archive named # For some reason, these wants archive named
@ -91,15 +103,14 @@ function build()
mv archive.tar.gz $TMP_FOLDER/../${PACKAGE}_${SVERSION}.orig.tar.gz mv archive.tar.gz $TMP_FOLDER/../${PACKAGE}_${SVERSION}.orig.tar.gz
# Build Debian package # Build Debian package
echo "> Starting build ..."
cd $TMP_FOLDER cd $TMP_FOLDER
$BUILD_DEB $DISTRIB $BRANCH . $BUILD_DEB $DISTRIB $BRANCH .
# Restore changelog # Restore changelog
echo "> Restoring previous changelog" info "Restoring previous changelog"
cd $GIT_REPOS/$PACKAGE cd $GIT_REPOS/$PACKAGE
cp debian/changelog.old debian/changelog cp debian/changelog.old debian/changelog
rm debian/changelog.old 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 '~' '-') readonly TAG=$(echo "debian/$VERSION" | tr '~' '-')
source /home/vinaigrette/config/config source /home/vinaigrette/config/config
source /home/vinaigrette/scripts/common.sh
# ##### # # ##### #
# Usage # # Usage #
@ -35,42 +36,17 @@ EOF
function validate_arguments() function validate_arguments()
{ {
[[ $PROJECT =~ ^yunohost|yunohost-admin|moulinette|SSOwat$ ]] || critical "Invalid project $PROJECT"
## Project [[ $BRANCH =~ ^testing|stable|unstable$ ]] || critical "Invalid branch $BRANCH"
if [[ ! $PROJECT =~ ^yunohost|yunohost-admin|moulinette|SSOwat$ ]]; then [[ $DISTRIB =~ ^stretch$ ]]; || critical "Invalid distribution $DISTRIB"
echo "Invalid project $PROJECT" [[ ! -z "$VERSION" ]] || critical "Invalid version $VERSION"
usage [[ "$(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 :|"
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
} }
function checkout_tag() function checkout_tag()
{ {
# Update project's repository # Update project's repository
echo "" boxed "> Updating $GIT_REPOS/$PROJECT repository ... "
echo "> Updating $GIT_REPOS/$PROJECT repository ... "
echo ""
cd $GIT_REPOS/$PROJECT cd $GIT_REPOS/$PROJECT
git fetch --quiet git fetch --quiet
@ -78,31 +54,18 @@ function checkout_tag()
git checkout $DISTRIB-$BRANCH --quiet git checkout $DISTRIB-$BRANCH --quiet
git reset --hard origin/$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) 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 # Get commit for the tag and for HEAD
TAGCOMMIT=$(git rev-parse "$TAG") TAGCOMMIT=$(git rev-parse "$TAG")
HEADCOMMIT=$(git rev-parse "HEAD") HEADCOMMIT=$(git rev-parse "HEAD")
if [[ "$TAGCOMMIT" != "$HEADCOMMIT" ]] [[ "$TAGCOMMIT" == "$HEADCOMMIT" ]] || critical "Tag $TAG is not the HEAD of the branch :/"
then
echo "Tag $TAG is not the HEAD of the branch :/"
exit
fi
} }
function build() function build()
@ -111,15 +74,11 @@ function build()
TMP_FOLDER=$(mktemp -d) TMP_FOLDER=$(mktemp -d)
# Extract git archive a desired tag # Extract git archive a desired tag
echo "" info "Exporting in $TMP_FOLDER ... "
echo "> Exporting in $TMP_FOLDER ... "
echo ""
git archive $TAG --format=tar | tar -x -C $TMP_FOLDER git archive $TAG --format=tar | tar -x -C $TMP_FOLDER
# Build Debian package # Build Debian package
echo "###############################" boxed "Building Debian package ... "
echo "# Building Debian package ... #"
echo "###############################"
cd $TMP_FOLDER cd $TMP_FOLDER
$BUILD_DEB $DISTRIB $BRANCH . $BUILD_DEB $DISTRIB $BRANCH .
} }
@ -127,32 +86,13 @@ function build()
function main() function main()
{ {
# If used asked for help, show usage
if [[ $1 == "-h" ]] || [[ $1 == "--help" ]]; then
usage
exit 0
fi
validate_arguments validate_arguments
if [[ "$(tty)" == "not a tty" ]] boxed "Building $PROJECT $BRANCH release - $VERSION version"
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 "########################################################"
checkout_tag checkout_tag
build build
} }
[[ "$1" =~ ^-h|--help$ ]] && (usage; exit 0) || main
main