>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 t...@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:
_______________________________________________
freebsd-bugs@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-bugs
To unsubscribe, send any mail to "freebsd-bugs-unsubscr...@freebsd.org"

Reply via email to