57 lines
1.4 KiB
Bash
Executable File
57 lines
1.4 KiB
Bash
Executable File
#!/bin/bash -eu
|
|
|
|
# This is the install script for radvd when run in a privileged
|
|
# container.
|
|
#
|
|
# The host file system must be mounted at /host
|
|
|
|
cd /
|
|
PATH="/usr/bin:/usr/sbin"
|
|
MISSING_PACKAGES=0
|
|
: "${HOST:=/host}"
|
|
: "${ORIGIN:=}"
|
|
|
|
QUADLET_DIR="$HOST/etc/containers/systemd"
|
|
QUADLET_FILENAME="radvd.container"
|
|
|
|
if [ ! -d $HOST/etc ] || [ ! -d $HOST/proc ] || [ ! -d $HOST/run ]; then
|
|
echo "radvd-install: host file system is not mounted at $HOST"
|
|
exit 1
|
|
fi
|
|
|
|
if test ! -w "/host/etc"; then
|
|
echo "radvd-install: this container cannot be installed by a non-root user."
|
|
exit 1
|
|
fi
|
|
|
|
installed=false
|
|
if test ! -e "/host/etc/radvd.conf"; then
|
|
random() {
|
|
od -An -d -N2 /dev/urandom
|
|
}
|
|
|
|
prefix=`printf "fd%02x:%04x:%04x:0001::/64\n" $(($(random) % 256)) $(random) $(random)`
|
|
sed -e "s,prefix (fd.*/64),prefix $prefix," $ORIGIN/etc/radvd.conf > $HOST/etc/radvd.conf
|
|
echo "radvd-install: created /etc/radvd.conf with ULA prefix $prefix"
|
|
|
|
installed=true
|
|
fi
|
|
|
|
if test ! -e "$QUADLET_DIR/$QUADLET_FILENAME"; then
|
|
mkdir -p "$QUADLET_DIR"
|
|
sed -e "s,%IMAGE%,%{IMAGE},g" "$ORIGIN/container/quadlet/${QUADLET_FILENAME}.in" \
|
|
> "$QUADLET_DIR/${QUADLET_FILENAME}"
|
|
echo "radvd-install: installed $QUADLET_FILENAME quadlet"
|
|
chroot "$HOST" systemctl daemon-reload
|
|
installed=true
|
|
fi
|
|
|
|
if test "$installed" = "true"; then
|
|
echo radvd container installed, to start it:
|
|
else
|
|
echo radvd container was already installed, to start it
|
|
fi
|
|
|
|
echo systemctl enable --now radvd
|
|
|