Bug 68357 - Maintainer update: net/isc-dhcp3 (startup script rewritten)
Summary: Maintainer update: net/isc-dhcp3 (startup script rewritten)
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-ports-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-06-26 04:20 UTC by Cyrille Lefevre
Modified: 2004-06-30 01:50 UTC (History)
1 user (show)

See Also:


Attachments
file.diff (17.93 KB, patch)
2004-06-26 04:20 UTC, Cyrille Lefevre
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Cyrille Lefevre 2004-06-26 04:20:29 UTC
	new paranoia and jail options handled by rc variables to easy they use.

	Makefile
		PORTREVISION added
		RCSCRIPTS_SUB updated
	pkg-message
		updated
	pkg-plist
		leases files removed
	files/client::scripts::freebsd
		origator restored
	files/isc-dhcpd.sh.sample
		fully rewritten
	files/patch-client::dhclient.8
		origator restored
	pkg-install
		new file

How-To-Repeat: 	n/a
Comment 1 Oliver Eikemeier 2004-06-26 09:34:14 UTC
Cyrille Lefevre wrote:

> 	pkg-install
> 		new file

Try

   make package; make deinstall; pkg_add `make -VPKGFILE`

-Oliver
Comment 2 Cyrille Lefevre 2004-06-26 14:10:29 UTC
On Jun 26, 2004 10:34:14 am +0200, Oliver Eikemeier wrote:
> Cyrille Lefevre wrote:
> 
> > 	pkg-install
> > 		new file
> 
> Try
> 
>    make package; make deinstall; pkg_add `make -VPKGFILE`

was I drunk when I wrote this script ? no, I was tired and I don't
redo for the nth time make install; make deinstall; pkg_add ..., etc.
dhcpd really is isc-dhcpd.sh and I missed a double colon (well, this
is a last time change) in pkg-install !
I also forgot PKGDEINSTALL in Makefile, to relocate PKGINSTALL and
to document dhcpd_umask.
this time, I really do all the make */pkg_* chain w/ success and all
seems to be fine. sorry.

--- Makefile.orig	Sat Jun 26 04:00:17 2004
+++ Makefile	Sat Jun 26 15:03:52 2004
@@ -61,6 +61,8 @@
 
 MSG_FILE=	${.CURDIR}/pkg-message
 DESCR=		${.CURDIR}/pkg-descr
+PKGINSTALL=	${.CURDIR}/pkg-install
+PKGDEINSTALL=	${PKGINSTALL}
 PKGMESSAGE=	${WRKDIR}/pkg-message
 PLIST=		${.CURDIR}/pkg-plist
 
--- pkg-install.orig	Sat Jun 26 14:44:29 2004
+++ pkg-install	Sat Jun 26 14:48:28 2004
@@ -9,10 +9,11 @@
 
 case $2 in
 POST-INSTALL)
-	${PKG_PREFIX}/etc/rc.d/dhcpd forceinstall
+	${PKG_PREFIX}/etc/rc.d/isc-dhcpd.sh forceinstall
 	;;
 DEINSTALL)
-	${PKG_PREFIX}/etc/rc.d/dhcpd forceuninstall
+	${PKG_PREFIX}/etc/rc.d/isc-dhcpd.sh forceuninstall
+	;;
 POST-DEINSTALL|PRE-INSTALL)
 	;;
 *)
--- pkg-message.orig	Sat Jun 26 04:21:28 2004
+++ pkg-message	Sat Jun 26 05:13:23 2004
@@ -8,6 +8,7 @@
 	    dhcpd_flags="-q"				# command option(s)
 	    dhcpd_conf="%%PREFIX%%/etc/dhcpd.conf"	# configuration file
 	    dhcpd_ifaces=""				# ethernet interface(s)
+	    dhcpd_umask="022"				# file creation mask
 
 ****  If compiled with paranoia support (the default), the following lines
       are also supported:

Cyrille Lefevre
-- 
mailto:cyrille.lefevre@laposte.net
Comment 3 Oliver Eikemeier freebsd_committer 2004-06-26 15:32:57 UTC
State Changed
From-To: open->closed

committed, thanks.
Comment 4 Cyrille Lefevre 2004-06-29 20:54:30 UTC
Makefile
	the install script isn't called at make install time !

Index: Makefile
===================================================================
RCS file: /home/ncvs/ports/net/isc-dhcp3-server/Makefile,v
retrieving revision 1.98
diff -u -I$Id.*$ -I$.+BSD.*$ -r1.98 Makefile
--- Makefile	26 Jun 2004 14:32:40 -0000	1.98
+++ Makefile	29 Jun 2004 19:52:45 -0000
@@ -42,6 +42,7 @@
 CONFIGURE_ARGS=	--subsys ${SUBSYS}
 ALL_TARGET=	all.${SUBSYS}
 INSTALL_TARGET=	install.${SUBSYS}
+SCRIPTS_ENV+=	PKG_PREFIX=${PREFIX}
 
 .if ${SUBSYS} == client
 MAN5=		dhclient.conf.5 dhclient.leases.5
@@ -212,7 +213,7 @@
 post-install: strip-binary-files install-startup-files \
 	      install-doc-files install-sample-files \
 	      create-conf-files create-data-files \
-	      display-message
+	      configure-package display-message
 
 strip-binary-files:
 .for f in ${BIN_FILES}
@@ -255,6 +256,9 @@
 	@${TOUCH} ${DATADIR}/${f}
 .endif
 .endfor
+
+configure-package:
+	@${SETENV} ${SCRIPTS_ENV} ${SH} ${PKGINSTALL} ${PKGNAME} POST-INSTALL
 
 display-message:
 .if ${SUBSYS} != devel

Cyrille Lefevre
-- 
mailto:cyrille.lefevre@laposte.net
Comment 5 Oliver Eikemeier 2004-06-29 21:44:21 UTC
Cyrille Lefevre wrote:

> Makefile
> 	the install script isn't called at make install time !
[...]
>  post-install: strip-binary-files install-startup-files \
>  	      install-doc-files install-sample-files \
>  	      create-conf-files create-data-files \
> -	      display-message
> +	      configure-package display-message

Nothing guarantees you that install-startup-files is executed before 
configure-package. If you depend on a certain order, either put the 
steps in one target (preferred, because it is what you are trying to 
express), or use .ORDER

Be aware that using .ORDER might conflict with upcoming hacks in 
bsd.*.mk, like the current gnome hack for pre-patch.

-Oliver
Comment 6 Cyrille Lefevre 2004-06-30 01:37:42 UTC
On Jun 29, 2004 10:44:21 pm +0200, Oliver Eikemeier wrote:
> Cyrille Lefevre wrote:
> > Makefile
> > 	the install script isn't called at make install time !
> [...]
> >  post-install: strip-binary-files install-startup-files \
> >  	      install-doc-files install-sample-files \
> >  	      create-conf-files create-data-files \
> > -	      display-message
> > +	      configure-package display-message
> 
> Nothing guarantees you that install-startup-files is executed before 
> configure-package. If you depend on a certain order, either put the 
> steps in one target (preferred, because it is what you are trying to 
> express), or use .ORDER

so, I have to fix some other ports... :)
for instance, I implement .ORDER

> Be aware that using .ORDER might conflict with upcoming hacks in 
> bsd.*.mk, like the current gnome hack for pre-patch.

do you have any pointers ?

in the meantime, someone identified a problem in the startup script
(lsmod() added), I've also identified some other bugs (those identified
as fixed below) and completed the uninstallation process.

PS : hope I've fixed all the major bugs (and possibly the minor ones :)

Makefile
	configure-package added to post-install
	.ORDER added
files/isc-dhcpd.sh.sample
	some debug() added
	precious() test inverted
	lsmod() added
	safe_chmod() fixed (don't chown .../dev if mounted)
	safe_mkdir() fixed (don't create .../dev if mounted)
	check_chuser() fixed (-z "${var}" instead of -z ${var})
	setup_umask() fixed (dhcpd_umask -> dhcpd_withumask)
	dhcpd_stop() fixed (sh $0 force... instead of $0 ...)
	_dhcpd__uninstall() added
	dhcpd_uninstall() recursively called to handle all the
	combinations of dhcpd_chuser_enable and dhcpd_chroot_enable
	$__dhcpd_uninstall added
	$_dhcpd_piddir and $_dhcpd_leaddir -> $__dhcpd_*

Index: Makefile
===================================================================
RCS file: /home/ncvs/ports/net/isc-dhcp3-server/Makefile,v
retrieving revision 1.98
diff -u -I$Id.*$ -I$.+BSD.*$ -r1.98 Makefile
--- Makefile	26 Jun 2004 14:32:40 -0000	1.98
+++ Makefile	30 Jun 2004 00:16:33 -0000
@@ -42,6 +42,7 @@
 CONFIGURE_ARGS=	--subsys ${SUBSYS}
 ALL_TARGET=	all.${SUBSYS}
 INSTALL_TARGET=	install.${SUBSYS}
+SCRIPTS_ENV+=	PKG_PREFIX=${PREFIX}
 
 .if ${SUBSYS} == client
 MAN5=		dhclient.conf.5 dhclient.leases.5
@@ -209,10 +210,14 @@
 # Post-install
 #
 
-post-install: strip-binary-files install-startup-files \
-	      install-doc-files install-sample-files \
-	      create-conf-files create-data-files \
-	      display-message
+POST-INSTALL= parallel-post-install configure-package display-message
+.ORDER: ${POST-INSTALL}
+post-install: ${POST-INSTALL}
+
+parallel-post-install: \
+	strip-binary-files install-startup-files \
+	install-doc-files install-sample-files \
+	create-conf-files create-data-files
 
 strip-binary-files:
 .for f in ${BIN_FILES}
@@ -255,6 +260,9 @@
 	@${TOUCH} ${DATADIR}/${f}
 .endif
 .endfor
+
+configure-package:
+	@${SETENV} ${SCRIPTS_ENV} ${SH} ${PKGINSTALL} ${PKGNAME} POST-INSTALL
 
 display-message:
 .if ${SUBSYS} != devel
Index: files/isc-dhcpd.sh.sample
===================================================================
RCS file: /home/ncvs/ports/net/isc-dhcp3-server/files/isc-dhcpd.sh.sample,v
retrieving revision 1.6
diff -u -I$Id.*$ -I$.+BSD.*$ -r1.6 isc-dhcpd.sh.sample
--- files/isc-dhcpd.sh.sample	26 Jun 2004 14:32:41 -0000	1.6
+++ files/isc-dhcpd.sh.sample	30 Jun 2004 00:19:48 -0000
@@ -44,7 +44,10 @@
 	shift
 
 	if [ "${_rc}" -eq 0 ]; then
+		debug safe_run: "$@"
 		"$@" || _rc=1
+	else
+		warn safe_run: "$@"
 	fi
 	return ${_rc}
 }
@@ -53,11 +56,30 @@
 {
 	local _entry _rc
 
-	_rc=1
+	_rc=0
 	for _entry; do
 		# do nothing if /var/run or /var/db
-		echo ${_entry} | egrep -q '^//*(var//*(run|db)/*)?$' && _rc=0
+		echo ${_entry} | egrep -q '^//*(var//*(run|db)/*)?$' || _rc=1
 	done
+	debug precious: "$@" rc=${_rc}
+	return ${_rc}
+}
+
+lsmod ()	# user group file...
+{
+	local _entry _user _group _rc
+
+	_user=$1 _group=$2
+	shift 2
+
+	_rc=0
+	for _entry; do
+		ls -ld ${_entry} 2> /dev/null |
+		awk -v u=${_user} -v g=${_group} '{
+		    exit ((u && $3 != u) || (g && $4 != g))
+		}' || _rc=1
+	done
+	debug lsmod: "$@" rc=${_rc}
 	return ${_rc}
 }
 
@@ -72,12 +94,12 @@
 	if [ -n "${_user}" -o -n "${_group}" ]; then
 		_usergroup=${_user}${_group:+:${_group}}
 		for _entry; do
+			if [ -d ${_entry} ] && mounted ${_entry}; then
+				continue
+			fi
 			if [ -e ${_entry} ] &&
 			   ! precious ${_entry} &&
-			   ! ls -ld ${_entry} 2> /dev/null |
-			     awk -v u=${_user} -v g=${_group} '{
-				exit ((u && $3 != u) || (g && $4 != g))
-			     }' &&
+			   ! lsmod ${_user} ${_group} ${_entry} &&
 			   ! safe_run ${_rc} chown ${_usergroup} ${_entry}; then
 				warn "unable to change permissions of ${_entry}"
 				_rc=1
@@ -111,7 +133,8 @@
 	_rc=0
 	for _dir; do
 		if [ -d ${_dir} ] &&
-		   ! precious ${_dir}; then
+		   ! precious ${_dir} &&
+		   ! mounted ${_dir}; then
 			if safe_run ${_rc} rmdir ${_dir}; then
 				safe_run ${_rc} safe_rmdir ${_dir%/*} || _rc=1
 			else
@@ -179,6 +202,7 @@
 	    BEGIN { n = ARGC; ARGC = 2 }
 	    { for (i = 2; i != n; i++) if ($3 == ARGV[i]) exit 1 }
 	' - "$@" || _rc=0
+	debug mounted: "$@" rc=${_rc}
 	return ${_rc}
 }
 
@@ -250,7 +274,7 @@
 {
 	if checkyesno paranoia; then
 		if checkyesno dhcpd_chuser_enable &&
-		   [ -z ${dhcpd_withuser} -a -z ${dhcpd_withgroup} ]; then
+		   [ -z "${dhcpd_withuser}" -a -z "${dhcpd_withgroup}" ]; then
 			err 1 "one of dhcpd_withuser and dhcpd_withgroup" \
 			      "must be set if dhcpd_chuser_enable is enabled"
 		fi
@@ -303,8 +327,8 @@
 rcvar_chuser ()
 {
 	if checkyesno paranoia && checkyesno dhcpd_chuser_enable; then
-		dhcpd_piddir=${_dhcpd_piddir}/${name}
-		dhcpd_leasesdir=${_dhcpd_leasesdir}/${name}
+		dhcpd_piddir=${__dhcpd_piddir}/${name}
+		dhcpd_leasesdir=${__dhcpd_leasesdir}/${name}
 	else
 		dhcpd_withuser= dhcpd_withgroup=
 	fi
@@ -328,8 +352,8 @@
 rcvar_pidnleases ()
 {
 	if ! checkyesno dhcpd_chuser_enable; then
-		dhcpd_piddir=${_dhcpd_piddir}
-		dhcpd_leasesdir=${_dhcpd_leasesdir}
+		dhcpd_piddir=${__dhcpd_piddir}
+		dhcpd_leasesdir=${__dhcpd_leasesdir}
 	fi
 	dhcpd_pidfile=${dhcpd_piddir}/${name}.pid
 	dhcpd_leasesfile=${dhcpd_leasesdir}/${name}.leases
@@ -372,8 +396,8 @@
 
 setup_umask ()
 {
-	if [ -n "${dhcpd_umask}" ]; then
-		umask ${dhcpd_umask}
+	if [ -n "${dhcpd_withumask}" ]; then
+		umask ${dhcpd_withumask}
 	fi
 }
 
@@ -435,8 +459,8 @@
 
 dhcpd_stop ()
 {
-	if $0 status; then
-		$0 stop
+	if sh $0 forcestatus; then
+		sh $0 forcestop
 	fi
 }
 
@@ -515,21 +539,71 @@
 	fi
 }
 
+_dhcpd_uninstall ()	# user group root
+{
+	local _user _group _root
+
+	_user=$1 _group=$2 _root=$3
+
+	if [ -n "${_user}" -o -n "${_group}" ]; then
+		dhcpd_chuser_enable=YES
+		dhcpd_withuser=${_user}
+		dhcpd_withgroup=${_group}
+	else
+		dhcpd_chuser_enable=NO
+	fi
+	if [ -n "${_root}" ]; then
+		dhcpd_chroot_enable=YES
+		dhcpd_rootdir=${_root}
+	else
+		dhcpd_chroot_enable=NO
+	fi
+	dhcpd_check
+	dhcpd_rcvar
+	dhcpd_uninstall
+}
+
 dhcpd_uninstall ()
 {
-	dhcpd_stop
-	remove_pid
-	remove_leases
-	remove_chuser
-	remove_chroot
+	if checkyesno __dhcpd_uninstall; then
+		dhcpd_stop
+		remove_pid
+		remove_leases
+		remove_chuser
+		remove_chroot
+	else
+		local _user _group _root
+
+		__dhcpd_uninstall=YES
+
+		_user=${dhcpd_withuser}
+		_group=${dhcpd_withgroup}
+		_root=${dhcpd_rootdir}
+
+		_dhcpd_uninstall "" "" ""
+
+		if checkyesno paranoia; then
+			if [ -n "${_user}" -o -n "${_group}" ]; then
+				_dhcpd_uninstall "${_user}" "${_group}" ""
+			fi
+			if [ -n "${_root}" ]; then
+				_dhcpd_uninstall "" "" "${_root}"
+			fi
+			if [ -n "${_user}" -o -n "${_group}" ] &&
+			   [ -n "${_root}" ]; then
+				_dhcpd_uninstall "${_user}" "${_group}" "${_root}"
+			fi
+		fi
+	fi
 }
 
 rcvar=$(set_rcvar)
 load_rc_config ${name}
 
-_dhcpd_piddir=/var/run			# pid file directory
-_dhcpd_leasesdir=/var/db			# leases file directory
-#_dhcpd_rootdir=/var/db/${name}		# root directory
+__dhcpd_uninstall="NO"			# internal use only
+__dhcpd_piddir=/var/run			# pid file directory
+__dhcpd_leasesdir=/var/db		# leases file directory
+#__dhcpd_rootdir=/var/db/${name}	# root directory
 
 dhcpd_check
 dhcpd_rcvar

CC David Du SERRE-TELMON  and Jonathan Weiss

Cyrille Lefevre
-- 
mailto:cyrille.lefevre@laposte.net