diff options
author | Adam Tkac <atkac@redhat.com> | 2012-01-30 16:59:01 +0100 |
---|---|---|
committer | Adam Tkac <atkac@redhat.com> | 2012-01-30 16:59:01 +0100 |
commit | d218af54a5284ff3508ad697176ee8167a0e3bd0 (patch) | |
tree | 5c62259022e260745c4a28b1c3e3d842882f44d4 /setup-named-chroot.sh | |
parent | c7d6bc15c0f8c3851018d994baa5da0d89f86994 (diff) | |
download | bind-d218af54a5284ff3508ad697176ee8167a0e3bd0.tar.gz bind-d218af54a5284ff3508ad697176ee8167a0e3bd0.tar.xz bind-d218af54a5284ff3508ad697176ee8167a0e3bd0.zip |
retire initscript in favour of systemd unit files (#719419)
Signed-off-by: Adam Tkac <atkac@redhat.com>
Diffstat (limited to 'setup-named-chroot.sh')
-rwxr-xr-x | setup-named-chroot.sh | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/setup-named-chroot.sh b/setup-named-chroot.sh new file mode 100755 index 0000000..38cb1ce --- /dev/null +++ b/setup-named-chroot.sh @@ -0,0 +1,80 @@ +#!/bin/bash + +ROOTDIR_MOUNT='/etc/named /etc/pki/dnssec-keys /var/named /etc/named.conf +/etc/named.dnssec.keys /etc/named.rfc1912.zones /etc/rndc.conf /etc/rndc.key +/usr/lib64/bind /usr/lib/bind /etc/named.iscdlv.key /etc/named.root.key' + +usage() +{ + echo + echo 'This script setups chroot environment for BIND' + echo 'Usage: setup-named-chroot.sh ROOTDIR [on|off]' +} + +if ! [ "$#" -eq 2 ]; then + echo 'Wrong number of arguments' + usage + exit 1 +fi + +ROOTDIR="$1" + +# Exit if ROOTDIR doesn't exist +if ! [ -d "$ROOTDIR" ]; then + echo "Root directory $ROOTDIR doesn't exist" + usage + exit 1 +fi + +mount_chroot_conf() +{ + if [ -n "$ROOTDIR" ]; then + for all in $ROOTDIR_MOUNT; do + # Skip nonexistant files + [ -e "$all" ] || continue + + # If mount source is a file + if ! [ -d "$all" ]; then + # mount it only if it is not present in chroot or it is empty + if ! [ -e "$ROOTDIR$all" ] || [ `stat -c'%s' "$ROOTDIR$all"` -eq 0 ]; then + touch "$ROOTDIR$all" + mount --bind "$all" "$ROOTDIR$all" + fi + else + # Mount source is a directory. Mount it only if directory in chroot is + # empty. + if [ -e "$all" ] && [ `ls -1A $ROOTDIR$all | wc -l` -eq 0 ]; then + mount --bind "$all" "$ROOTDIR$all" + fi + fi + done + fi +} + +umount_chroot_conf() +{ + for all in $ROOTDIR_MOUNT; do + # Check if file is mount target. Do not use /proc/mounts because detecting + # of modified mounted files can fail. + if mount | grep -q '.* on '"$ROOTDIR$all"' .*'; then + umount "$ROOTDIR$all" + # Remove temporary created files + [ -f "$all" ] && rm -f "$ROOTDIR$all" + fi + done +} + +case "$2" in + on) + mount_chroot_conf + ;; + off) + umount_chroot_conf + ;; + *) + echo 'Second argument has to be "on" or "off"' + usage + exit 1 +esac + +exit 0 |