]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
[UTILS] Add `build-debs-native.sh` script.
authors3rj1k <evasive.gyron@gmail.com>
Fri, 24 Jan 2025 20:44:41 +0000 (21:44 +0100)
committers3rj1k <evasive.gyron@gmail.com>
Sat, 25 Jan 2025 15:46:28 +0000 (16:46 +0100)
scripts/packaging/build/README.md [new file with mode: 0644]
scripts/packaging/build/build-debs-native.sh [new file with mode: 0755]

diff --git a/scripts/packaging/build/README.md b/scripts/packaging/build/README.md
new file mode 100644 (file)
index 0000000..e3a13a9
--- /dev/null
@@ -0,0 +1,37 @@
+# Build Scripts
+
+This directory contains scripts for building FreeSWITCH.
+
+## build-debs-native.sh
+Builds Debian packages for FreeSWITCH from git tree on supported Debian distributions.
+
+### TLDR: Example running from FreeSWITCH git root
+```bash
+scripts/packaging/fsget.sh pat_hFooBar
+scripts/packaging/build/build-debs-native.sh -b 999 -o /tmp/fsdebs/
+```
+
+### Prerequisites
+- Root access is recommended
+- Supported Debian system and architecture
+- FreeSWITCH git repository in the working directory
+- FreeSWITCH Debian repository configured (use `fsget.sh`)
+
+### Features
+- Automated dependency installation
+- FreeSWITCH Debian (source) package creation
+
+### Usage
+```bash
+./build-debs-native.sh -b BUILD_NUMBER -o OUTPUT_DIR [-w WORKING_DIR]
+```
+
+Required:
+- `-b`: Build number (part of package version)
+- `-o`: Output directory for packages
+
+Optional:
+- `-w`: Working directory (defaults to git root, needs to be git tree)
+
+### Output
+Generates `.deb`, `.dsc`, `.changes`, and `.tar.*` files in the output directory.
diff --git a/scripts/packaging/build/build-debs-native.sh b/scripts/packaging/build/build-debs-native.sh
new file mode 100755 (executable)
index 0000000..1aceaaf
--- /dev/null
@@ -0,0 +1,117 @@
+#!/bin/bash
+
+# lint: shfmt -w -s -bn -ci -sr -fn scripts/packaging/build/build-debs-native.sh
+
+set -e          # Exit immediately if a command exits with a non-zero status
+set -u          # Treat unset variables as an error
+set -o pipefail # Return value of a pipeline is the value of the last (rightmost) command to exit with a non-zero status
+
+print_usage()
+{
+       echo "Usage: $0 -b BUILD_NUMBER -o OUTPUT_DIR [-w WORKING_DIR]"
+       exit 1
+}
+
+WORKING_DIR=$(git rev-parse --show-toplevel 2> /dev/null || pwd -P)
+
+while getopts ":b:o:w:" opt; do
+       case ${opt} in
+               b) BUILD_NUMBER=$OPTARG ;;
+               o) OUTPUT_DIR=$OPTARG ;;
+               w) WORKING_DIR=$OPTARG ;;
+               \?) print_usage ;;
+       esac
+done
+
+if [ -z "${BUILD_NUMBER:-}" ] || [ -z "${OUTPUT_DIR:-}" ]; then
+       print_usage
+fi
+
+if [ "$(id -u)" != "0" ]; then
+       echo "Non-root user detected. Execution may fail."
+fi
+
+cd "${WORKING_DIR}" || exit 1
+
+install_deps()
+{
+       apt-get update || echo "WARNING: apt-get update failed"
+       apt-get install -y \
+               apt-transport-https \
+               debhelper \
+               gnupg2 \
+               build-essential \
+               ca-certificates \
+               curl \
+               devscripts \
+               dh-autoreconf \
+               dos2unix \
+               doxygen \
+               lsb-release \
+               pkg-config \
+               wget || echo "WARNING: package installation failed"
+}
+
+export_vars()
+{
+       export CODENAME=$(lsb_release -sc)
+       if ! VERSION=$(cat ./build/next-release.txt | tr -d '\n'); then
+               echo "Failed to read version file" >&2
+               exit 1
+       fi
+       export GIT_SHA=$(git rev-parse --short HEAD)
+}
+
+setup_git_local()
+{
+       if [ -z "$(git config user.email)" ]; then
+               git config user.email "$(id -un)@localhost"
+       fi
+       if [ -z "$(git config user.name)" ]; then
+               git config user.name "$(id -un)"
+       fi
+       git config --add safe.directory '*'
+}
+
+bootstrap_freeswitch()
+{
+       ./debian/util.sh prep-create-orig -n -V${VERSION}-${BUILD_NUMBER}-${GIT_SHA} -x
+       ./debian/util.sh prep-create-dsc ${CODENAME}
+}
+
+install_freeswitch_deps()
+{
+       apt-get update || echo "WARNING: apt-get update failed"
+       mk-build-deps --install --remove debian/control \
+               --tool "apt-get --yes --no-install-recommends" || echo "WARNING: mk-build-deps failed"
+       apt-get --yes --fix-broken install || echo "WARNING: apt-get fix-broken failed"
+}
+
+build_source_package()
+{
+       dch -b -M -v "${VERSION}-${BUILD_NUMBER}-${GIT_SHA}~${CODENAME}" \
+               --force-distribution -D "${CODENAME}" "Nightly build, ${GIT_SHA}"
+
+       ./debian/util.sh create-orig -n -V${VERSION}-${BUILD_NUMBER}-${GIT_SHA} -x
+}
+
+build_and_move()
+{
+       dpkg-source --diff-ignore=.* --compression=xz --compression-level=9 --build . \
+               && debuild -b -us -uc \
+               && mkdir -p "${OUTPUT_DIR}" \
+               && mv -v ../*.{deb,dsc,changes,tar.*} "${OUTPUT_DIR}"/
+}
+
+main()
+{
+       install_deps
+       export_vars
+       setup_git_local
+       bootstrap_freeswitch
+       install_freeswitch_deps
+       build_source_package
+       build_and_move
+}
+
+main "$@"