debian-packages/dendrite/deb.sh

122 lines
2.4 KiB
Bash
Raw Normal View History

2022-12-17 07:56:34 +00:00
#!/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"
2023-01-21 16:17:08 +00:00
TARGET_TAG=""
2022-12-17 07:56:34 +00:00
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"
2023-01-21 16:17:08 +00:00
echo " -t specify the tag to build, instead of the latest one"
2022-12-17 07:56:34 +00:00
}
BUILD_REL=""
2023-01-21 16:17:08 +00:00
while getopts ":b:t:" arg
2022-12-17 07:56:34 +00:00
do
case "$arg" in
b)
BUILD_REL="$OPTARG"
;;
2023-01-21 16:17:08 +00:00
t)
TARGET_TAG="$OPTARG"
;;
2022-12-17 07:56:34 +00:00
*)
usage
2023-01-21 16:17:08 +00:00
exit 1
2022-12-17 07:56:34 +00:00
;;
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
2023-01-21 16:17:08 +00:00
}
function switch_tag()
{
ACTION="switch tag"
if [ -z "$TARGET_TAG" ]
then
TARGET_TAG=$(git -C "$REPO_DIR" tag --sort=-version:refname --list 'v*' | head -n 1)
fi
echo "switching to tag: $TARGET_TAG"
git -C "$REPO_DIR" switch --detach "$TARGET_TAG"
2022-12-17 07:56:34 +00:00
}
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
2023-01-21 16:17:08 +00:00
switch_tag
2022-12-17 07:56:34 +00:00
build
package