Date: Fri, 23 Apr 2010 02:48:04 +0200 From: "Aragon Gouveia" <aragon@phat.za.net> To: FreeBSD-gnats-submit@FreeBSD.org Subject: misc/145962: [nanobsd] improved cfg save script Message-ID: <20100423004804.A13983A465@mail.geek.sh> Resent-Message-ID: <201004230050.o3N0o523013980@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>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:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20100423004804.A13983A465>