nginx-proxy-manager/docker/rootfs/etc/cont-init.d/01_s6-secret-init.sh

30 lines
1.3 KiB
Bash
Raw Normal View History

2021-02-06 20:05:40 -05:00
#!/usr/bin/with-contenv bash
2021-02-04 11:25:26 -05:00
# ref: https://github.com/linuxserver/docker-baseimage-alpine/blob/master/root/etc/cont-init.d/01-envfile
# in s6, environmental variables are written as text files for s6 to monitor
2021-02-05 16:52:24 -05:00
# seach through full-path filenames for files ending in "__FILE"
for FILENAME in $(find /var/run/s6/container_environment/ | grep "__FILE$"); do
2021-02-06 20:05:40 -05:00
echo "[secret-init] Evaluating ${FILENAME##*/} ..."
2021-02-04 11:25:26 -05:00
2021-02-05 16:52:24 -05:00
# set SECRETFILE to the contents of the full-path textfile
2021-02-04 11:25:26 -05:00
SECRETFILE=$(cat ${FILENAME})
# SECRETFILE=${FILENAME}
2021-02-06 20:05:40 -05:00
# echo "[secret-init] Set SECRETFILE to ${SECRETFILE}" # DEBUG - rm for prod!
2021-02-04 11:25:26 -05:00
# if SECRETFILE exists / is not null
if [[ -f ${SECRETFILE} ]]; then
# strip the appended "__FILE" from environmental variable name ...
2021-02-05 16:52:24 -05:00
STRIPFILE=$(echo ${FILENAME} | sed "s/__FILE//g")
2021-02-06 20:05:40 -05:00
# echo "[secret-init] Set STRIPFILE to ${STRIPFILE}" # DEBUG - rm for prod!
2021-02-05 16:52:24 -05:00
2021-02-04 11:25:26 -05:00
# ... and set value to contents of secretfile
# since s6 uses text files, this is effectively "export ..."
2021-02-06 20:05:40 -05:00
printf $(cat ${SECRETFILE}) > ${STRIPFILE}
# echo "[secret-init] Set ${STRIPFILE##*/} to $(cat ${STRIPFILE})" # DEBUG - rm for prod!"
echo "[secret-init] Success! ${STRIPFILE##*/} set from ${FILENAME##*/}"
2021-02-04 11:25:26 -05:00
else
2021-02-05 16:52:24 -05:00
echo "[secret-init] cannot find secret in ${FILENAME}"
2021-02-04 11:25:26 -05:00
fi
done