forgejo_runner_debian_packager/build.sh
2024-03-10 19:11:53 +01:00

119 lines
3.4 KiB
Bash
Executable file

#!/bin/bash
DEBUG=0
INSTALL_DEPS=0
QUIET_ARG=""
function usage() {
[ -n "$@" ] && echo -e "$@\n" > /dev/stderr
echo "Usage: $0 [-x] [-I]"
echo " -I/--install-deps Install build dependencies"
echo " -q/--quiet Enable quiet mode"
echo " -x/--debug Enable debug mode"
[ -n "$@" ] && exit 1
}
idx=1
while [ $idx -le $# ]
do
OPT=${!idx}
case $OPT in
-I|--install-deps)
INSTALL_DEPS=1
;;
-q|--quiet)
QUIET_ARG="--quiet"
;;
-x|--debug)
set -x
DEBUG=1
;;
*)
usage "Unkown parameter '$OPT'"
esac
let idx=idx+1
done
# Enter source directory
cd $( dirname $0 )
# Install build dependencies
if [ $INSTALL_DEPS -eq 1 ]
then
echo "Install build dependencies..."
apt-get update
apt-get install --no-install-recommends --yes \
$(grep Build-Depends debian/control|sed 's/Build-Depends: //'|sed 's/([^)]\+)//'|tr -d ',')
fi
echo "Clean previous build..."
rm -fr dist
echo "Detect version using git describe..."
[ $DEBUG -eq 1 ] && git show
VERSION="$( git describe --tags|sed 's/^[^0-9]*//' )-0"
echo "Create building environment..."
BDIR=dist/forgejo-runner-$VERSION
mkdir -p $BDIR
[ -z "$QUIET_ARG" ] && RSYNC_ARG="-v" || RSYNC_ARG=""
rsync -a $RSYNC_ARG debian/ $BDIR/debian/
echo "Download forgejo-runner binary..."
[ -n "$QUIET_ARG" ] && CURL_ARG="--silent" || CURL_ARG=""
curl $CURL_ARG --location -o $BDIR/forgejo-runner \
https://code.forgejo.org/forgejo/runner/releases/download/v$VERSION/forgejo-runner-$VERSION-linux-amd64
echo "Generate forgejo-runner configuration example file..."
chmod 755 $BDIR/forgejo-runner
$BDIR/forgejo-runner generate-config > $BDIR/config.yml
echo "Adjust forgejo configuration file..."
sed -i 's#^\( *file:\).*#\1 /etc/forgejo-runner/.runner#' $BDIR/config.yml
sed -i 's#^\( *dir:\).*#\1 /var/cache/forgejo-runner#' $BDIR/config.yml
sed -i 's|^\( *\)envs:.*|\1# envs:|' $BDIR/config.yml
sed -i 's|^\( *\)\( A_TEST_ENV.*\)|\1# \2|' $BDIR/config.yml
if [ -z "$DEBIAN_CODENAME" ]
then
echo "Retreive debian codename using lsb_release..."
DEBIAN_CODENAME=$( lsb_release -c -s )
else
echo "Use debian codename from environment ($DEBIAN_CODENAME)"
fi
echo "Generate debian changelog using gitdch..."
GITDCH_ARGS=('--verbose')
[ -n "$QUIET_ARG" ] && GITDCH_ARGS=('--warning')
if [ -n "$MAINTAINER_NAME" ]
then
echo "Use maintainer name from environment ($MAINTAINER_NAME)"
GITDCH_ARGS+=("--maintainer-name" "${MAINTAINER_NAME}")
fi
if [ -n "$MAINTAINER_EMAIL" ]
then
echo "Use maintainer email from environment ($MAINTAINER_EMAIL)"
GITDCH_ARGS+=("--maintainer-email" "$MAINTAINER_EMAIL")
fi
gitdch \
--package-name forgejo-runner \
--version "${VERSION}" \
--code-name $DEBIAN_CODENAME \
--output $BDIR/debian/changelog \
--release-notes dist/release_notes.md \
"${GITDCH_ARGS[@]}"
BUILD_ARGS=""
if [ -n "$MAINTAINER_NAME" -a -n "$MAINTAINER_EMAIL" ]
then
echo "Set Maintainer field in debian control file ($MAINTAINER_NAME <$MAINTAINER_EMAIL>)..."
sed -i "s/^Maintainer: .*$/Maintainer: $MAINTAINER_NAME <$MAINTAINER_EMAIL>/" $BDIR/debian/control
else
echo "Maintainer email not found in environment, disable signing."
BUILD_ARGS="--no-sign"
fi
echo "Build debian package..."
cd $BDIR
dpkg-buildpackage $BUILD_ARGS