| Matthias Andreas Benkard | 3cf43e3 | 2026-11-05 22:28:28 +0100 | [diff] [blame] | 1 | #! /bin/sh |
| 2 | # Runs inside the mailcow-conf-sync helper pod. Updates the config PVC |
| 3 | # mounted at /conf in place: |
| 4 | # |
| 5 | # - files in /tmp/changes that already exist: overwrite content only, |
| 6 | # keeping owner and mode, |
| 7 | # - new files: create, owned like their parent directory, |
| 8 | # - files listed in /tmp/deleted-files.txt: delete. |
| 9 | set -eu |
| 10 | |
| 11 | conf=/conf |
| 12 | changes=/tmp/changes |
| 13 | |
| 14 | cd "$changes" |
| 15 | find . -type f | while read -r f; do |
| 16 | f=${f#./} |
| 17 | dst=$conf/$f |
| 18 | if [ -e "$dst" ]; then |
| 19 | cat "$f" >"$dst" |
| 20 | echo "updated $f" |
| 21 | else |
| 22 | dir=$(dirname "$dst") |
| 23 | if [ ! -d "$dir" ]; then |
| 24 | parent=$dir |
| 25 | while [ ! -d "$parent" ]; do parent=$(dirname "$parent"); done |
| 26 | owner=$(stat -c %u:%g "$parent") |
| 27 | mkdir -p "$dir" |
| 28 | # Hand every newly created directory to the existing parent's owner. |
| 29 | d=$dir |
| 30 | while [ "$d" != "$parent" ]; do chown "$owner" "$d"; d=$(dirname "$d"); done |
| 31 | fi |
| 32 | cp "$f" "$dst" |
| 33 | chown "$(stat -c %u:%g "$dir")" "$dst" |
| 34 | chmod "$(stat -c %a "$f")" "$dst" |
| 35 | echo "created $f" |
| 36 | fi |
| 37 | done |
| 38 | |
| 39 | while read -r f; do |
| 40 | if [ -e "$conf/$f" ]; then |
| 41 | rm "$conf/$f" |
| 42 | echo "deleted $f" |
| 43 | fi |
| 44 | done </tmp/deleted-files.txt |