01_s6-secret-init.sh 1.3 KB

1234567891011121314151617181920212223242526272829
  1. #!/usr/bin/with-contenv bash
  2. # ref: https://github.com/linuxserver/docker-baseimage-alpine/blob/master/root/etc/cont-init.d/01-envfile
  3. # in s6, environmental variables are written as text files for s6 to monitor
  4. # seach through full-path filenames for files ending in "__FILE"
  5. for FILENAME in $(find /var/run/s6/container_environment/ | grep "__FILE$"); do
  6. echo "[secret-init] Evaluating ${FILENAME##*/} ..."
  7. # set SECRETFILE to the contents of the full-path textfile
  8. SECRETFILE=$(cat ${FILENAME})
  9. # SECRETFILE=${FILENAME}
  10. # echo "[secret-init] Set SECRETFILE to ${SECRETFILE}" # DEBUG - rm for prod!
  11. # if SECRETFILE exists / is not null
  12. if [[ -f ${SECRETFILE} ]]; then
  13. # strip the appended "__FILE" from environmental variable name ...
  14. STRIPFILE=$(echo ${FILENAME} | sed "s/__FILE//g")
  15. # echo "[secret-init] Set STRIPFILE to ${STRIPFILE}" # DEBUG - rm for prod!
  16. # ... and set value to contents of secretfile
  17. # since s6 uses text files, this is effectively "export ..."
  18. printf $(cat ${SECRETFILE}) > ${STRIPFILE}
  19. # echo "[secret-init] Set ${STRIPFILE##*/} to $(cat ${STRIPFILE})" # DEBUG - rm for prod!"
  20. echo "[secret-init] Success! ${STRIPFILE##*/} set from ${FILENAME##*/}"
  21. else
  22. echo "[secret-init] cannot find secret in ${FILENAME}"
  23. fi
  24. done