uzytkownicy i grupy

Andrzej Krzysztofowicz ankry w green.mif.pg.gda.pl
Pią, 13 Sie 2004, 18:08:04 CEST


Kolejna propozycja rozwiazania problemu usuwania userow i grup, z
przykladami zastosowania.
Pierwsze dwa makra (%usertestrm/%grouptestrm) sa przeznaczone do obslugi
sytuacji niestandardowych, np gdy trzeba do userdel podac opcje "-r" lub
oprocz usuniecia usera zrobic cos jeszcze.
Ostatnie dwa makra sa pomyslane jako podstawowe.
Pozwolilem sobie umiescic obsluge zalosci w jednym skrypcie, bo chyba
wydajnosc nie jest tu szczegolnie istotna.
Poziom "rozmownosci", przy ktorym sa wypisywane odp. komunikaty zostal
oczywiscie wziety z sufitu.

Uwagi? Komentarze?
Jutro mnie nie ma, ale w niedziele/poniedzialek moge sie wziac za wdrazanie
tej implementacji...


--- /usr/lib/rpm/macros.old	2004-08-10 18:41:20.000000000 +0200
+++ /usr/lib/rpm/macros	2004-08-13 00:16:42.000000000 +0200
@@ -1586,3 +1586,10 @@
 %xmms_general_plugindir       %(xmms-config --general-plugin-dir)
 
 %_target_base_arch	%(echo %{_target_cpu} | sed 's/i.86/i386/;s/athlon/i386/;s/pentium./i386/;s/amd64/x86_64/')
+
+# user/group checking macros
+%usertestrm	/usr/lib/rpm/user_group user testrm
+%grouptestrm	/usr/lib/rpm/user_group group testrm
+
+%userremove	/usr/lib/rpm/user_group user del
+%groupremove	/usr/lib/rpm/user_group group del
--- /dev/null	2004-07-16 03:07:27.000000000 +0200
+++ /usr/lib/rpm/user_group	2004-08-13 10:35:41.000000000 +0200
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+[ -f /etc/sysconfig/rpm ] && . /etc/sysconfig/rpm
+[ -z "$RPM_SCRIPTVERBOSITY" ] && RPM_SCRIPTVERBOSITY=5
+
+if [ "$1" = user -o "$1" = group ]; then
+	MODE=$1
+else
+	echo ERROR
+	exit 2
+fi
+shift
+
+testrm()
+{
+	[ "$RPM_USERDEL" != yes ] && return 1
+	[ -z "$1" ] && return 2
+	rpm -q --whatprovides "${MODE}($1)" >/dev/null 2>&1
+	# no package Provides it (strange)
+	[ $? -ne 0 ] && return 0
+	# only current package Provides it
+	[ `rpm -q --whatprovides "${MODE}($1)" | wc -l` -lt 2 ] && return 0
+	return 1
+}
+
+if [ "$1" = "testrm" ]; then
+	testrm $2
+	exit $?
+elif [ "$1" = del ]; then
+	if testrm $2; then
+		[ "$RPM_SCRIPTVERBOSITY" -lt 2 ] || echo "Removing $MODE $2"
+		/usr/sbin/${MODE}del $2 || :
+	fi
+else
+	echo ERROR
+	exit 2
+fi
--- /dev/null	2004-07-16 03:07:27.000000000 +0200
+++ /etc/sysconfig/rpm	2004-08-13 00:16:43.000000000 +0200
@@ -0,0 +1,10 @@
+# This file is intended for setting rpm options that cannot be set as macros
+#
+# NOTE:
+#	At this moment only few packages use this features.
+
+# How verbose the .rpm scripts/triggers should be?
+RPM_SCRIPTVERBOSITY=5
+
+# Should unused users be removed at package deinstalation?
+RPM_USERDEL=yes
--- tftp-hpa.spec~	9 Jul 2004 23:59:45 -0000	1.30
+++ tftp-hpa.spec	13 Aug 2004 15:26:49 -0000
@@ -15,6 +15,8 @@
 Patch0:		%{name}-configure.in.patch
 BuildRequires:	automake
 BuildRequires:	readline-devel
+Provides:	group(tftp)
+Provides:	user(tftp)
 Obsoletes:	tftp
 BuildRoot:	%{tmpdir}/%{name}-%{version}-root-%(id -u -n)
 
@@ -149,10 +151,14 @@
 	/etc/rc.d/init.d/rc-inetd reload
 fi
 if [ "$1" = "0" ]; then
-	echo "Removing user tftp."
-	/usr/sbin/userdel tftp
-	echo "Removing group tftp."
-	/usr/sbin/groupdel tftp
+	if %usertestrm tftp; then
+		echo "Removing user tftp."
+		/usr/sbin/userdel tftp
+	fi
+	if %grouptestrm tftp; then
+		echo "Removing group tftp."
+		/usr/sbin/groupdel tftp
+	fi
 fi
 
 %files
--- postfix.spec~	23 Jul 2004 20:33:26 -0000	1.214
+++ postfix.spec	13 Aug 2004 15:31:48 -0000
@@ -72,6 +72,9 @@
 Requires:	findutils
 %{?with_cdb:Requires:tinycdb}
 Provides:	smtpdaemon
+Provides:	group(maildrop)
+Provides:	group(postfix)
+Provides:	user(postfix)
 Obsoletes:	courier
 Obsoletes:	exim
 Obsoletes:	masqmail
@@ -337,9 +340,9 @@
 %postun
 /sbin/ldconfig
 if [ "$1" = "0" ]; then
-	/usr/sbin/groupdel maildrop 2> /dev/null
-	/usr/sbin/userdel postfix 2> /dev/null
-	/usr/sbin/groupdel postfix 2> /dev/null
+	%groupremove maildrop
+	%userremove postfix
+	%groupremove postfix
 fi
 
 %triggerpostun -- postfix < 1:1.1.2

-- 
=======================================================================
  Andrzej M. Krzysztofowicz               ankry w mif.pg.gda.pl
  phone (48)(58) 347 14 61
Faculty of Applied Phys. & Math.,   Gdansk University of Technology




Więcej informacji o liście dyskusyjnej pld-devel-pl