Remove custom service handling

This commit is contained in:
TheSpad 2022-06-10 16:16:17 +01:00
parent ec6eed279d
commit 92a97355b4
No known key found for this signature in database
GPG key ID: 08F06191F4587860

View file

@ -2,37 +2,21 @@
# Directories
SCRIPTS_DIR_OLD="/config/custom-cont-init.d"
SERVICES_DIR_OLD="/config/custom-services.d"
SCRIPTS_DIR="/custom-cont-init.d"
SERVICES_DIR="/custom-services.d"
# chown legacy folders if they exist
if [ -e "${SCRIPTS_DIR_OLD}" ]; then
chown -R 0:0 "${SCRIPTS_DIR_OLD}"
fi
if [ -e "${SERVICES_DIR_OLD}" ]; then
chown -R 0:0 "${SERVICES_DIR_OLD}"
fi
# Remove all existing custom services before continuing to ensure
# we aren't running anything the user may have removed
if [ -n "$(/bin/ls -A /etc/services.d/custom-service-* 2>/dev/null)" ]; then
echo "[custom-init] removing existing custom services..."
rm -rf /etc/services.d/custom-service-*
fi
if { [ -z "$(/bin/ls -A ${SCRIPTS_DIR} 2>/dev/null)" ]; } && \
{ [ -z "$(/bin/ls -A ${SERVICES_DIR} 2>/dev/null)" ]; } && \
{ [ -z "$(/bin/ls -A ${SCRIPTS_DIR_OLD} 2>/dev/null)" ]; } && \
{ [ -z "$(/bin/ls -A ${SERVICES_DIR_OLD} 2>/dev/null)" ]; }; then
{ [ -z "$(/bin/ls -A ${SCRIPTS_DIR_OLD} 2>/dev/null)" ]; }; then
echo "[custom-init] no custom files found, exiting..."
exit 0
fi
# Make sure custom init directory exists and has files in it
if { [ -e "${SCRIPTS_DIR}" ] && [ -n "$(/bin/ls -A ${SCRIPTS_DIR} 2>/dev/null)" ]; } || \
{ [ -e "${SERVICES_DIR}" ] && [ -n "$(/bin/ls -A ${SERVICES_DIR} 2>/dev/null)" ]; }; then
if { [ -e "${SCRIPTS_DIR}" ] && [ -n "$(/bin/ls -A ${SCRIPTS_DIR} 2>/dev/null)" ]; }; then
if [ -n "$(/bin/ls -A ${SCRIPTS_DIR} 2>/dev/null)" ]; then
echo "[custom-init] files found, executing"
for SCRIPT in ${SCRIPTS_DIR}/*; do
@ -46,25 +30,9 @@ if { [ -e "${SCRIPTS_DIR}" ] && [ -n "$(/bin/ls -A ${SCRIPTS_DIR} 2>/dev/null)"
fi
done
fi
if [ -n "$(/bin/ls -A ${SERVICES_DIR} 2>/dev/null)" ]; then
echo "[custom-init] service files found in ${SERVICES_DIR}"
for SERVICE in ${SERVICES_DIR}/*; do
NAME="$(basename "${SERVICE}")"
if [ -f "${SERVICE}" ]; then
echo "[custom-init] ${NAME}: service detected, copying..."
mkdir -p /etc/services.d/custom-service-"${NAME}"/
cp "${SERVICE}" /etc/services.d/custom-service-"${NAME}"/run
chmod +x /etc/services.d/custom-service-"${NAME}"/run
echo "[custom-init] ${NAME}: copied"
elif [ ! -f "${SERVICE}" ]; then
echo "[custom-init] ${NAME}: is not a file"
fi
done
fi
fi
if { [ -e "${SCRIPTS_DIR_OLD}" ] && [ -n "$(/bin/ls -A ${SCRIPTS_DIR_OLD} 2>/dev/null)" ]; } || \
{ [ -e "${SERVICES_DIR_OLD}" ] && [ -n "$(/bin/ls -A ${SERVICES_DIR_OLD} 2>/dev/null)" ]; }; then
if { [ -e "${SCRIPTS_DIR_OLD}" ] && [ -n "$(/bin/ls -A ${SCRIPTS_DIR_OLD} 2>/dev/null)" ]; }; then
if [ -n "$(/bin/ls -A ${SCRIPTS_DIR_OLD} 2>/dev/null)" ]; then
echo "[custom-init] files found, executing"
for SCRIPT in ${SCRIPTS_DIR_OLD}/*; do
@ -78,19 +46,4 @@ if { [ -e "${SCRIPTS_DIR_OLD}" ] && [ -n "$(/bin/ls -A ${SCRIPTS_DIR_OLD} 2>/dev
fi
done
fi
if [ -n "$(/bin/ls -A ${SERVICES_DIR_OLD} 2>/dev/null)" ]; then
echo "[custom-init] service files found in ${SERVICES_DIR_OLD}"
for SERVICE in ${SERVICES_DIR_OLD}/*; do
NAME="$(basename "${SERVICE}")"
if [ -f "${SERVICE}" ]; then
echo "[custom-init] ${NAME}: service detected, copying..."
mkdir -p /etc/services.d/custom-service-"${NAME}"/
cp "${SERVICE}" /etc/services.d/custom-service-"${NAME}"/run
chmod +x /etc/services.d/custom-service-"${NAME}"/run
echo "[custom-init] ${NAME}: copied"
elif [ ! -f "${SERVICE}" ]; then
echo "[custom-init] ${NAME}: is not a file"
fi
done
fi
fi