docker_bind/setup_docker.sh

32 lines
1010 B
Bash
Executable File

#! /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 the group and user
id -g bind >/dev/null 2>&1 || groupadd -f -g "$gid" bind
id -u bind >/dev/null 2>&1 || useradd -u "$uid" -g "$gid" -M --no-log-init bind
# create 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.
for d in cfg cache zones; do
rsync -av --chown bind:bind --ignore-existing ./$d/ /etc/bind/$d/
done
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