vinaigrette/daily-build

117 lines
2.8 KiB
Text
Raw Normal View History

2017-09-18 22:41:39 +02:00
#!/bin/bash
readonly THISSCRIPT=$0
readonly BRANCH_NIGHTLY="unstable"
readonly DISTRIB="stretch"
readonly TIMETAG="$(date +%Y%m%d%H%M)"
readonly PACKAGES="moulinette SSOwat yunohost yunohost-admin"
readonly FORCE="false"
2017-09-18 22:41:39 +02:00
source /home/vinaigrette/config/config
function main()
{
2018-04-26 18:35:52 +02:00
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
2017-09-18 22:41:39 +02:00
for PACKAGE in $PACKAGES;
do
echo "-------------------------------------"
echo "Looking for update in ${PACKAGE} ... "
build_if_needed $PACKAGE
done
echo "-------------------------------------"
}
function build_if_needed()
{
local PACKAGE=$1
cd $GIT_REPOS/$PACKAGE
git fetch origin
# Check if there's a branch named distrib-branch (e.g. stretch-unstable)
# By default, keep just 'branch'
BRANCH_NIGHTLY_GIT="$BRANCH_NIGHTLY"
if git branch --list | tr '*' ' ' | awk '{print $1}' | grep -q "^$DISTRIB-$BRANCH_NIGHTLY$"
then
BRANCH_NIGHTLY_GIT="$DISTRIB-$BRANCH_NIGHTLY"
fi
# If the branch name is an alias to another branch, "resolve" the alias
if grep -q "ref: " .git/refs/heads/$BRANCH_NIGHTLY_GIT
then
BRANCH_NIGHTLY_GIT=$(cat .git/refs/heads/$BRANCH_NIGHTLY_GIT | tr '/' ' ' | awk '{print $4}')
fi
git checkout $BRANCH_NIGHTLY_GIT >/dev/null 2>/dev/null
if [ -z "$(git log ${BRANCH_NIGHTLY_GIT}..origin/${BRANCH_NIGHTLY_GIT})" ]; then
if ! "$FORCE";
then
echo "Sources up-to-date, nothing to build."
return
else
echo "Sources up-to-date but forcing build anyway."
fi
2017-09-18 22:41:39 +02:00
fi
git pull origin $BRANCH_NIGHTLY_GIT >/dev/null
git reset --hard origin/$BRANCH_NIGHTLY_GIT
2017-09-18 22:41:39 +02:00
VERSION=$(dpkg-parsechangelog -S Version 2>/dev/null)
2018-04-28 22:10:51 +02:00
VERSION_NIGHTLY="${VERSION}+${TIMETAG}"
2017-09-18 22:41:39 +02:00
# Tweak the changelog temporarily
echo "> Setting version in changelog to ${VERSION_NIGHTLY}"
rm -f debian/changelog.dch
cp debian/changelog debian/changelog.old
dch --package "${PACKAGE}" \
--force-bad-version \
-v "${VERSION_NIGHTLY}" \
-D "${BRANCH_NIGHTLY}" \
--force-distribution \
"Daily build." \
2017-09-18 22:41:39 +02:00
> /dev/null 2>&1
head -n 10 debian/changelog
# Launch the build using build_deb script
build
# Restore changelog
echo "> Restoring previous changelog"
cd $GIT_REPOS/$PACKAGE
cp debian/changelog.old debian/changelog
rm debian/changelog.old
}
function build()
{
# Create temporary folder
TMP_FOLDER=$(mktemp -d)
# Move files to a tmp folder
echo "> Exporting in $TMP_FOLDER ... "
git ls-files | xargs tar -czf archive.tar.gz
2017-09-18 22:41:39 +02:00
cat archive.tar.gz | tar -xz -C $TMP_FOLDER
rm archive.tar.gz
# Build Debian package
echo "> Starting build ..."
cd $TMP_FOLDER
$BUILD_DEB $DISTRIB $BRANCH_NIGHTLY .
2017-09-18 22:41:39 +02:00
}
main