From owner-freebsd-bugs@FreeBSD.ORG Fri Apr 23 00:50:05 2010 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A4D731065672 for ; Fri, 23 Apr 2010 00:50:05 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 6956E8FC0C for ; Fri, 23 Apr 2010 00:50:05 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id o3N0o5qi013981 for ; Fri, 23 Apr 2010 00:50:05 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id o3N0o523013980; Fri, 23 Apr 2010 00:50:05 GMT (envelope-from gnats) Resent-Date: Fri, 23 Apr 2010 00:50:05 GMT Resent-Message-Id: <201004230050.o3N0o523013980@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Aragon Gouveia Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 47047106567C for ; 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 ; 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 ; 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" To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Cc: Subject: misc/145962: [nanobsd] improved cfg save script X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Aragon Gouveia List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 23 Apr 2010 00:50:05 -0000 >Number: 145962 >Category: misc >Synopsis: [nanobsd] improved cfg save script >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Fri Apr 23 00:50:05 UTC 2010 >Closed-Date: >Last-Modified: >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: >Unformatted: