Skip to content

Commit dc13e85

Browse files
authored
Merge pull request ossec#2193 from atomicturtle/deb-build-01
Update for the debian packaging
2 parents 4e1c1bf + ce121ac commit dc13e85

File tree

19 files changed

+122
-542
lines changed

19 files changed

+122
-542
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,6 @@ src/win32/route-null.cmd
8787

8888
# Local testsuite (not tracked)
8989
testsuite/
90+
91+
# Pbuilder prepared source (generate_ossec.sh -d writes here)
92+
contrib/debian-packages/build/

contrib/debian-packages/Readme.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ ossec-debian
33

44
OSSEC is an Open Source Host-based Intrusion Detection System that performs log analysis, file integrity checking, policy monitoring, rootkit detection, real-time alerting and active response.
55

6-
These are the files used to create OSSEC-HIDS version 2.8 debian packages, the ones included both in ossec.net website and in WAZUH repository. You can find these packages at:
6+
This directory is the single canonical location for Debian/Ubuntu packaging. The former debian_files/ at the repo root (versioned layout) has been retired; all packaging lives here under contrib/debian-packages/ (ossec-hids and ossec-hids-agent). These files are used to create OSSEC-HIDS packages (updated for 4.0.0). You can find these packages at:
77

88
http://www.ossec.net/?page_id=19
99

@@ -19,9 +19,7 @@ Each one of the subdirectories includes:
1919
* Patches
2020
* Debian control files: changelog, compat, control, copyright, lintian-overrides, postinst, postrm, preinst, rules
2121

22-
Additionally a script, ```generate_ossec.sh```, is included to generate the Debian packages for Jessie, Sid and Wheezy Debian distributions, both for i386 and amd64 architectures. This script uses Pbuilder to build the packages, and uploads those to an APT repository, setup with Reprepro.
23-
24-
For more details on how to create Debian Packages and an APT repository you can check my post at:
22+
Build with generate_ossec.sh: -d (prepare source from local tree or download), -u (create/update pbuilder chroots), -b (build). See PBUILDER.md. Config is in pbuilderrc. The script can also upload to a Reprepro repository (-s). For more details on creating Debian packages and an APT repository you can check:
2523

2624
http://santi-bassett.blogspot.com/2014/07/setting-up-apt-repository-with-reprepro.html
2725

contrib/debian-packages/generate_ossec.sh

Lines changed: 99 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,37 @@
2020
# CONFIGURATION VARIABLES
2121
#
2222

23-
ossec_version='3.6.0'
24-
source_file="ossec-hids-${ossec_version}.tar.gz"
23+
NAME="ossec-hids"
24+
ossec_version='4.0.0'
25+
source_file="${NAME}-${ossec_version}.tar.gz"
2526
#packages=(ossec-hids ossec-hids-agent) # only options available
26-
packages=(ossec-hids-agent)
27+
packages=(ossec-hids ossec-hids-agent)
2728

2829
# codenames=(sid jessie wheezy precise trusty utopic)
29-
codenames=(bionic)
30+
codenames=(bookworm)
3031

31-
# For Debian use: sid, jessie or wheezy (hardcoded in update_changelog function)
32-
# For Ubuntu use: lucid, precise, trusty or utopic
33-
codenames_ubuntu=(precise trusty xenial bionic focal)
34-
codenames_debian=(sid jessie wheezy)
32+
# For Debian use: sid, jessie, wheezy, bookworm (hardcoded in update_changelog function)
33+
# For Ubuntu use: xenial, bionic, focal, jammy, noble (24.04)
34+
codenames_ubuntu=(xenial bionic focal jammy noble)
35+
codenames_debian=(sid jessie wheezy bookworm)
3536

3637
# architectures=(amd64 i386) only options available
37-
architectures=(arm64)
38+
architectures=(amd64)
3839

39-
# Debian files
40-
debian_files_path="/home/ubuntu/debian_files"
40+
# Debian files path (set after scriptpath below; use contrib/debian-packages, no version subdir)
41+
debian_files_path=""
4142

42-
# Setting up logfile
43+
# Setting up paths
4344
scriptpath=$( cd $(dirname $0) ; pwd -P )
45+
debian_files_path="${scriptpath}"
46+
repo_root="$(cd "${scriptpath}/../.." && pwd)"
47+
build_root="${scriptpath}/build"
4448
logfile=$scriptpath/ossec_packages.log
4549

50+
# Optional env overrides for one-off tests (e.g. on Fedora: CODENAMES=noble ARCHITECTURES=amd64)
51+
[[ -n "${CODENAMES:-}" ]] && codenames=(${CODENAMES})
52+
[[ -n "${ARCHITECTURES:-}" ]] && architectures=(${ARCHITECTURES})
53+
4654

4755
#
4856
# Function to write to LOG_FILE
@@ -77,7 +85,7 @@ contains_element() {
7785
show_help()
7886
{
7987
echo "
80-
This tool can be used to generate OSSEC packages for Ubuntu and Debian.
88+
This tool builds OSSEC Debian/Ubuntu packages with pbuilder.
8189
8290
CONFIGURATION: The script is currently configured with the following variables:
8391
* Packages: ${packages[*]}.
@@ -151,6 +159,8 @@ update_changelog()
151159
local debdist="testing"
152160
elif [ $codename = "wheezy" ]; then
153161
local debdist="stable"
162+
elif [ $codename = "bookworm" ]; then
163+
local debdist="bookworm"
154164
fi
155165

156166
# For Ubuntu
@@ -196,7 +206,11 @@ update_chroots()
196206
do
197207
for arch in ${architectures[@]}
198208
do
199-
if [ -f /var/cache/pbuilder/$codename-$arrch-base.tgz ]; then
209+
# Ensure pbuilder cache dirs exist (debootstrap fails if aptcache/ is missing)
210+
sudo mkdir -p /var/cache/pbuilder/${codename}-${arch}/aptcache \
211+
/var/cache/pbuilder/${codename}-${arch}/result \
212+
/var/cache/pbuilder/build
213+
if [ -f /var/cache/pbuilder/$codename-$arch-base.tgz ]; then
200214
echo "Updating chroot environment: ${codename}-${arch}" | write_log
201215
if sudo DIST=$codename ARCH=$arch pbuilder update --configfile $scriptpath/pbuilderrc ; then
202216
echo "Successfully updated chroot environment: ${codename}-${arch}" | write_log
@@ -219,57 +233,63 @@ update_chroots()
219233

220234

221235
#
222-
# Downloads packages and prepare source directories.
223-
# This is needed before building the packages.
236+
# Prepare source directories for building. Uses a dedicated build/ dir so we never
237+
# overwrite the packaging dirs (contrib/debian-packages/ossec-hids, ossec-hids-agent).
238+
# Prefer building from the local tree when possible (repo with .git and src/).
224239
#
225240
download_source()
226241
{
227-
cd ${scriptpath}
228-
229-
# Checking that Debian files exist for this version
230-
for package in ${packages[*]}
231-
do
232-
if [ ! -d ${debian_files_path}/${ossec_version}/$package/debian ]; then
233-
echo "Error: Couldn't find debian files directory for $package, version ${ossec_version}" | write_log
242+
# Check that Debian packaging dirs exist (we only read from them)
243+
for package in ${packages[*]}; do
244+
if [ ! -d "${debian_files_path}/$package/debian" ]; then
245+
echo "Error: Couldn't find debian files directory for $package at ${debian_files_path}/$package/debian" | write_log
234246
exit 1
235247
fi
236248
done
237249

238-
# Downloading file
239-
if wget -O $scriptpath/${source_file} -U ossec https://github.com/ossec/ossec-hids/archive/${ossec_version}.tar.gz ; then
240-
echo "Successfully downloaded source file ${source_file} from ossec.net" | write_log
241-
else
242-
echo "Error: File ${source_file} was could not be downloaded" | write_log
243-
exit 1
244-
fi
250+
mkdir -p "${build_root}"
251+
cd "${build_root}"
252+
tmp_directory="${NAME}-${ossec_version}"
245253

246-
# Uncompressing files
247-
tmp_directory=$(echo ${source_file} | sed -e 's/.tar.gz$//')
248-
if [ -d ${scriptpath}/${tmp_directory} ]; then
249-
echo " + Deleting previous directory ${scriptpath}/${tmp_directory}" | write_log
250-
sudo rm -rf ${scriptpath}/${tmp_directory}
251-
fi
252-
tar -xvzf ${scriptpath}/${source_file}
253-
if [ ! -d ${scriptpath}/${tmp_directory} ]; then
254-
echo "Error: Couldn't find uncompressed directory, named ${tmp_directory}" | write_log
255-
exit 1
254+
# Prefer local tree when we have a full repo (src/ present)
255+
if [ -d "${repo_root}/src" ]; then
256+
echo "Building from local source tree at ${repo_root}" | write_log
257+
if [ -f "${build_root}/${source_file}" ]; then
258+
rm -f "${build_root}/${source_file}"
259+
fi
260+
(cd "${repo_root}" && tar -czf "${build_root}/${source_file}" --exclude='.git' --exclude="${source_file}" \
261+
--transform "s,^\./,${tmp_directory}/," .)
262+
else
263+
# Download or use SOURCE_TARBALL
264+
if [ -n "${SOURCE_TARBALL:-}" ] && [ -f "${SOURCE_TARBALL}" ]; then
265+
cp -p "${SOURCE_TARBALL}" "${build_root}/${source_file}"
266+
echo "Using local source tarball ${SOURCE_TARBALL}" | write_log
267+
elif wget -O "${build_root}/${source_file}" -U ossec "https://github.com/ossec/ossec-hids/archive/${ossec_version}.tar.gz"; then
268+
echo "Successfully downloaded ${source_file} from GitHub" | write_log
269+
else
270+
echo "Error: Could not obtain ${source_file}. Set SOURCE_TARBALL or run from a git clone." | write_log
271+
exit 1
272+
fi
256273
fi
257274

258-
# Organizing directories structure
259-
for package in ${packages[*]}
260-
do
261-
if [ -d ${scriptpath}/$package ]; then
262-
echo " + Deleting previous source directory ${scriptpath}/$package" | write_log
263-
sudo rm -rf ${scriptpath}/$package
275+
# Unpack and prepare each package under build/ (never touch scriptpath/package)
276+
for package in ${packages[*]}; do
277+
rm -rf "${build_root}/${package}"
278+
mkdir -p "${build_root}/${package}"
279+
tar -xzf "${build_root}/${source_file}" -C "${build_root}/${package}"
280+
if [ ! -d "${build_root}/${package}/${tmp_directory}" ]; then
281+
echo "Error: Unpack did not create ${build_root}/${package}/${tmp_directory}" | write_log
282+
exit 1
264283
fi
265-
mkdir $scriptpath/$package
266-
cp -pr $scriptpath/${tmp_directory} $scriptpath/$package/$package-${ossec_version}
267-
cp -p $scriptpath/${source_file} $scriptpath/$package/${package}_${ossec_version}.orig.tar.gz
268-
cp -pr ${debian_files_path}/${ossec_version}/$package/debian $scriptpath/$package/${package}-${ossec_version}/debian
284+
target="${build_root}/${package}/${package}-${ossec_version}"
285+
if [ "${build_root}/${package}/${tmp_directory}" != "${target}" ]; then
286+
mv "${build_root}/${package}/${tmp_directory}" "${target}"
287+
fi
288+
cp -p "${build_root}/${source_file}" "${build_root}/${package}/${package}_${ossec_version}.orig.tar.gz"
289+
cp -pr "${debian_files_path}/${package}/debian" "${target}/debian"
269290
done
270-
rm -rf $scriptpath/${tmp_directory}
271291

272-
echo "The packages directories for ${packages[*]} version ${ossec_version} have been successfully prepared." | write_log
292+
echo "Prepared source for ${packages[*]} version ${ossec_version} under ${build_root}" | write_log
273293
}
274294

275295

@@ -288,12 +308,18 @@ do
288308

289309
echo "Building Debian package ${package} ${codename}-${arch}" | write_log
290310

291-
local source_path="$scriptpath/${package}/${package}-${ossec_version}"
292-
local changelog_file="${source_path}/debian/changelog"
293-
if [ ! -f ${changelog_file} ] ; then
294-
echo "Error: Couldn't find changelog file for ${package}-${ossec_version}" | write_log
311+
# Prefer build/ (local or prepared source); fall back to scriptpath/package for backward compat
312+
local source_path=""
313+
if [ -f "${build_root}/${package}/${package}-${ossec_version}/debian/changelog" ]; then
314+
source_path="${build_root}/${package}/${package}-${ossec_version}"
315+
elif [ -f "$scriptpath/${package}/${package}-${ossec_version}/debian/changelog" ]; then
316+
source_path="$scriptpath/${package}/${package}-${ossec_version}"
317+
fi
318+
if [ -z "${source_path}" ] || [ ! -f "${source_path}/debian/changelog" ]; then
319+
echo "Error: Couldn't find changelog for ${package}-${ossec_version}. Run -d first to prepare source." | write_log
295320
exit 1
296321
fi
322+
local changelog_file="${source_path}/debian/changelog"
297323

298324
# Updating changelog file with new codename, date and debdist.
299325
if update_changelog ${changelog_file} ${codename} ; then
@@ -317,13 +343,19 @@ do
317343
sudo mkdir -p ${results_dir}
318344
fi
319345

320-
# Building the package
346+
# Building the package (configfile must be absolute so it works from any cwd)
347+
local build_log="${build_root}/pdebuild-${package}-${codename}-${arch}.log"
321348
cd ${source_path}
322-
if sudo DIST=$codename ARCH=$arch /usr/bin/pdebuild --configfile $scriptpath/pbuilderrc --use-pdebuild-internal --architecture ${arch} --buildresult ${results_dir} -- --basetgz \
323-
${base_tgz} --distribution ${codename} --architecture ${arch} --aptcache ${cache_dir} --override-config ; then
349+
if sudo DIST=$codename ARCH=$arch /usr/bin/pdebuild --configfile "$scriptpath/pbuilderrc" --use-pdebuild-internal --architecture ${arch} --buildresult ${results_dir} -- --basetgz \
350+
${base_tgz} --distribution ${codename} --architecture ${arch} --aptcache ${cache_dir} --override-config >> "${build_log}" 2>&1 ; then
324351
echo " + Successfully built Debian package ${package} ${codename}-${arch}" | write_log
325352
else
326353
echo "Error: Could not build package $package ${codename}-${arch}" | write_log
354+
echo "Last 100 lines of build log (full log: ${build_log}):" | write_log
355+
tail -100 "${build_log}" | while read line; do echo "$line" | write_log; done
356+
echo "---" | write_log
357+
echo "Build failed. Last 100 lines of build output:" 1>&2
358+
tail -100 "${build_log}" 1>&2
327359
exit 1
328360
fi
329361

@@ -343,11 +375,19 @@ do
343375
echo " + Package ${results_dir}/${deb_file} ${codename}-${arch} contains ${files} files" | write_log
344376
fi
345377

378+
# Copy built artifacts into repo for easy access (build/result/<codename>-<arch>/)
379+
local out_dir="${build_root}/result/${codename}-${arch}"
380+
mkdir -p "${out_dir}"
381+
sudo cp -p "${results_dir}/${deb_file}" "${results_dir}/${changes_file}" "${out_dir}/" 2>/dev/null || true
382+
sudo cp -p "${results_dir}"/*.buildinfo "${out_dir}/" 2>/dev/null || true
383+
sudo chown "$(id -un):$(id -gn)" "${out_dir}"/* 2>/dev/null || true
384+
346385
echo "Successfully built Debian package ${package} ${codename}-${arch}" | write_log
347386

348387
done
349388
done
350389
done
390+
echo "Built .deb and .changes are in ${build_root}/result/<codename>-<arch>/ and in /var/cache/pbuilder/<codename>-<arch>/result/<package>/" | write_log
351391
}
352392

353393
# Synchronizes with the external repository, uploading new packages and ubstituting old ones.

contrib/debian-packages/pbuilderrc

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,35 @@
11
#!/bin/bash
2-
# Codenames for Debian suites according to their alias. Update these when
3-
# needed.
2+
# Pbuilder configuration for OSSEC-HIDS. Used by generate_ossec.sh with
3+
# sudo DIST=<codename> ARCH=<arch> pbuilder create|update|... --configfile contrib/debian-packages/pbuilderrc
4+
# Codenames: update when new releases exist.
45
UNSTABLE_CODENAME="sid"
5-
TESTING_CODENAME="bullseye"
6-
STABLE_CODENAME="buster"
6+
TESTING_CODENAME="trixie"
7+
STABLE_CODENAME="bookworm"
78
STABLE_BACKPORTS_SUITE="$STABLE_CODENAME-backports"
89

9-
# List of Debian suites.
10+
# List of Debian suites (codenames and aliases).
1011
DEBIAN_SUITES=($UNSTABLE_CODENAME $TESTING_CODENAME $STABLE_CODENAME
1112
"unstable" "testing" "stable")
1213

13-
# List of Ubuntu suites. Update these when needed.
14-
UBUNTU_SUITES=("eoan" "bionic" "xenial")
14+
# List of Ubuntu suites. LTS: noble (24.04), jammy (22.04), focal (20.04), bionic (18.04).
15+
UBUNTU_SUITES=("noble" "jammy" "focal" "bionic" "xenial")
1516

16-
# Mirrors to use. Update these to your preferred mirror.
17-
DEBIAN_MIRROR="ftp.us.debian.org"
18-
UBUNTU_MIRROR="ftp.ubuntu.com"
17+
# Mirrors. Override via DEBIAN_MIRROR / UBUNTU_MIRROR if needed.
18+
DEBIAN_MIRROR="deb.debian.org"
19+
UBUNTU_MIRROR="archive.ubuntu.com"
1920
UBUNTU_PORTS_MIRROR="ports.ubuntu.com"
2021

21-
# Optionally use the changelog of a package to determine the suite to use if
22-
# none set.
22+
# Optionally use the changelog of a package to determine the suite to use if none set.
2323
if [ -z "${DIST}" ] && [ -r "debian/changelog" ]; then
2424
DIST=$(dpkg-parsechangelog | awk '/^Distribution: / {print $2}')
2525
DIST="${DIST%%-*}"
26-
# Use the unstable suite for certain suite values.
2726
if $(echo "experimental UNRELEASED" | grep -q $DIST); then
2827
DIST="$UNSTABLE_CODENAME"
2928
fi
3029
fi
3130

32-
# Optionally set a default distribution if none is used. Note that you can set
33-
# your own default (i.e. ${DIST:="unstable"}).
34-
: ${DIST:="$(lsb_release --short --codename)"}
31+
: ${DIST:="$(lsb_release --short --codename 2>/dev/null)"}
3532

36-
# Optionally change Debian release states in $DIST to their names.
3733
case "$DIST" in
3834
unstable)
3935
DIST="$UNSTABLE_CODENAME"
@@ -46,8 +42,6 @@ case "$DIST" in
4642
;;
4743
esac
4844

49-
# Optionally set the architecture to the host architecture if none set. Note
50-
# that you can set your own default (i.e. ${ARCH:="i386"}).
5145
: ${ARCH:="$(dpkg --print-architecture)"}
5246

5347
NAME="$DIST"
@@ -56,35 +50,33 @@ if [ -n "${ARCH}" ]; then
5650
DEBOOTSTRAPOPTS=("--arch" "$ARCH" "${DEBOOTSTRAPOPTS[@]}")
5751
fi
5852
BASETGZ="/var/cache/pbuilder/$NAME-base.tgz"
59-
# Optionally, set BASEPATH (and not BASETGZ) if using cowbuilder
60-
# BASEPATH="/var/cache/pbuilder/$NAME/base.cow/"
53+
# For cowbuilder: BASEPATH="/var/cache/pbuilder/$NAME/base.cow/"
6154
DISTRIBUTION="$DIST"
6255
BUILDRESULT="/var/cache/pbuilder/$NAME/result/"
6356
APTCACHE="/var/cache/pbuilder/$NAME/aptcache/"
6457
BUILDPLACE="/var/cache/pbuilder/build/"
6558

6659
if $(echo ${DEBIAN_SUITES[@]} | grep -q $DIST); then
67-
# Debian configuration
6860
MIRRORSITE="http://$DEBIAN_MIRROR/debian/"
6961
COMPONENTS="main contrib non-free"
7062
DEBOOTSTRAPOPTS=("${DEBOOTSTRAPOPTS[@]}" "--keyring=/usr/share/keyrings/debian-archive-keyring.gpg")
71-
7263
elif $(echo ${UBUNTU_SUITES[@]} | grep -q $DIST); then
73-
# Ubuntu configuration
7464
case "$ARCH" in
7565
i386|amd64)
7666
MIRRORSITE="http://$UBUNTU_MIRROR/ubuntu/"
7767
;;
7868
arm64)
7969
MIRRORSITE="http://$UBUNTU_PORTS_MIRROR/ubuntu-ports/"
8070
DEBOOTSTRAP="qemu-debootstrap"
81-
# pbuilder-satisfydepends-aptitude SEGVs on arm64 qemu env.
8271
PBUILDERSATISFYDEPENDSCMD=/usr/lib/pbuilder/pbuilder-satisfydepends-experimental
8372
;;
73+
*)
74+
MIRRORSITE="http://$UBUNTU_MIRROR/ubuntu/"
75+
;;
8476
esac
8577
COMPONENTS="main restricted universe multiverse"
8678
DEBOOTSTRAPOPTS=("${DEBOOTSTRAPOPTS[@]}" "--keyring=/usr/share/keyrings/ubuntu-archive-keyring.gpg")
8779
else
88-
echo "Unknown distribution: $DIST"
80+
echo "Unknown distribution: $DIST (supported: Debian ${DEBIAN_SUITES[*]}, Ubuntu ${UBUNTU_SUITES[*]})"
8981
exit 1
9082
fi

debian_files/3.6.0/ossec-hids-agent/debian/changelog

Lines changed: 0 additions & 18 deletions
This file was deleted.

debian_files/3.6.0/ossec-hids-agent/debian/compat

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)