scripts/start.sh hinzugefügt

This commit is contained in:
2024-12-06 10:22:38 +01:00
parent a27c1d1f87
commit 1c369e36e3

53
scripts/start.sh Normal file
View File

@@ -0,0 +1,53 @@
#!/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*" > /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}
chown -R {UID}:${GID} ${DATA_DIR}/*.conf
echo "---Starting...---"
term_handler() {
echo "---Stopping WireGuard tunnel---"
wg-quick down wg0 > /dev/null 2>&1
kill $(pidof sleep)
exit 143;
}
trap 'kill ${!}; term_handler' SIGTERM
su ${USER} -c "/opt/scripts/start-server.sh" &
killpid="$!"
while true
do
wait $killpid
exit 0;
done