docker_bind/setup.sh

41 lines
1.4 KiB
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=$(podman 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/
# install our podman config
if [ -d /etc/containers/systemd ]; then
install -o root -g root -m 0644 named.container /etc/containers/systemd/
systemctl daemon-reload
systemctl start named
else
echo "containers-common not installed?"
exit 1
fi
exit 0