#! /bin/bash set -e # NOTE: groupadd and useradd require root. [ "$EUID" -ne 0 ] && echo "Must be run by root" && exit 1 IMAGE="docker.io/internetsystemsconsortium/bind9:9.18" # determine current uid and gid uidgid=$(docker run --rm --entrypoint=/bin/sh "$IMAGE" -c "/usr/bin/id -u bind; /usr/bin/id -g bind") read -d '' -r uid gid <<< "$uidgid" || : # Create or update the on host user to match the container's 'bind' user and group ACTUAL_UID=$(id -u bind 2>/dev/null) ACTUAL_GID=$(id -g bind 2>/dev/null) [ -z "$ACTUAL_GID" ] && groupadd -f -g "$gid" bind [ -z "$ACTUAL_UID" ] && useradd -u "$uid" -g "$gid" -M --no-log-init bind [ "$ACTUAL_GID" -ne "$gid" ] && groupmod -g "$gid" bind [ "$ACTUAL_UID" -ne "$uid" ] && usermod -u "$uid" -g "$gid" # create/update our main directory setup install -d -o bind -g bind -m 0755 /etc/bind/cfg /etc/bind/cache /etc/bind/zones /etc/bind/log/named # copy over our config and data without overwriting anything, hopefully. rsync -av --chown bind:bind --del ./cfg/ /etc/bind/cfg/ rsync -av --chown bind:bind ./zones /etc/bind/zones/ rsync -av --chown bind:bind --ignore-existing ./cache/ /etc/bind/cache/ if [ -f docker.named.service ]; then install -m 0644 docker.named.service /etc/systemd/system/docker.named.service fi systemctl try-restart docker.named.service exit 0