debian-packages/dendrite/deb.sh

123 lines
2.4 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"
TARGET_TAG=""
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"
echo " -t specify the tag to build, instead of the latest one"
}
BUILD_REL=""
while getopts ":b:t:" arg
do
case "$arg" in
b)
BUILD_REL="$OPTARG"
;;
t)
TARGET_TAG="$OPTARG"
;;
*)
usage
exit 1
;;
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
}
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 --force-create build "$TARGET_TAG"
echo "cleaning workspace..."
git -C "$REPO_DIR" clean --force -xd
}
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.yaml
export VERSION=$($BUILD_DIR/dendrite --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
switch_tag
build
package