From owner-freebsd-ports@FreeBSD.ORG Thu Jan 3 17:28:47 2013 Return-Path: Delivered-To: freebsd-ports@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 0D2A3DA1 for ; Thu, 3 Jan 2013 17:28:47 +0000 (UTC) (envelope-from prvs=7089a4044=pschmehl_lists@tx.rr.com) Received: from ip-002.utdallas.edu (ip-002.utdallas.edu [129.110.20.108]) by mx1.freebsd.org (Postfix) with ESMTP id D3B436B3 for ; Thu, 3 Jan 2013 17:28:46 +0000 (UTC) X-Group: None X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ap8EAJG+5VCBbgog/2dsb2JhbABFgX+7aXOCHgEBBAE4Aj8FCwsOCi4hNgYBEgmHeAMJBgyvOw2GLIttgRKDOmEDiGKJd4FdjQ2FEYMTgUkCHgQ X-IronPort-AV: E=Sophos;i="4.84,403,1355119200"; d="scan'208";a="113168727" Received: from zxtm01.utdallas.edu (HELO utd71538.utdallas.edu) ([129.110.10.32]) by ip-002.utdallas.edu with ESMTP/TLS/DHE-RSA-AES256-SHA; 03 Jan 2013 11:28:44 -0600 Date: Thu, 03 Jan 2013 11:28:43 -0600 From: Paul Schmehl To: Fabian Keil , freebsd-ports@freebsd.org Subject: Re: What is policy about auto-editing config files on port install / deinstall? Message-ID: <956FEBA7374A9446245A9CEE@utd71538.campus.ad.utdallas.edu> In-Reply-To: <20130103131243.043c47cf@fabiankeil.de> References: <50E49A73.2070008@quip.cz> <20130103131243.043c47cf@fabiankeil.de> X-Mailer: Mulberry/4.1.0a1 (Mac OS X) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline; size=4889 Cc: Scot Hetzel , Miroslav Lachman <000.fbsd@quip.cz> X-BeenThere: freebsd-ports@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: Paul Schmehl List-Id: Porting software to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Jan 2013 17:28:47 -0000 --On January 3, 2013 1:12:43 PM +0100 Fabian Keil wrote: > Scot Hetzel wrote: > >> On Wed, Jan 2, 2013 at 2:37 PM, Miroslav Lachman <000.fbsd@quip.cz> >> wrote: >> > Is somewhere written policy or portmgr recommendation about ports >> > behavior on install / deinstall? > > My impression is that every maintainer has her own undocumented > policy although the approaches taken could be grouped into a few > categories. > This is likely true, however the Porters Handbook describes the preferred methods for doing things. >> > I am talking about some ports doing "nasty" things. >> > >> > Some ports are stopping services on deinstall, some not. >> >> I prefer that when a port is uninstalled, that the service is stopped. > According to the Porters Handbook, this is not the preferred method: "6.24.1 Stopping Services at Deinstall It is possible to have a service stopped automatically as part of the deinstall routine. We advise using this feature only when it is absolutely necessary to stop a service before its files go away. Usually, it is up to the administrator's discretion to decide, whether to stop the service on deinstall or not. Also note this affects upgrades, too. A line like this goes in the pkg-plist: @stopdaemon doormand The argument must match the content of USE_RC_SUBR variable." > >> > Some ports are editing "my config files" on deinstall, so even on >> > upgrade procedure I must check if port did some changes before I can >> > restart target daemon. >> > >> Most ports don't edit the config files as they install the original >> config file to a different name. > > In my opinion ports shouldn't mess with user-modified files unless > they properly parse them and can be expected not to break them. The Porters Handbooks explicitly states this: "7.3 Configuration Files If your port installs configuration files to PREFIX/etc (or elsewhere) do not simply list them in the pkg-plist. That will cause pkg_delete(1) to remove the files carefully edited by the user, and a re-installation will wipe them out. Instead, install sample file(s) with a filename.sample suffix. Then copy the sample file to the real configuration file name, if it does not already exist. On deinstall delete the configuration file, but only if it is identical to the .sample file. You need to handle this both in the port Makefile, and in the pkg-plist (for installation from the package). Example of the Makefile part: post-install: @if [ ! -f ${PREFIX}/etc/orbit.conf ]; then \ ${CP} -p ${PREFIX}/etc/orbit.conf.sample ${PREFIX}/etc/orbit.conf ; \ fi For each configuration file, create the following three lines in pkg-plist: @unexec if cmp -s %D/etc/orbit.conf.sample %D/etc/orbit.conf; then rm -f %D/etc/orbit.conf; fi etc/orbit.conf.sample @exec if [ ! -f %D/etc/orbit.conf ] ; then cp -p %D/%F %B/orbit.conf; fi The order of these lines is important. On deinstallation, the sample file is compared to the actual configuration file. If these files are identical, no changes have been made by the user and the actual file can be safely deleted. Because the sample file must still exist for the comparison, the @unexec line comes before the sample configuration file name. On installation, if an actual configuration file is not already present, the sample file is copied to the actual file. The sample file must be present before it can be copied, so the @exec line comes after the sample configuration file name. To debug any issues, temporarily remove the -s flag to cmp(1) for more output. See pkg_create(1) for more information on %D and related substitution markers. If there is a very good reason not to install a working configuration file by default, leave the @exec line out of pkg-plist and add a message pointing out that the user must copy and edit the file before the software will work." > > And even then I don't think it should be done automatically without > user interaction. > > I believe that's currently up to the maintainer as well, though. > Not if they are properly following the Porters Handbook and the committers are verifying that they are doing so. As with any system where humans are involved, the process is flawed. However, there is a right way to do things. Refer to the Porters Handbook and follow its instructions as much as is humanly possible. -- Paul Schmehl, Senior Infosec Analyst As if it wasn't already obvious, my opinions are my own and not those of my employer. ******************************************* "It is as useless to argue with those who have renounced the use of reason as to administer medication to the dead." Thomas Jefferson "There are some ideas so wrong that only a very intelligent person could believe in them." George Orwell