From owner-svn-src-all@FreeBSD.ORG Fri Mar 14 20:20:32 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id B0851E84; Fri, 14 Mar 2014 20:20:32 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 9D801A1A; Fri, 14 Mar 2014 20:20:32 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s2EKKWlI069400; Fri, 14 Mar 2014 20:20:32 GMT (envelope-from imp@svn.freebsd.org) Received: (from imp@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s2EKKW5p069399; Fri, 14 Mar 2014 20:20:32 GMT (envelope-from imp@svn.freebsd.org) Message-Id: <201403142020.s2EKKW5p069399@svn.freebsd.org> From: Warner Losh Date: Fri, 14 Mar 2014 20:20:32 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r263189 - head/tools/tools/nanobsd/Files/root X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 14 Mar 2014 20:20:32 -0000 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