01_envfile.sh 1.4 KB

123456789101112131415161718192021222324252627282930
  1. #! /bin/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] Setting 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. # cat ${SECRETFILE} > ${STRIPFILE}
  19. cat $(${SECRETFILE} | sed "s/[^\w.-]+//g") > ${STRIPFILE}
  20. echo "[secret-init] Set ${STRIPFILE} to $(cat ${STRIPFILE})" # DEBUG - rm for prod!"
  21. echo "[secret-init] Success! ${STRIPFILE} set from ${FILENAME}"
  22. else
  23. echo "[secret-init] cannot find secret in ${FILENAME}"
  24. fi
  25. done