share-certs.sh 806 B

12345678910111213141516171819202122232425262728
  1. #!/bin/bash
  2. #---Objective---
  3. # Replicates keys to another directory and make them world readable
  4. # so other containers can make use of them.
  5. #---Context---
  6. # acme-companion sets the root user as the key owner
  7. # and removes read permission for other users.
  8. # Other containers run under unprivileged user IDs, e.g. 1000 or 9000,
  9. # and cannot access the keys.
  10. # Define source and destination directories
  11. src_dir="/etc/nginx/certs/"
  12. dest_dir="/etc/nginx/certs-shared/"
  13. mkdir -p $dest_dir
  14. # Copy the files and update permissions
  15. cp --dereference --update -p $src_dir*.key $src_dir*.crt $dest_dir
  16. chmod -R a+r $dest_dir
  17. # Delete files in the destination that are not in the source
  18. for file in $dest_dir*; do
  19. base_file=$(basename "$file")
  20. if [[ ! -e $src_dir$base_file ]]; then
  21. rm "$file"
  22. fi
  23. done