Skip to content

Commit 7095001

Browse files
committed
Fix duplicate paths in MOD_AUTO_SHARE
1 parent 0320fae commit 7095001

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

entrypoint.sh

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ mod_fix_kad_bootstrap() {
3939
if [ ! -f "${AMULE_HOME}/nodes.dat" ]; then
4040
printf "[MOD_FIX_KAD_BOOTSTRAP] Downloading nodes.dat from %s ... You can disable this mod with MOD_FIX_KAD_BOOTSTRAP_ENABLED=false\n" "${KAD_NODES_DAT_URL}"
4141
curl -s -o "${AMULE_HOME}/nodes.dat" "${KAD_NODES_DAT_URL}"
42-
chown ${AMULE_USER}:${AMULE_GROUP} "${AMULE_HOME}/nodes.dat"
42+
chown "${AMULE_USER}:${AMULE_GROUP}" "${AMULE_HOME}/nodes.dat"
4343
printf "[MOD_FIX_KAD_BOOTSTRAP] Downloaded successfully!\n"
4444
else
4545
printf "[MOD_FIX_KAD_BOOTSTRAP] File nodes.dat already exist. You can disable this mod with MOD_FIX_KAD_BOOTSTRAP_ENABLED=false\n"
@@ -54,17 +54,26 @@ mod_auto_share() {
5454
# Fix issue https://github.com/ngosang/docker-amule/issues/9
5555
# Share all the directories (separated by semicolon ';') and subdirectories in aMule.
5656
printf "[MOD_AUTO_SHARE] Sharing the following directories with sub-directories: %s ... You can disable this mod with MOD_AUTO_SHARE_ENABLED=false\n" "$MOD_AUTO_SHARE_DIRECTORIES"
57-
SHAREDDIR_CONF=${AMULE_HOME}/shareddir.dat
58-
printf "/incoming\n" > "$SHAREDDIR_CONF"
59-
iter=""
60-
IN="$MOD_AUTO_SHARE_DIRECTORIES"
61-
while [ "$IN" != "$iter" ] ;do
62-
iter=${IN%%;*}
63-
IN="${IN#"$iter";}"
64-
printf "[MOD_AUTO_SHARE] Sharing directory '%s' with sub-directories...\n" "$iter"
65-
find "$iter" -type d >> "$SHAREDDIR_CONF"
57+
SHAREDDIR_CONF="${AMULE_HOME}/shareddir.dat"
58+
SHAREDDIR_TMP="${SHAREDDIR_CONF}.tmp"
59+
printf "%s\n" "${AMULE_INCOMING}" > "$SHAREDDIR_TMP"
60+
IFS=';'
61+
set -- "$MOD_AUTO_SHARE_DIRECTORIES"
62+
for raw_dir in "$@"; do
63+
dir=$(printf '%s' "$raw_dir" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
64+
[ -z "$dir" ] && continue
65+
if [ -d "$dir" ]; then
66+
printf "[MOD_AUTO_SHARE] Sharing directory '%s' with sub-directories...\n" "$dir"
67+
find "$dir" -type d >> "$SHAREDDIR_TMP"
68+
else
69+
printf "[MOD_AUTO_SHARE] Skipping missing directory '%s'\n" "$dir"
70+
fi
6671
done
67-
chown ${AMULE_USER}:${AMULE_GROUP} "$SHAREDDIR_CONF"
72+
sort -u "$SHAREDDIR_TMP" > "$SHAREDDIR_CONF"
73+
rm -f "$SHAREDDIR_TMP"
74+
chown "${AMULE_USER}:${AMULE_GROUP}" "$SHAREDDIR_CONF"
75+
# Read-only file because aMule rewrites it on the first run
76+
chmod 444 "$SHAREDDIR_CONF"
6877
fi
6978
}
7079

@@ -354,9 +363,9 @@ if [ -n "${WEBUI_PWD}" ]; then
354363
fi
355364

356365
# Set permissions
357-
chown -R "${AMULE_UID}:${AMULE_GID}" ${AMULE_INCOMING}
358-
chown -R "${AMULE_UID}:${AMULE_GID}" ${AMULE_TEMP}
359-
chown -R "${AMULE_UID}:${AMULE_GID}" ${AMULE_HOME}
366+
chown -R "${AMULE_UID}:${AMULE_GID}" "${AMULE_INCOMING}"
367+
chown -R "${AMULE_UID}:${AMULE_GID}" "${AMULE_TEMP}"
368+
chown -R "${AMULE_UID}:${AMULE_GID}" "${AMULE_HOME}"
360369

361370
# Modifications / Fixes
362371
mod_auto_restart
@@ -375,4 +384,4 @@ while true; do
375384
break
376385
fi
377386
done
378-
exit $EXIT_CODE
387+
exit "$EXIT_CODE"

0 commit comments

Comments
 (0)