#!/bin/bash echo "---Ensuring UID: ${UID} matches user---" usermod -u ${UID} ${USER} echo "---Ensuring GID: ${GID} matches user---" groupmod -g ${GID} ${USER} > /dev/null 2>&1 ||: usermod -g ${GID} ${USER} echo "---Setting umask to ${UMASK}---" umask ${UMASK} echo "---Checking for optional scripts---" cp -f /opt/custom/user.sh /opt/scripts/start-user.sh > /dev/null 2>&1 ||: cp -f /opt/scripts/user.sh /opt/scripts/start-user.sh > /dev/null 2>&1 ||: if [ -f /opt/scripts/start-user.sh ]; then echo "---Found optional script, executing---" chmod -f +x /opt/scripts/start-user.sh ||: /opt/scripts/start-user.sh || echo "---Optional Script has thrown an Error---" else echo "---No optional script found, continuing---" fi if [ ! -f /etc/sudoers.d/${USER} ]; then echo "---Creating sudoers file for user: ${USER}---" echo "${USER} ALL=(ALL) NOPASSWD: /usr/bin/wg-quick up * ${USER} ALL=(ALL) NOPASSWD: /usr/bin/wg-quick down * ${USER} ALL=(ALL) NOPASSWD: /usr/bin/wg show wg* ${USER} ALL=(ALL) NOPASSWD: /usr/local/bin/iptables-wg" > /etc/sudoers.d/${USER} else echo "---Found sudoers file for user: ${USER}---" fi echo "---Taking ownership of data...---" chown -R root:${GID} /opt/scripts chmod 440 /etc/sudoers.d/${USER} chmod -R 750 /opt/scripts chown ${UID}:${GID} ${DATA_DIR} chmod -R ${DATA_PERM} ${DATA_DIR} chown -R ${UID}:${GID} ${DATA_DIR}/*.conf /etc/wireguard echo "---Starting...---" term_handler() { echo "---Stopping WireGuard tunnel---" wg-quick down wg0 > /dev/null 2>&1 kill $(pidof sleep) exit 143; } if [ ! -z "${CONNECTED_CONTAINERS}" ]; then /opt/scripts/start-connected-containers.sh & fi trap 'kill ${!}; term_handler' SIGTERM su ${USER} -c "/opt/scripts/start-server.sh" & killpid="$!" while true do wait $killpid exit 0; done