From aragon@phat.za.net  Fri Apr 23 00:48:09 2010
Return-Path: <aragon@phat.za.net>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 47047106567C
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 23 Apr 2010 00:48:09 +0000 (UTC)
	(envelope-from aragon@phat.za.net)
Received: from mail.geek.sh (decoder.geek.sh [196.36.198.81])
	by mx1.freebsd.org (Postfix) with ESMTP id 6ADE88FC1A
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 23 Apr 2010 00:48:07 +0000 (UTC)
Received: from phat.za.net (196-209-37-82-ndn-esr-3.dynamic.isadsl.co.za [196.209.37.82])
	by mail.geek.sh (Postfix) with ESMTPA id A13983A465
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 23 Apr 2010 02:48:04 +0200 (SAST)
Received: by phat.za.net (sSMTP sendmail emulation); Fri, 23 Apr 2010 02:48:04 +0200
Message-Id: <20100423004804.A13983A465@mail.geek.sh>
Date: Fri, 23 Apr 2010 02:48:04 +0200
From: "Aragon Gouveia" <aragon@phat.za.net>
Reply-To: Aragon Gouveia <aragon@phat.za.net>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [nanobsd] improved cfg save script
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         145962
>Category:       misc
>Synopsis:       [nanobsd] [patch] improved cfg save script
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    imp
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Fri Apr 23 00:50:05 UTC 2010
>Closed-Date:    Fri Mar 14 14:30:44 MDT 2014
>Last-Modified:  Fri Mar 14 14:30:44 MDT 2014
>Originator:     Aragon Gouveia
>Release:        FreeBSD 8.0-STABLE amd64
>Organization:
>Environment:
System: FreeBSD igor.geek.sh 8.0-STABLE FreeBSD 8.0-STABLE #0: Mon Mar 8 01:27:41 SAST 2010 toor@igor.geek.sh:/usr/obj/usr/src/sys/IGOR amd64


	
>Description:
	NanoBSD has a utility shell script called save_cfg which helps keep /cfg updated with the modified configuration files in /etc.  I have written an improved version with the following features:

	* Recurses directories.
	* Only requires file arguments the first time the file/directory is added to /cfg.
	* Handles file deletions.
	* Is named "cfgsync" so is much easier to type.
>How-To-Repeat:
	
>Fix:

	

--- cfgsync begins here ---
#!/bin/sh

set -e

rundir="$(pwd)/"
trap "umount /cfg" 1 2 3 15 EXIT
mount /cfg
for i in "$@"; do
	if [ -n "${i%%/*}" ]; then
		# relative (to rundir) path given
		if [ -n "${rundir%%/etc/*}" ]; then
			echo "${i} not under /etc -- skipping" 1>&2
			continue
		fi
		etcfile="${rundir}${i}"
		cfgfile="/cfg/${rundir##*/etc/}${i}"
	else
		# absolute path given
		if [ -z "${i%%/etc/*}" ]; then
			echo "${i} not under /etc -- skipping" 1>&2
			continue
		fi
		etcfile="${i}"
		cfgfile="/cfg/${i##*/etc/}"
	fi
	cfgdir=$(dirname ${cfgfile})
	if [ ! -f ${etcfile} ]; then
		echo "${i} not a file -- skipping" 1>&2
		continue
	fi
	if ! cmp -s ${etcfile} ${cfgfile}; then
		if [ ! -d ${cfgdir} ]; then
			mkdir -pv ${cfgdir}
		fi
		cp -pfv ${etcfile} ${cfgfile}
	fi
done
for i in $( find /cfg -type f ); do
	etcfile="/etc/${i##*/cfg/}"
	cfgfile="${i}"
	if [ ! -f ${etcfile} ]; then
		echo -n "${etcfile} disappeared.  Delete from /cfg? [y/N] "
		read delconfirm
		if [ "${delconfirm}" = "y" ]; then
			echo -n "deleting "
			rm -fv ${cfgfile}
		fi
	elif ! cmp -s ${etcfile} ${cfgfile}; then
		cp -pfv ${etcfile} ${cfgfile}
	fi
done
--- cfgsync ends here ---


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->imp 
Responsible-Changed-By: imp 
Responsible-Changed-When: Fri May 13 13:55:00 MDT 2011 
Responsible-Changed-Why:  
This looks good.  I'll integrate. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=145962 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: misc/145962: commit references a PR
Date: Fri, 14 Mar 2014 20:20:39 +0000 (UTC)

 Author: imp
 Date: Fri Mar 14 20:20:32 2014
 New Revision: 263189
 URL: http://svnweb.freebsd.org/changeset/base/263189
 
 Log:
   NanoBSD has a utility shell script called save_cfg which helps keep
   /cfg updated with the modified configuration files in /etc. I have
   written an improved version with the following features:
   
   * Recurses directories.
   * Only requires file arguments the first time the file/directory is
   * added to /cfg.
   * Handles file deletions.
   
   PR: 145962, 157533
   Submitted by: Aragon Gouveia and Alex Bakhtin
 
 Modified:
   head/tools/tools/nanobsd/Files/root/save_cfg
 
 Modified: head/tools/tools/nanobsd/Files/root/save_cfg
 ==============================================================================
 --- head/tools/tools/nanobsd/Files/root/save_cfg	Fri Mar 14 19:46:32 2014	(r263188)
 +++ head/tools/tools/nanobsd/Files/root/save_cfg	Fri Mar 14 20:20:32 2014	(r263189)
 @@ -1,6 +1,7 @@
  #!/bin/sh
  #
  # Copyright (c) 2006 Mathieu Arnold
 +# Copyright (c) 2010 Alex Bakhtin
  # All rights reserved.
  #
  # Redistribution and use in source and binary forms, with or without
 @@ -32,11 +33,86 @@ set -e
  trap "umount /cfg" 1 2 15 EXIT
  mount /cfg
  (
 +cd /etc
 +for filename in "$@" `find * -type f`
 +do
 +	if [ ! -f /cfg/$filename -a ! -f /cfg/.ignore/$filename ]
 +	then
 +
 +		#
 +		# If file doesn't exist in /cfg and file is not in the 'ignore' list
 +		# then check if this file is exactly the same as original file
 +		# in nanobsd image
 +		#
 +		if ! cmp -s /etc/$filename /conf/base/etc/$filename 
 +		then
 +			file_path=`echo "$filename" | sed 's/\/[^/]*$//'`
 +			if [ $file_path != $filename ]
 +			then
 +				if [ ! -d /etc/$file_path ]
 +				then
 +					# should never go here unless we have some errors in
 +					# sed script extracting file path
 +					echo "Error: Path /etc/$file_path is not directory."
 +					exit 1;
 +				fi
 +			fi
 +
 +			#
 +			# Ask user - how should we handle this file.
 +			# Add to cfg (y/n/i)?
 +			#	y) -> save this file in /cfg
 +			#	n) -> do not save this file in /cfg for current script invocation ONLY
 +			#	i) -> add file to ignore list (/cfg/.ignore hiereachy) and never save
 +			#	      try to add this file to /cfg.
 +			#
 +			# touch is ised to add files to /cfg to keep the script flow straight and easy
 +			#
 +			read -p "New file /etc/$filename found. Add to /cfg (y/n/i)? " key
 +			case "$key" in
 +			[yY])
 +				if [ $file_path != $filename ]
 +				then
 +					mkdir -vp /cfg/$file_path
 +				fi
 +				touch /cfg/$filename && echo "File /etc/$filename added to /cfg."
 +				;;
 +			[iI])
 +				mkdir -vp /cfg/.ignore
 +				if [ $file_path != $filename ]
 +				then
 +					mkdir -vp /cfg/.ignore/$file_path
 +				fi
 +				touch /cfg/.ignore/$filename && echo "File /etc/$filename added to ignore list."
 +				;;
 +			esac
 +		fi
 +	fi
 +done
 +
 +#
 +# Actually check all files in /cfg and save if necessary
 +#
  cd /cfg
 -for i in "$@" `find * -type f`
 +for filename in "$@" `find * -type f`
  do
 -        cmp -s /etc/$i /cfg/$i || cp -pfv /etc/$i /cfg/$i
 +	if [ -f /etc/$filename ]
 +	then
 +        	cmp -s /etc/$filename /cfg/$filename || cp -pfv /etc/$filename /cfg/$filename
 +	else
 +
 +		#
 +		# Give user an option to remove file from /cfg if this file is removed from /etc
 +		#
 +		read -p "File /cfg/$filename not found in /etc. Remove from /cfg (y/n)? " key
 +		case "$key" in
 +		[yY])
 +			rm /cfg/$filename && echo "File /cfg/$filename removed"
 +			;;
 +		esac
 +	fi
  done
 +
  )
  umount /cfg
  trap 1 2 15 EXIT
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->closed 
State-Changed-By: imp 
State-Changed-When: Fri Mar 14 14:30:32 MDT 2014 
State-Changed-Why:  
Now in tree. Thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=145962 
>Unformatted:
