Skip to content

Commit 8eeaf0b

Browse files
committed
deb: make helper scripts fail safely
The post-install script could report success after an account or ownership operation failed, and the package build helper selected broad archive and source-tree globs that could consume stale artifacts. Enable immediate post-install failure propagation and derive the exact package version, archive, and staging tree from configure.ac. The build helper now recreates only that version's generated inputs instead of selecting arbitrary glob matches.
1 parent ff2b73b commit 8eeaf0b

2 files changed

Lines changed: 42 additions & 14 deletions

File tree

deb/build_deb.sh

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,56 @@
11
#! /bin/bash
22

3-
set -e
3+
set -euo pipefail
4+
5+
script_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
6+
top_dir=$(cd -- "${script_dir}/.." && pwd)
7+
version=$(sed -n 's/^AC_INIT(\[fapolicyd\],\[\([^]]*\)\].*/\1/p' \
8+
"${top_dir}/configure.ac")
9+
if [ "${version}" = "" ] ; then
10+
echo "Unable to determine fapolicyd version" >&2
11+
exit 1
12+
fi
13+
14+
dist_dir="fapolicyd-${version}"
15+
source_archive="${top_dir}/${dist_dir}.tar.gz"
16+
build_archive="${script_dir}/${dist_dir}.tar.gz"
17+
source_dir="${script_dir}/${dist_dir}"
18+
19+
# make dist otherwise reuses an existing archive, which may not match the
20+
# current source tree.
21+
rm -f "${source_archive}"
22+
make -C "${top_dir}" dist
23+
if [ ! -f "${source_archive}" ] ; then
24+
echo "Expected distribution archive ${source_archive} was not created" >&2
25+
exit 1
26+
fi
27+
28+
# Recreate only this version's packaging tree so repeated runs cannot select
29+
# stale archives or unpack over the previous debmake output.
30+
rm -rf "${source_dir}"
31+
cp "${source_archive}" "${build_archive}"
32+
tar -xzf "${build_archive}" -C "${script_dir}"
33+
if [ ! -d "${source_dir}" ] ; then
34+
echo "Expected distribution directory ${source_dir} was not extracted" >&2
35+
exit 1
36+
fi
437

5-
cd .. || exit 1
6-
make dist
7-
cd deb || exit 1
8-
cp ../fapolicyd-*.tar.gz .
9-
10-
tar zxvf fapolicyd-*.tar.gz
1138

1239
(
13-
cd fapolicyd-*/ || exit 1
40+
cd "${source_dir}"
1441

1542
# Ugly work around for INSTALL.tmp
1643
# Need to figure out proper fix.
1744
mv INSTALL INSTALL.tmp
1845
)
1946

20-
tar zcvf fapolicyd-*.tar.gz fapolicyd-*/
21-
cd fapolicyd-*/ || exit 1
47+
tar -C "${script_dir}" -czf "${build_archive}" "${dist_dir}"
48+
cd "${source_dir}"
2249

2350
debmake
2451

25-
cp ../rules debian/
26-
cp ../postinst debian/
27-
cp ../README.Debian debian/
52+
cp "${script_dir}/rules" debian/
53+
cp "${script_dir}/postinst" debian/
54+
cp "${script_dir}/README.Debian" debian/
2855

2956
debuild

deb/postinst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#! /bin/sh
22

3+
set -e
4+
35
adduser --system --group fapolicyd
46
mkdir -p /etc/fapolicyd/rules.d
57
mkdir -p /etc/fapolicyd/trust.d
@@ -12,4 +14,3 @@ chown fapolicyd:fapolicyd /var/lib/fapolicyd/
1214
chown root:fapolicyd /run/fapolicyd/
1315
chmod 0770 /run/fapolicyd/
1416

15-

0 commit comments

Comments
 (0)