From e3dd323579d614c6fa4bbc28d6bd14bfbe4e2cf7 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 12 Oct 2022 18:22:46 +0300 Subject: .deb/.rpm: add osmocom user during package install Create osmocom user & group during package installation. Fix the configuration dir/files permission to match. Related: OS#4107 Tweaked-By: Oliver Smith Change-Id: I7826fedb1b055a282954e5774615245092ddae5d --- contrib/osmo-sip-connector.spec.in | 15 +++++++++++- contrib/systemd/osmo-sip-connector.service | 2 ++ debian/control | 2 +- debian/postinst | 39 ++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 2 deletions(-) create mode 100755 debian/postinst diff --git a/contrib/osmo-sip-connector.spec.in b/contrib/osmo-sip-connector.spec.in index 3548e28..6b65800 100644 --- a/contrib/osmo-sip-connector.spec.in +++ b/contrib/osmo-sip-connector.spec.in @@ -50,19 +50,32 @@ make %{?_smp_mflags} %install %make_install -%if 0%{?suse_version} %preun +%if 0%{?suse_version} %service_del_preun %{name}.service +%endif %postun +%if 0%{?suse_version} %service_del_postun %{name}.service +%endif %pre +getent group osmocom >/dev/null || groupadd --system osmocom +getent passwd osmocom >/dev/null || useradd --system --gid osmocom --home-dir /var/lib/osmocom \ + --shell /sbin/nologin --comment "Open Source Mobile Communications" osmocom +%if 0%{?suse_version} %service_add_pre %{name}.service +%endif %post +%if 0%{?suse_version} %service_add_post %{name}.service %endif +chown osmocom:osmocom /etc/osmocom/osmo-sip-connector.cfg +chmod 0660 /etc/osmocom/osmo-sip-connector.cfg +chown root:osmocom /etc/osmocom +chmod 2775 /etc/osmocom %check make %{?_smp_mflags} check || (find . -name testsuite.log -exec cat {} +) diff --git a/contrib/systemd/osmo-sip-connector.service b/contrib/systemd/osmo-sip-connector.service index 27688af..69e628e 100644 --- a/contrib/systemd/osmo-sip-connector.service +++ b/contrib/systemd/osmo-sip-connector.service @@ -8,6 +8,8 @@ Type=simple Restart=always StateDirectory=osmocom WorkingDirectory=%S/osmocom +User=osmocom +Group=osmocom ExecStart=/usr/bin/osmo-sip-connector -c /etc/osmocom/osmo-sip-connector.cfg RestartSec=2 diff --git a/debian/control b/debian/control index 4c7e4b0..b1a7580 100644 --- a/debian/control +++ b/debian/control @@ -17,7 +17,7 @@ Vcs-Browser: https://gitea.osmocom.org/cellular-infrastructure/osmo-sip-connecto Package: osmo-sip-connector Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends} +Depends: ${shlibs:Depends}, ${misc:Depends}, adduser Description: MNCC to SIP bridge for osmo-nitb Use the osmo-nitb MNCC interface and bridge it to SIP. diff --git a/debian/postinst b/debian/postinst new file mode 100755 index 0000000..83be547 --- /dev/null +++ b/debian/postinst @@ -0,0 +1,39 @@ +#!/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 + if ! OVERRIDE=`dpkg-statoverride --list $4 2>&1`; then + if [ -e $4 ]; then + chown $1:$2 $4 + chmod $3 $4 + fi + fi +} + +case "$1" in + configure) + 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" \ + osmocom + fi +# Set permissions according to https://www.debian.org/doc/debian-policy/ch-files.html#s-permissions-owners + chperms osmocom osmocom 0660 /etc/osmocom/osmo-sip-connector.cfg + chperms root osmocom 2775 /etc/osmocom + + ;; +esac + +# dh_installdeb(1) will replace this with shell code automatically +# generated by other debhelper scripts. +#DEBHELPER# -- cgit v1.2.3