Package: rsync
Version: 3.0.7-1
Severity: wishlist
Tags: patch

Hi,

Managing a monolithic /etc/rsyncd.conf file can be pain, especially
if you are deploying parts of that file using packages.

There are various update-* scripts that take a bunch of snippets and
munge them together to generate a config file that the appriopriate
tool can use.

I've grabbed one of those (which one I can't tell you as I typed
in the wrong filename into the script when I first wrote it years
ago) and modified it to generate /etc/rsyncd.conf.

I've attached this script, and find it really useful.

Cheers!


-- System Information:
Debian Release: squeeze/sid
  APT prefers unstable
  APT policy: (500, 'unstable'), (1, 'experimental')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.30-2-amd64 (SMP w/2 CPU cores)
Locale: LANG=en_NZ.UTF-8, LC_CTYPE=POSIX (charmap=ANSI_X3.4-1968)
Shell: /bin/sh linked to /bin/bash

Versions of packages rsync depends on:
ii  base-files                    5.1        Debian base system miscellaneous f
ii  libacl1                       2.2.49-2   Access control list shared library
ii  libc6                         2.10.2-6   Embedded GNU C Library: Shared lib
ii  libpopt0                      1.15-1     lib for parsing cmdline parameters
ii  lsb-base                      3.2-23     Linux Standard Base 3.2 init scrip

rsync recommends no packages.

Versions of packages rsync suggests:
ii  openssh-client                1:5.3p1-1  secure shell (SSH) client, for sec
ii  openssh-server                1:5.3p1-1  secure shell (SSH) server, for sec

-- no debconf information
#!/bin/sh

# Build an /etc/rsyncd.conf file from snippets in /etc/rsyncd.conf.d.
# Modelled on various other similar scripts from Debian.

RSYNCCONFFILE=/etc/rsyncd.conf
RSYNCCONFTMPFILE="${RSYNCCONFFILE}.$$"

HEADER="### This file is automatically generated by update-rsyncd.conf"

set -e

if [ "$1" = "force" ] ; then
        force=1
else
        force=
fi

checkoverwrite() {
        cfgfile="$1"

        if [ -f "$cfgfile" ]; then
                if ! sed -ne 1p "$cfgfile" | grep -q "^$HEADER" ; then
                        echo "Error: the current $cfgfile is not automatically generated." >&2
                        if [ -z "$force" ]; then
                                echo "Use \"update-rsyncd.conf force\" to force (re)generation."
                                exit 3
                        else
                                echo "force specified, (re)generating file anyway."
                        fi
                fi
        fi
}

createfile() {
        cat <<EOF > "$1"
$HEADER
#
# Please do not edit this file directly. If you want to change or add
# anything please take a look at the files in /etc/rsyncd.conf.d and run
# update-rsyncd.conf
#
EOF
}

addfile() {
        src="$1"
        tgt="$2"

        echo "### update-rsyncd.conf: start processing $src" >> "$tgt"
        if [ -e "$src" ] ; then
                cat "$src" >> "$tgt"
        else
                echo "Warnings: $src does not exist (dangling symlink?)"
        fi
        cat <<EOF >> "$tgt"

### update-rsyncd.conf: end processing $cfg

EOF
}

checkoverwrite "$RSYNCCONFFILE"

if [ 0 -ne "`id -u`" ]; then
        echo "You have to be root to do this." >&2
        exit 2
fi

[ -e "$RSYNCCONFFILE" ] && cp -f "$RSYNCCONFFILE" "${RSYNCCONFFILE}.old"

createfile "$RSYNCCONFTMPFILE"

for cfg in /etc/rsyncd.conf.d/* ; do
        if [ -f "$cfg" ]; then
                if ! echo $cfg | grep -q '\(\.dpkg-[a-z]*\|\.orig|,v|~\)$' ; then
                        addfile "$cfg" "$RSYNCCONFTMPFILE"
                fi
        fi
done

mv "$RSYNCCONFTMPFILE" "$RSYNCCONFFILE"

Reply via email to