.deb/.rpm: various fixes related to non-root

* Explicitly chown /var/lib/osmocom to osmocom:osmocom, instead of
  relying on systemd to do it when the service starts up. This does not
  work with the systemd versions in debian 10 and almalinux 8.
* deb: Use "useradd" instead of the interactive "adduser" perl script
  from Debian. This makes it consistent with how we do it in rpm, and
  avoids the dependency on "adduser".
* deb: Consistently use tabs through the file, instead of mixing tabs
  and spaces.
* deb: Remove support for the "dpkg-statoverride --list" logic. This
  seems to be a rather obscure feature to override permissions for
  certain files or directories, for which it does not seem to be a good
  idea to make the postinst script less maintainable. Something similar
  can be achieved by using your own Osmocom config file in a different
  path with different permissions.

Related: OS#4107
Change-Id: I6dd0205fb65d4ad5a79821c111865e67fb293a73
This commit is contained in:
Oliver Smith 2024-04-26 15:08:45 +02:00 committed by osmith
parent da7d33e284
commit ba81785b71
3 changed files with 25 additions and 32 deletions

View File

@ -94,6 +94,8 @@ chown osmocom:osmocom /etc/osmocom/osmo-hnbgw.cfg
chmod 0660 /etc/osmocom/osmo-hnbgw.cfg
chown root:osmocom /etc/osmocom
chmod 2775 /etc/osmocom
mkdir -p /var/lib/osmocom
chown -R osmocom:osmocom /var/lib/osmocom
make %{?_smp_mflags} check || (find . -name testsuite.log -exec cat {} +)

debian/control vendored
View File

@ -31,7 +31,7 @@ Homepage: https://projects.osmocom.org/projects/osmo-hnbgw
Package: osmo-hnbgw
Architecture: any
Multi-Arch: foreign
Depends: ${misc:Depends}, ${shlibs:Depends}, adduser
Depends: ${misc:Depends}, ${shlibs:Depends}
Recommends: osmo-mgw
Description: OsmoHNBGW: Osmocom Home Node B Gateway

debian/postinst vendored
View File

@ -1,37 +1,28 @@
#!/bin/sh -e
# Create 'osmocom' user and group (if it doesn't exist yet) and adjust permissions
# of directories which are not automatically adjusted by systemd from previous (root-owned)
# install.
# N. B: the user is intentionally NOT removed during package uninstall:
# see https://wiki.debian.org/AccountHandlingInMaintainerScripts for reasoning.
chperms() {
# chperms <user> <group> <perms> <file>
if ! OVERRIDE=`dpkg-statoverride --list $4 2>&1`; then
if [ -e $4 ]; then
chown $1:$2 $4
chmod $3 $4
case "$1" in
if ! getent passwd osmocom > /dev/null; then
adduser --quiet \
--system \
--group \
--no-create-home \
--disabled-password \
--home /var/lib/osmocom \
--gecos "Open Source Mobile Communications" \
# Set permissions according to https://www.debian.org/doc/debian-policy/ch-files.html#s-permissions-owners
chperms osmocom osmocom 0660 /etc/osmocom/osmo-hnbgw.cfg
chperms root osmocom 2775 /etc/osmocom
# Create the osmocom group and user (if it doesn't exist yet)
if ! getent group osmocom >/dev/null; then
groupadd --system osmocom
if ! getent passwd osmocom >/dev/null; then
useradd \
--system \
--gid osmocom \
--home-dir /var/lib/osmocom \
--shell /sbin/nologin \
--comment "Open Source Mobile Communications" \
# Fix permissions of previous (root-owned) install (OS#4107)
chown osmocom:osmocom /etc/osmocom/osmo-hnbgw.cfg
chmod 0660 /etc/osmocom/osmo-hnbgw.cfg
chown root:osmocom /etc/osmocom
chmod 2775 /etc/osmocom
mkdir -p /var/lib/osmocom
chown -R osmocom:osmocom /var/lib/osmocom
# dh_installdeb(1) will replace this with shell code automatically