Add build script for dendrite

This commit is contained in:
leafee98 2022-12-17 02:56:34 -05:00
parent d16b293f1c
commit 59f6e2d64b

105
dendrite/deb.sh Normal file
View file

@ -0,0 +1,105 @@
#!/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" describe --tags $(git -C "$REPO_DIR" rev-list --tags --max-count=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