Skip to content

Commit 17daa7a

Browse files
authored
Merge pull request #8 from linuxserver/new-custom-files-fedora
Support new custom files locations
2 parents 1ed4e55 + d52c295 commit 17daa7a

File tree

1 file changed

+102
-37
lines changed

1 file changed

+102
-37
lines changed
Lines changed: 102 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,114 @@
11
#!/usr/bin/with-contenv bash
2+
# shellcheck shell=bash
23

34
# Directories
4-
SCRIPTS_DIR="/config/custom-cont-init.d"
5-
SERVICES_DIR="/config/custom-services.d"
5+
SCRIPTS_DIR_OLD="/config/custom-cont-init.d"
6+
SERVICES_DIR_OLD="/config/custom-services.d"
7+
SCRIPTS_DIR="/custom-cont-init.d"
8+
SERVICES_DIR="/custom-services.d"
69

710
# Remove all existing custom services before continuing to ensure
811
# we aren't running anything the user may have removed
9-
if [ -n "$(/bin/ls -A /etc/services.d/custom-service-* 2>/dev/null)" ]; then
10-
echo "[custom-init] removing existing custom services..."
11-
rm -rf /etc/services.d/custom-service-*
12+
if [[ -n "$(/bin/ls -A /etc/s6-overlay/s6-rc.d/custom-svc-* 2>/dev/null)" ]]; then
13+
echo "[custom-init] removing existing custom services..."
14+
rm -rf /etc/s6-overlay/s6-rc.d/custom-svc-*
1215
fi
1316

14-
# Make sure custom init directory exists and has files in it
15-
if ([ -e "${SCRIPTS_DIR}" ] && \
16-
[ -n "$(/bin/ls -A ${SCRIPTS_DIR} 2>/dev/null)" ]) || \
17-
([ -e "${SERVICES_DIR}" ] && \
18-
[ -n "$(/bin/ls -A ${SERVICES_DIR} 2>/dev/null)" ]); then
19-
if [ -n "$(/bin/ls -A ${SCRIPTS_DIR} 2>/dev/null)" ]; then
20-
echo "[custom-init] files found in ${SCRIPTS_DIR} executing"
21-
for SCRIPT in ${SCRIPTS_DIR}/*; do
22-
NAME="$(basename "${SCRIPT}")"
23-
if [ -f "${SCRIPT}" ]; then
24-
echo "[custom-init] ${NAME}: executing..."
25-
/bin/bash ${SCRIPT}
26-
echo "[custom-init] ${NAME}: exited $?"
27-
elif [ ! -f "${SCRIPT}" ]; then
28-
echo "[custom-init] ${NAME}: is not a file"
29-
fi
30-
done
17+
if [[ -z "$(/bin/ls -A ${SERVICES_DIR} 2>/dev/null)" ]] &&
18+
[[ -z "$(/bin/ls -A ${SERVICES_DIR_OLD} 2>/dev/null)" ]]; then
19+
echo "[custom-init] no custom services found, skipping..."
20+
else
21+
# Make sure custom service directory exists and has files in it
22+
if [[ -e "${SERVICES_DIR}" ]] && [[ -n "$(/bin/ls -A ${SERVICES_DIR} 2>/dev/null)" ]]; then
23+
echo "[custom-init] service files found in ${SERVICES_DIR}"
24+
for SERVICE in "${SERVICES_DIR}"/*; do
25+
NAME="$(basename "${SERVICE}")"
26+
if [[ -f "${SERVICE}" ]]; then
27+
echo "[custom-init] ${NAME}: service detected, copying..."
28+
mkdir -p /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/
29+
cp "${SERVICE}" /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/run
30+
chmod +x /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/run
31+
echo "longrun" >/etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/type
32+
touch /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/dependencies.d/init-services
33+
touch /etc/s6-overlay/s6-rc.d/init-mods-end/dependencies.d/custom-svc-"${NAME}"
34+
echo "[custom-init] ${NAME}: copied"
35+
elif [[ ! -f "${SERVICE}" ]]; then
36+
echo "[custom-init] ${NAME}: is not a file"
37+
fi
38+
done
3139
fi
32-
if [ -n "$(/bin/ls -A ${SERVICES_DIR} 2>/dev/null)" ]; then
33-
echo "[custom-init] service files found in ${SERVICES_DIR}"
34-
for SERVICE in ${SERVICES_DIR}/*; do
35-
NAME="$(basename "${SERVICE}")"
36-
if [ -f "${SERVICE}" ]; then
37-
echo "[custom-init] ${NAME}: service detected, copying..."
38-
mkdir -p /etc/services.d/custom-service-${NAME}/
39-
cp ${SERVICE} /etc/services.d/custom-service-${NAME}/run
40-
chmod +x /etc/services.d/custom-service-${NAME}/run
41-
echo "[custom-init] ${NAME}: copied"
42-
elif [ ! -f "${SERVICE}" ]; then
43-
echo "[custom-init] ${NAME}: is not a file"
44-
fi
45-
done
40+
41+
if [[ -e "${SERVICES_DIR_OLD}" ]] && [[ -n "$(/bin/ls -A ${SERVICES_DIR_OLD} 2>/dev/null)" ]]; then
42+
echo "[custom-init] service files found in ${SERVICES_DIR_OLD}"
43+
for SERVICE in "${SERVICES_DIR_OLD}"/*; do
44+
NAME="$(basename "${SERVICE}")"
45+
if [[ -f "${SERVICE}" ]]; then
46+
echo "[custom-init] ${NAME}: service detected, copying..."
47+
mkdir -p /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/
48+
cp "${SERVICE}" /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/run
49+
chmod +x /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/run
50+
echo "longrun" >/etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/type
51+
touch /etc/s6-overlay/s6-rc.d/custom-svc-"${NAME}"/dependencies.d/init-services
52+
touch /etc/s6-overlay/s6-rc.d/init-mods-end/dependencies.d/custom-svc-"${NAME}"
53+
echo "[custom-init] ${NAME}: copied"
54+
elif [[ ! -f "${SERVICE}" ]]; then
55+
echo "[custom-init] ${NAME}: is not a file"
56+
fi
57+
done
4658
fi
59+
fi
60+
61+
if [[ -z "$(/bin/ls -A ${SCRIPTS_DIR} 2>/dev/null)" ]] &&
62+
[[ -z "$(/bin/ls -A ${SCRIPTS_DIR_OLD} 2>/dev/null)" ]]; then
63+
echo "[custom-init] no custom files found, skipping..."
4764
else
48-
echo "[custom-init] no custom files found exiting..."
65+
# Make sure custom init directory exists and has files in it
66+
if [[ -e "${SCRIPTS_DIR}" ]] && [[ -n "$(/bin/ls -A ${SCRIPTS_DIR} 2>/dev/null)" ]]; then
67+
echo "[custom-init] files found, executing"
68+
for SCRIPT in "${SCRIPTS_DIR}"/*; do
69+
NAME="$(basename "${SCRIPT}")"
70+
if [[ -f "${SCRIPT}" ]]; then
71+
echo "[custom-init] ${NAME}: executing..."
72+
/bin/bash "${SCRIPT}"
73+
echo "[custom-init] ${NAME}: exited $?"
74+
elif [[ ! -f "${SCRIPT}" ]]; then
75+
echo "[custom-init] ${NAME}: is not a file"
76+
fi
77+
done
78+
fi
79+
80+
if [[ -e "${SCRIPTS_DIR_OLD}" ]] && [[ -n "$(/bin/ls -A ${SCRIPTS_DIR_OLD} 2>/dev/null)" ]]; then
81+
echo "[custom-init] files found, executing"
82+
for SCRIPT in "${SCRIPTS_DIR_OLD}"/*; do
83+
NAME="$(basename "${SCRIPT}")"
84+
if [[ -f "${SCRIPT}" ]]; then
85+
echo "[custom-init] ${NAME}: executing..."
86+
/bin/bash "${SCRIPT}"
87+
echo "[custom-init] ${NAME}: exited $?"
88+
elif [[ ! -f "${SCRIPT}" ]]; then
89+
echo "[custom-init] ${NAME}: is not a file"
90+
fi
91+
done
92+
fi
93+
fi
94+
95+
if [[ -n "$(/bin/ls -A "${SCRIPTS_DIR_OLD}" 2>/dev/null)" ]] ||
96+
[[ -n "$(/bin/ls -A "${SERVICES_DIR_OLD}" 2>/dev/null)" ]]; then
97+
cat <<-EOF | tee ${SCRIPTS_DIR_OLD}/README.txt,${SERVICES_DIR_OLD}/README.txt 2>/dev/null
98+
********************************************************
99+
********************************************************
100+
* *
101+
* !!!! *
102+
* Custom scripts or services found in legacy locations *
103+
* !!!! *
104+
* Please move your custom scripts and services *
105+
* to ${SCRIPTS_DIR} and ${SERVICES_DIR} *
106+
* respectively to ensure they continue working. *
107+
* *
108+
* Visit https://linuxserver.io/custom for more info. *
109+
* *
110+
********************************************************
111+
********************************************************
112+
EOF
49113
fi
114+
exit 0

0 commit comments

Comments
 (0)