Fix permission denied when --force overwrites root-owned config files
When Docker containers write config files (e.g. searxng/settings.yml), those files end up owned by root. write_if_new now falls back to sudo tee when the destination file exists but is not writable. https://claude.ai/code/session_012gDnantBmFTWZGCiKyjazx
This commit is contained in:
@@ -535,7 +535,11 @@ write_if_new() {
|
||||
local dest="$1"
|
||||
local content; content=$(cat)
|
||||
if [[ ! -f "$dest" ]] || $FORCE; then
|
||||
printf '%s\n' "$content" > "$dest"
|
||||
if [[ -e "$dest" ]] && [[ ! -w "$dest" ]]; then
|
||||
printf '%s\n' "$content" | sudo tee "$dest" > /dev/null
|
||||
else
|
||||
printf '%s\n' "$content" > "$dest"
|
||||
fi
|
||||
ok "Wrote $(basename "$dest")"
|
||||
else
|
||||
info "Kept $(basename "$dest") (--force to overwrite)"
|
||||
|
||||
Reference in New Issue
Block a user