mirror of
https://github.com/YunoHost/vinaigrette.git
synced 2024-09-03 20:06:11 +02:00
116 lines
3.1 KiB
Bash
Executable file
116 lines
3.1 KiB
Bash
Executable file
#!/bin/bash
|
||
|
||
readonly THISSCRIPT=$0
|
||
readonly PROJECT=$1
|
||
readonly BRANCH=$2
|
||
readonly VERSION=$3
|
||
readonly TAG=$(echo "debian/$VERSION" | tr '~' '-')
|
||
|
||
if [[ "$(echo $VERSION | awk -F'.' '{print $1}')" == "4" ]]
|
||
then
|
||
readonly DISTRIB="buster"
|
||
elif [[ "$(echo $VERSION | awk -F'.' '{print $1}')" == "11" ]]
|
||
then
|
||
readonly DISTRIB="bullseye"
|
||
elif [[ "$(echo $VERSION | awk -F'.' '{print $1}')" == "12" ]]
|
||
then
|
||
readonly DISTRIB="bookworm"
|
||
else
|
||
readonly DISTRIB="fixyoversionnumberbruh"
|
||
fi
|
||
|
||
|
||
source /home/vinaigrette/config/config
|
||
source /home/vinaigrette/scripts/common.sh
|
||
|
||
# ##### #
|
||
# Usage #
|
||
# ##### #
|
||
|
||
function usage()
|
||
{
|
||
cat << EOF
|
||
|
||
Usage:
|
||
$THISSCRIPT <project> <branch> <version>
|
||
|
||
Arguments:
|
||
<project> moulinette, yunohost, yunohost-admin or SSOwat
|
||
<branch> testing or stable
|
||
<version> x.y.z (ex: 2.6.1)
|
||
|
||
EOF
|
||
}
|
||
|
||
# ################# #
|
||
# Check user inputs #
|
||
# ################# #
|
||
|
||
function validate_arguments()
|
||
{
|
||
[[ $PROJECT =~ ^yunohost|yunohost-admin|moulinette|SSOwat$ ]] || critical "Invalid project $PROJECT"
|
||
grep -q "^Codename: $DISTRIB$" $REPO_CONFIG || critical "Invalid distribution $DISTRIB"
|
||
grep -q "^Components: .*$BRANCH.*$" $REPO_CONFIG || critical "Invalid branch $BRANCH"
|
||
[[ -n "$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
|
||
boxed "> Updating $GIT_REPOS/$PROJECT repository ... "
|
||
|
||
cd $GIT_REPOS/$PROJECT
|
||
git fetch --quiet
|
||
git fetch --tags --quiet
|
||
git checkout $TAG --quiet
|
||
git reset --hard $TAG --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 !)"
|
||
|
||
# Get commit for the tag and for HEAD
|
||
|
||
TAGCOMMIT=$(git rev-parse "$TAG")
|
||
HEADCOMMIT=$(git rev-parse "HEAD")
|
||
|
||
[[ "$TAGCOMMIT" == "$HEADCOMMIT" ]] || critical "Tag $TAG is not the HEAD of the branch :/"
|
||
}
|
||
|
||
function build()
|
||
{
|
||
# check if the build branch type is coherent between what the user has specified and what is entered in the changelog
|
||
if ! [[ "$(head -n 1 debian/changelog)" == *"$BRANCH"* ]]; then
|
||
echo "The specified branch type is not coherent with the changelog one!"
|
||
exit 1
|
||
fi
|
||
|
||
# Create temporary folder
|
||
TMP_FOLDER=$(mktemp -d)
|
||
|
||
# Extract git archive a desired tag
|
||
info "Exporting in $TMP_FOLDER ... "
|
||
git archive $TAG --format=tar | tar -x -C $TMP_FOLDER
|
||
|
||
# Build Debian package
|
||
boxed "Building Debian package ... "
|
||
cd $TMP_FOLDER
|
||
$BUILD_DEB $DISTRIB $BRANCH .
|
||
}
|
||
|
||
|
||
function main()
|
||
{
|
||
validate_arguments
|
||
|
||
boxed "Building $PROJECT $BRANCH release - $VERSION version"
|
||
|
||
checkout_tag
|
||
build
|
||
}
|
||
|
||
[[ "$1" =~ ^-h|--help$ ]] && usage || main
|
||
|