debian-packages/dendrite/deb.sh
leafee98 ef5f2d5ff3 Fix: change method to get version of dendrite
New tag format like helm-dendrite-0.10.9, now instead of get the latest
commit and get its version, we us `git --sort=version:refname` to sort tags.
2023-01-18 10:07:44 -05:00

106 lines
2.2 KiB
Bash

#!/bin/bash
GIT_URL="https://github.com/matrix-org/dendrite.git"
SCRIPT_PATH=$(dirname $(realpath $0))
REPO_DIR="${SCRIPT_PATH}/repo"
PACK_DIR="${SCRIPT_PATH}/package"
BUILD_DIR="$REPO_DIR/bin"
ROOTFS="${SCRIPT_PATH}/rootfs"
ACTION="initialze"
function err_occur {
echo "Error occurred in $ACTION"
}
trap err_occur ERR
set -o errexit
set -o errtrace
function usage()
{
echo "$0 usage:"
echo " -b the build release number"
}
BUILD_REL=""
while getopts ":b" arg
do
case "$arg" in
b)
BUILD_REL="$OPTARG"
;;
*)
usage
;;
esac
done
function download()
{
ACTION="download"
echo "downloading/update sources..."
if [ ! -d "$REPO_DIR" ]
then
git clone "$GIT_URL" "$REPO_DIR"
else
git -C "$REPO_DIR" fetch --all
fi
LATEST_TAG=$(git -C "$REPO_DIR" tag --sort=-version:refname --list 'v*' | head -n 1)
echo "switching to tag: $LATEST_TAG"
git -C "$REPO_DIR" switch --detach "$LATEST_TAG"
}
function build()
{
ACTION="build"
echo "building the program..."
cd "$REPO_DIR"
bash build.sh
}
function package()
{
ACTION="package"
echo "packaging the binaries..."
rm -rf "$ROOTFS"/*
install -D -t $ROOTFS/usr/local/lib/dendrite $BUILD_DIR/*
install -D -t $ROOTFS/etc/dendrite $REPO_DIR/dendrite-sample.polylith.yaml
install -D -t $ROOTFS/etc/dendrite $REPO_DIR/dendrite-sample.monolith.yaml
export VERSION=$($BUILD_DIR/dendrite-monolith-server --version)
if [ -n "${BUILD_REL}" ]
then
VERSION=$VERSION-brel$BUILD_REL
fi
mkdir -p $ROOTFS/DEBIAN
sed "s/+++VERSION+++/${VERSION}/" > $ROOTFS/DEBIAN/control << EOF
Package: dendrite
Version: +++VERSION+++
Priority: optional
Architecture: all
Maintainer: leafee98 <me@leafee98.com>
Description: Dendrite is a second-generation Matrix homeserver written in Go!
Dendrite is a second-generation Matrix homeserver written in Go. It intends to provide an efficient, reliable and scalable alternative to Synapse.
EOF
mkdir -p "$PACK_DIR"
dpkg-deb --build --root-owner-group $ROOTFS $PACK_DIR/dendrite-$VERSION.deb
}
download
build
package