Files
dhcp/rootfs/entrypoint.sh
GianLuca Vagnuzzi aef0ae4dea
All checks were successful
Update Docker Hub Description / dockerHubDescription (push) Successful in 12s
Defined CMD in Dockerfile; ENTRYPOINT now supports user-provided commands
2026-01-02 08:21:38 +01:00

108 lines
2.7 KiB
Bash
Executable File

#!/bin/bash
set -x
: ${path_list:="
/path/foo
"}
function _dirs {
DEST_PATH="/data"
echo "--------------------------------------"
echo " Moving persistent data in $DEST_PATH "
echo "--------------------------------------"
for path_name in $path_list; do
if [ ! -e ${DEST_PATH}${path_name} ]; then
if [ -d $path_name ]; then
rsync -Ra ${path_name}/ ${DEST_PATH}/
else
rsync -Ra ${path_name} ${DEST_PATH}/
fi
else
echo "---------------------------------------------------------"
echo " No NEED to move anything for $path_name in ${DEST_PATH} "
echo "---------------------------------------------------------"
fi
rm -rf ${path_name}
ln -s ${DEST_PATH}${path_name} ${path_name}
done
}
function _main {
[ -e "/data/dhcpd4.conf" ] || cp "/template/dhcpd4.conf" "/data/"
[ -e "/data/dhcpd6.conf" ] || cp "/template/dhcpd6.conf" "/data/"
[ -e "/data/dhcpd4.leases" ] || touch "/data/dhcpd4.leases"
[ -e "/data/dhcpd6.leases" ] || touch "/data/dhcpd6.leases"
useradd dhcpd
uid=$(id -u dhcpd)
gid=$(id -g dhcpd)
chown -R dhcpd: "/data/dhcpd4.leases" "/data/dhcpd6.leases"
#export CMDv4="/usr/sbin/dhcpd -4 -f -d --no-pid -cf /data/dhcpd4.conf -lf /data/dhcpd4.leases -user dhcpd -group dhcpd"
export CMDv6="/usr/sbin/dhcpd -6 -f -d --no-pid -cf /data/dhcpd6.conf -lf /data/dhcpd6.leases -user dhcpd -group dhcpd"
chown -R dhcpd: "/data"
}
custom_bashrc() {
cat <<'EOF'
export LS_OPTIONS="--color=auto"
alias ls='ls $LS_OPTIONS'
alias ll='ls $LS_OPTIONS -la'
alias l='ls $LS_OPTIONS -lA'
# prompt SOLO per shell interattive
if [[ $- == *i* ]]; then
if [ "$(id -u)" -eq 0 ]; then
PS1="\[\e[35m\][\[\e[31m\]\u\[\e[36m\]@\[\e[32m\]\h\[\e[90m\] \w\[\e[35m\]]\[\e[0m\]# "
else
PS1="\[\e[35m\][\[\e[33m\]\u\[\e[36m\]@\[\e[32m\]\h\[\e[90m\] \w\[\e[35m\]]\[\e[0m\]$ "
fi
export PS1
fi
EOF
}
setup_bashrc() {
for home in /root /home/*; do
[ -d "$home" ] || continue
bashrc="$home/.bashrc"
# crea se manca
[ -f "$bashrc" ] || touch "$bashrc"
# evita duplicazioni
grep -q '### CUSTOM BASHRC ###' "$bashrc" && continue
{
echo ''
echo '### CUSTOM BASHRC ###'
custom_bashrc
} >> "$bashrc"
done
}
_main
setup_bashrc
# If any arguments were passed (i.e., CMD from Dockerfile), store them in CMD
[ "$#" -gt 0 ] && CMD="$@"
[ "$DHCP4" = "0" ] && export CMD=""
if [ "$DHCP6" = "1" ]; then
[ -z "$CMD" ] && export CMD=$CMDv6 || $CMDv6 &
fi
[ -z "$CMD" ] && echo "Warning! DHCP not selected." && exit
# Ensure terminal state is restored and cursor is visible when the container exits
trap 'stty sane 2>/dev/null; tput cnorm 2>/dev/null' EXIT
# print cmd that will be executed
echo "Starting: $*" >&2
# Split CMD into proper arguments and execute
set -- $CMD
exec "$@"