2017-08-29 17:17:25 +02:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
2017-09-09 17:26:11 +02:00
|
|
|
|
readonly THISSCRIPT=$0
|
|
|
|
|
readonly PROJECT=$1
|
|
|
|
|
readonly BRANCH=$2
|
2019-01-30 19:50:30 +01:00
|
|
|
|
readonly VERSION=$3
|
2018-05-03 03:21:34 +02:00
|
|
|
|
readonly TAG=$(echo "debian/$VERSION" | tr '~' '-')
|
2017-09-09 17:26:11 +02:00
|
|
|
|
|
2024-03-05 22:42:14 +01:00
|
|
|
|
if [[ "$(echo $VERSION | awk -F'.' '{print $1}')" == "11" ]]
|
2022-01-19 23:22:30 +01:00
|
|
|
|
then
|
|
|
|
|
readonly DISTRIB="bullseye"
|
2023-05-04 20:29:29 +02:00
|
|
|
|
elif [[ "$(echo $VERSION | awk -F'.' '{print $1}')" == "12" ]]
|
|
|
|
|
then
|
|
|
|
|
readonly DISTRIB="bookworm"
|
2022-01-19 23:22:30 +01:00
|
|
|
|
else
|
|
|
|
|
readonly DISTRIB="fixyoversionnumberbruh"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
2017-08-30 05:51:28 +02:00
|
|
|
|
source /home/vinaigrette/config/config
|
2018-07-01 00:59:14 +02:00
|
|
|
|
source /home/vinaigrette/scripts/common.sh
|
2017-08-29 17:17:25 +02:00
|
|
|
|
|
|
|
|
|
# ##### #
|
|
|
|
|
# Usage #
|
|
|
|
|
# ##### #
|
|
|
|
|
|
2017-09-09 17:26:11 +02:00
|
|
|
|
function usage()
|
|
|
|
|
{
|
2017-08-31 15:14:12 +02:00
|
|
|
|
cat << EOF
|
2017-09-09 17:26:11 +02:00
|
|
|
|
|
2017-08-29 17:17:25 +02:00
|
|
|
|
Usage:
|
2017-09-09 17:26:11 +02:00
|
|
|
|
$THISSCRIPT <project> <branch> <version>
|
2017-08-29 17:17:25 +02:00
|
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
|
<project> moulinette, yunohost, yunohost-admin or SSOwat
|
|
|
|
|
<branch> testing or stable
|
|
|
|
|
<version> x.y.z (ex: 2.6.1)
|
2017-09-09 17:26:11 +02:00
|
|
|
|
|
2017-08-31 15:14:12 +02:00
|
|
|
|
EOF
|
2017-08-29 17:17:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# ################# #
|
|
|
|
|
# Check user inputs #
|
|
|
|
|
# ################# #
|
|
|
|
|
|
2017-09-09 17:26:11 +02:00
|
|
|
|
function validate_arguments()
|
|
|
|
|
{
|
2018-07-01 00:59:14 +02:00
|
|
|
|
[[ $PROJECT =~ ^yunohost|yunohost-admin|moulinette|SSOwat$ ]] || critical "Invalid project $PROJECT"
|
2022-01-10 02:07:43 +01:00
|
|
|
|
grep -q "^Codename: $DISTRIB$" $REPO_CONFIG || critical "Invalid distribution $DISTRIB"
|
|
|
|
|
grep -q "^Components: .*$BRANCH.*$" $REPO_CONFIG || critical "Invalid branch $BRANCH"
|
2024-03-01 03:13:01 +01:00
|
|
|
|
[[ -n "$VERSION" ]] || critical "Invalid version $VERSION"
|
2018-07-01 00:59:14 +02:00
|
|
|
|
[[ "$(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 :|"
|
2017-09-09 17:26:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function checkout_tag()
|
|
|
|
|
{
|
|
|
|
|
# Update project's repository
|
2018-07-01 00:59:14 +02:00
|
|
|
|
boxed "> Updating $GIT_REPOS/$PROJECT repository ... "
|
2017-09-09 17:26:11 +02:00
|
|
|
|
|
|
|
|
|
cd $GIT_REPOS/$PROJECT
|
|
|
|
|
git fetch --quiet
|
|
|
|
|
git fetch --tags --quiet
|
2020-12-02 00:04:51 +01:00
|
|
|
|
git checkout $TAG --quiet
|
|
|
|
|
git reset --hard $TAG --quiet
|
2017-09-09 17:26:11 +02:00
|
|
|
|
|
2018-07-01 00:59:14 +02:00
|
|
|
|
# Validate constrains for the version number given (is in changelog + has corresponding tag)
|
|
|
|
|
|
2017-09-09 17:26:11 +02:00
|
|
|
|
LASTVERSIONCHANGELOG=$(dpkg-parsechangelog -S Version 2>/dev/null)
|
2018-07-01 00:59:14 +02:00
|
|
|
|
[[ "$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 !)"
|
2017-09-09 17:26:11 +02:00
|
|
|
|
|
|
|
|
|
# Get commit for the tag and for HEAD
|
2018-07-01 00:59:14 +02:00
|
|
|
|
|
2017-09-09 17:26:11 +02:00
|
|
|
|
TAGCOMMIT=$(git rev-parse "$TAG")
|
|
|
|
|
HEADCOMMIT=$(git rev-parse "HEAD")
|
|
|
|
|
|
2018-07-01 00:59:14 +02:00
|
|
|
|
[[ "$TAGCOMMIT" == "$HEADCOMMIT" ]] || critical "Tag $TAG is not the HEAD of the branch :/"
|
2017-09-09 17:26:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function build()
|
|
|
|
|
{
|
2024-03-01 03:23:45 +01:00
|
|
|
|
# check if the build branch type is coherent between what the user has specified and what is specified in the changelog
|
2024-03-01 03:14:42 +01:00
|
|
|
|
if ! [[ "$(head -n 1 debian/changelog)" == *"$BRANCH"* ]]; then
|
2024-03-01 02:08:34 +01:00
|
|
|
|
echo "The specified branch type is not coherent with the changelog one!"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2017-09-09 17:26:11 +02:00
|
|
|
|
# Create temporary folder
|
|
|
|
|
TMP_FOLDER=$(mktemp -d)
|
|
|
|
|
|
|
|
|
|
# Extract git archive a desired tag
|
2018-07-01 00:59:14 +02:00
|
|
|
|
info "Exporting in $TMP_FOLDER ... "
|
2017-09-09 17:26:11 +02:00
|
|
|
|
git archive $TAG --format=tar | tar -x -C $TMP_FOLDER
|
|
|
|
|
|
|
|
|
|
# Build Debian package
|
2018-07-01 00:59:14 +02:00
|
|
|
|
boxed "Building Debian package ... "
|
2017-09-09 17:26:11 +02:00
|
|
|
|
cd $TMP_FOLDER
|
2018-05-03 02:33:47 +02:00
|
|
|
|
$BUILD_DEB $DISTRIB $BRANCH .
|
2017-09-09 17:26:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function main()
|
|
|
|
|
{
|
|
|
|
|
validate_arguments
|
|
|
|
|
|
2018-07-01 00:59:14 +02:00
|
|
|
|
boxed "Building $PROJECT $BRANCH release - $VERSION version"
|
2017-09-09 17:26:11 +02:00
|
|
|
|
|
|
|
|
|
checkout_tag
|
|
|
|
|
build
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-10 10:56:01 +02:00
|
|
|
|
[[ "$1" =~ ^-h|--help$ ]] && usage || main
|
2017-08-29 17:17:25 +02:00
|
|
|
|
|