mirror of
				https://gitea.osmocom.org/cellular-infrastructure/osmo-upf.git
				synced 2025-11-03 21:43:34 +00:00 
			
		
		
		
	.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: I6caa561eff63d6ee58b5c7b0f8c69bfd2d134eb3
This commit is contained in:
		@@ -58,19 +58,32 @@ make %{?_smp_mflags}
 | 
				
			|||||||
%install
 | 
					%install
 | 
				
			||||||
%make_install
 | 
					%make_install
 | 
				
			||||||
 | 
					
 | 
				
			||||||
%if 0%{?suse_version}
 | 
					 | 
				
			||||||
%preun
 | 
					%preun
 | 
				
			||||||
 | 
					%if 0%{?suse_version}
 | 
				
			||||||
%service_del_preun %{name}.service
 | 
					%service_del_preun %{name}.service
 | 
				
			||||||
 | 
					%endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
%postun
 | 
					%postun
 | 
				
			||||||
 | 
					%if 0%{?suse_version}
 | 
				
			||||||
%service_del_postun %{name}.service
 | 
					%service_del_postun %{name}.service
 | 
				
			||||||
 | 
					%endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
%pre
 | 
					%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
 | 
					%service_add_pre %{name}.service
 | 
				
			||||||
 | 
					%endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
%post
 | 
					%post
 | 
				
			||||||
 | 
					%if 0%{?suse_version}
 | 
				
			||||||
%service_add_post %{name}.service
 | 
					%service_add_post %{name}.service
 | 
				
			||||||
%endif
 | 
					%endif
 | 
				
			||||||
 | 
					chown osmocom:osmocom /etc/osmocom/osmo-upf.cfg
 | 
				
			||||||
 | 
					chmod 0660 /etc/osmocom/osmo-upf.cfg
 | 
				
			||||||
 | 
					chown root:osmocom /etc/osmocom
 | 
				
			||||||
 | 
					chmod 2775 /etc/osmocom
 | 
				
			||||||
 | 
					
 | 
				
			||||||
%check
 | 
					%check
 | 
				
			||||||
make %{?_smp_mflags} check || (find . -name testsuite.log -exec cat {} +)
 | 
					make %{?_smp_mflags} check || (find . -name testsuite.log -exec cat {} +)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,6 +8,8 @@ Type=simple
 | 
				
			|||||||
StateDirectory=osmocom
 | 
					StateDirectory=osmocom
 | 
				
			||||||
WorkingDirectory=%S/osmocom
 | 
					WorkingDirectory=%S/osmocom
 | 
				
			||||||
Restart=always
 | 
					Restart=always
 | 
				
			||||||
 | 
					User=osmocom
 | 
				
			||||||
 | 
					Group=osmocom
 | 
				
			||||||
ExecStart=/usr/bin/osmo-upf -c /etc/osmocom/osmo-upf.cfg
 | 
					ExecStart=/usr/bin/osmo-upf -c /etc/osmocom/osmo-upf.cfg
 | 
				
			||||||
RestartSec=2
 | 
					RestartSec=2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										2
									
								
								debian/control
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								debian/control
									
									
									
									
										vendored
									
									
								
							@@ -25,7 +25,7 @@ Homepage: https://projects.osmocom.org/projects/osmo-upf
 | 
				
			|||||||
Package: osmo-upf
 | 
					Package: osmo-upf
 | 
				
			||||||
Architecture: any
 | 
					Architecture: any
 | 
				
			||||||
Multi-Arch: foreign
 | 
					Multi-Arch: foreign
 | 
				
			||||||
Depends: ${misc:Depends}, ${shlibs:Depends}
 | 
					Depends: ${misc:Depends}, ${shlibs:Depends}, adduser
 | 
				
			||||||
Description: OsmoUPF: Osmocom User Plane Function
 | 
					Description: OsmoUPF: Osmocom User Plane Function
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Package: osmo-upf-dbg
 | 
					Package: osmo-upf-dbg
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										39
									
								
								debian/postinst
									
									
									
									
										vendored
									
									
										Executable file
									
								
							
							
						
						
									
										39
									
								
								debian/postinst
									
									
									
									
										vendored
									
									
										Executable file
									
								
							@@ -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-upf.cfg
 | 
				
			||||||
 | 
					    chperms root osmocom 2775 /etc/osmocom
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  ;;
 | 
				
			||||||
 | 
					esac
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# dh_installdeb(1) will replace this with shell code automatically
 | 
				
			||||||
 | 
					# generated by other debhelper scripts.
 | 
				
			||||||
 | 
					#DEBHELPER#
 | 
				
			||||||
		Reference in New Issue
	
	Block a user