osmith has submitted this change. ( https://gerrit.osmocom.org/c/osmo-smlc/+/29720?usp=email )
Change subject: .deb/.rpm: add osmocom user during package install ......................................................................
.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 osmith@sysmocom.de Change-Id: I459ac6b80526afa0f5d47a8b56f40d5f636dbe28 --- M contrib/osmo-smlc.spec.in M contrib/systemd/osmo-smlc.service M debian/control A debian/postinst 4 files changed, 70 insertions(+), 2 deletions(-)
Approvals: osmith: Looks good to me, approved laforge: Looks good to me, but someone else must approve pespin: Looks good to me, but someone else must approve Jenkins Builder: Verified
diff --git a/contrib/osmo-smlc.spec.in b/contrib/osmo-smlc.spec.in index c1821db..6a6dc4b 100644 --- a/contrib/osmo-smlc.spec.in +++ b/contrib/osmo-smlc.spec.in @@ -58,19 +58,32 @@ %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-smlc.cfg +chmod 0660 /etc/osmocom/osmo-smlc.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-smlc.service b/contrib/systemd/osmo-smlc.service index 65e552f..f5dd44a 100644 --- a/contrib/systemd/osmo-smlc.service +++ b/contrib/systemd/osmo-smlc.service @@ -8,6 +8,8 @@ Restart=always StateDirectory=osmocom WorkingDirectory=%S/osmocom +User=osmocom +Group=osmocom ExecStart=/usr/bin/osmo-smlc -c /etc/osmocom/osmo-smlc.cfg RestartSec=2
diff --git a/debian/control b/debian/control index 242a797..bdfe6e9 100644 --- a/debian/control +++ b/debian/control @@ -23,7 +23,7 @@ Package: osmo-smlc Architecture: any Multi-Arch: foreign -Depends: ${misc:Depends}, ${shlibs:Depends}, libdbd-sqlite3 +Depends: ${misc:Depends}, ${shlibs:Depends}, libdbd-sqlite3, adduser Description: OsmoSMLC: Osmocom's Location Services Center FIXME . diff --git a/debian/postinst b/debian/postinst new file mode 100755 index 0000000..ae5fcb4 --- /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 <user> <group> <perms> <file> + 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-smlc.cfg + chperms root osmocom 2775 /etc/osmocom + + ;; +esac + +# dh_installdeb(1) will replace this with shell code automatically +# generated by other debhelper scripts. +#DEBHELPER#