-
Notifications
You must be signed in to change notification settings - Fork 2
/
ynh-build
executable file
·119 lines (91 loc) · 3.23 KB
/
ynh-build
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/bash
# shellcheck disable=SC2155
readonly THISSCRIPT=$0
readonly THISDIR=$(dirname "$0")
readonly PROJECT=$1
readonly BRANCH=$2
readonly VERSION=$3
readonly TAG=$(echo "debian/$VERSION" | tr '~' '-')
if [[ "$(echo "$VERSION" | awk -F'.' '{print $1}')" == "11" ]]; then
readonly DISTRIB="bullseye"
elif [[ "$(echo "$VERSION" | awk -F'.' '{print $1}')" == "12" ]]; then
readonly DISTRIB="bookworm"
elif [[ "$(echo "$VERSION" | awk -F'.' '{print $1}')" == "13" ]]; then
readonly DISTRIB="trixie"
else
readonly DISTRIB="fixyoversionnumberbruh"
fi
source "$THISDIR/config/config"
source "$THISDIR/scripts/common.sh"
# ##### #
# Usage #
# ##### #
function usage()
{
cat << EOF
Usage:
$THISSCRIPT <project> <branch> <version>
Arguments:
<project> moulinette, yunohost, yunohost-admin, yunohost-portal 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|yunohost-portal|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" || exit 1
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 specified 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" || exit 1
$BUILD_DEB $DISTRIB "$BRANCH" .
}
function main()
{
validate_arguments
boxed "Building $PROJECT $BRANCH release - $VERSION version"
checkout_tag
build
}
if [[ "$1" =~ ^-h|--help$ ]]; then
usage
exit
fi
main