Skip to content

Commit 28cad53

Browse files
committed
added PUSER_COPY option to docker entrypiont setup for dirinit container
1 parent 7901eaf commit 28cad53

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

shared/bin/docker-uid-gid-setup.sh

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,30 @@ if [[ -n ${PUSER_MKDIR} ]]; then
123123
done
124124
fi
125125

126+
# If there are files that need to be copied that are explicitly specified, copy them here. format of $PUSER_COPY is:
127+
# source_path:destination_path
128+
# Multiple entries can be separated by semicolon.
129+
# Ownership of copied files will be set to PUID/PGID
130+
#
131+
# e.g.,
132+
# For the entry: /source/file.conf:/dest/file.conf;/source/dir:/dest/dir
133+
# Will copy /source/file.conf to /dest/file.conf and /source/dir to /dest/dir
134+
# and chown both to PUID:PGID
135+
if [[ -n ${PUSER_COPY} ]]; then
136+
IFS=';' read -ra ENTITIES <<< "${PUSER_COPY}"
137+
for ENTITY in "${ENTITIES[@]}"; do
138+
SRC="$(echo "${ENTITY}" | cut -d: -f1)"
139+
DST="$(echo "${ENTITY}" | cut -d: -f2-)"
140+
if [[ -n ${SRC} ]] && [[ -e "${SRC}" ]] && [[ -n ${DST} ]]; then
141+
# Create destination directory if it doesn't exist
142+
mkdir -p "$(dirname "${DST}")" 2>/dev/null
143+
cp -r "${SRC}" "${DST}" 2>/dev/null
144+
[[ -n ${PUID} ]] && chown -R -f ${PUID} "${DST}" 2>/dev/null
145+
[[ -n ${PGID} ]] && chown -R -f :${PGID} "${DST}" 2>/dev/null
146+
fi
147+
done
148+
fi
149+
126150
# if there is a trusted CA file or directory specified and openssl is available, handle it
127151
if [[ -n ${PUSER_CA_TRUST} ]] && command -v openssl >/dev/null 2>&1; then
128152
declare -a CA_FILES
@@ -209,4 +233,4 @@ if [[ ! -z "${ENTRYPOINT_CMD}" ]]; then
209233
"${ENTRYPOINT_CMD}" $(printf "%q " "${ENTRYPOINT_ARGS[@]}")
210234
fi
211235
fi
212-
EOF
236+
EOF

0 commit comments

Comments
 (0)