Merge pull request #2749 from signalwire/scripts

[Scripts] Introduce FSDEB - a simple way to build FreeSWITCH packages for Debian.
This commit is contained in:
Andrey Volk 2025-01-27 14:05:48 +03:00 committed by GitHub
commit 75566bc270
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 174 additions and 0 deletions

View File

@ -48,6 +48,10 @@ Step by step tutorials to build FreeSWITCH with provided dependency packages:
* [Raspberry Pi](https://freeswitch.org/confluence/display/FREESWITCH/Raspberry+Pi)
* [CentOS 7](https://freeswitch.org/confluence/display/FREESWITCH/CentOS+7+and+RHEL+7)
### How to build Debian packages
* [Using FSDEB](/scripts/packaging/build)
## Downloads
* [Tarballs](https://files.freeswitch.org/releases/freeswitch/)

View File

@ -0,0 +1,53 @@
# Building FreeSWITCH packages using `FSDEB`
## Prerequisites
FreeSWITCH packages can be built when FreeSWITCH is cloned using `git` only.
(Methods described here won't work if you download a source tarball and extract it)
Please make sure you have `git` and `curl` installed:
```bash
apt-get update
apt-get install -y git curl
```
## Cloning FreeSWITCH
Assuming you build Debian packages for a FreeSWITCH release (this can be your fork or another branch as well).
```bash
cd /usr/src
git clone https://github.com/signalwire/freeswitch -b v1.10
```
## Configuring FreeSWITCH Debian repo (for dependencies)
Since we are building a FreeSWITCH release let's configure FreeSWITCH Community Release Debian repo.
We recommend using [FSGET](/scripts/packaging).
Replace `<PAT or API token>` with your `SignalWire Personal Access Token (PAT)`
[HOWTO Create a SignalWire Personal Access Token](https://developer.signalwire.com/freeswitch/FreeSWITCH-Explained/Installation/how-to-create-a-personal-access-token/how-to-create-a-personal-access-token)
```bash
curl -sSL https://freeswitch.org/fsget | bash -s <PAT or API token>
```
## Building packages with `FSDEB`
```bash
curl -sSL https://freeswitch.org/fsdeb | bash -s -- -b 999 -o /usr/src/fsdebs/ -w /usr/src/freeswitch
```
That's pretty much it!
## Output
`FSDEB` will generate `.deb`, `.dsc`, `.changes`, and `.tar.*` files in the output directory:
```bash
ls -la /usr/src/fsdebs/
```
## Usage
You may be interested in other arguments of `FSDEB`:
```bash
curl -sSL https://freeswitch.org/fsdeb | bash -s -- -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)

117
scripts/packaging/build/fsdeb.sh Executable file
View File

@ -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 "$@"