Browse Source

fix: [vps] make ``nextcloud upgrade`` change ``compose.yml`` in more scenarii

Signed-off-by: Valentin Lab <valentin.lab@kalysto.org>
rc1
Valentin Lab 2 years ago
parent
commit
feebbfbfe7
  1. 41
      bin/vps

41
bin/vps

@ -87,45 +87,56 @@ compose:get-compose-yml() {
decorator._mangle_fn compose:get-compose-yml
export -f compose:get-compose-yml
compose:has-container-project-myc() {
local projects
projects=$(docker:running-container-projects) || return 1
[[ $'\n'"$projects"$'\n' == *$'\n'"myc"$'\n'* ]]
}
compose:file:value-change() {
local key="$1" value="$2" first=1 count=0 diff=""
local key="$1" value="$2"
yaml:file:value-change "$(compose:get-compose-yml)" "$key" "$value" || exit 1
}
export -f compose:file:value-change
yaml:file:value-change() {
local file="$1" key="$2" value="$3" first=1 count=0 diff=""
(
COMPOSE_YML_FILE=$(compose:get-compose-yml) || exit 1
export COMPOSE_YML_FILE
cd "${COMPOSE_YML_FILE%/*}"
cd "${file%/*}"
while read-0 hunk; do
if [ -n "$first" ]; then
diff+="$hunk"
first=
continue
fi
[[ "$hunk" =~ $'\n'"+"[[:space:]]+"${key##*.}:" ]] && {
if [[ "$hunk" =~ $'\n'"+"[[:space:]]+"${key##*.}:" ]]; then
((count++))
diff+="$hunk" >&2
}
else
:
# echo "discarding:" >&2
# e "$hunk" | prefix " | " >&2
fi
done < <(
export DEBUG=
settmpdir YQ_TEMP
cp "${COMPOSE_YML_FILE}" "$YQ_TEMP/compose.yml" &&
cp "${file}" "$YQ_TEMP/compose.yml" &&
yq -i ".${key} = \"${value}\"" "$YQ_TEMP/compose.yml" &&
diff -u1 "${COMPOSE_YML_FILE}" "$YQ_TEMP/compose.yml" |
sed -r "s/^(@@.*)$/\x00\1/g;s%^(\+\+\+) [^\t]+%\1 ${COMPOSE_YML_FILE}%g"
sed -ri 's/^([^# ])/\n\0/g' "$YQ_TEMP/compose.yml" &&
diff -u0 -Z "${file}" "$YQ_TEMP/compose.yml" |
sed -r "s/^(@@.*)$/\x00\1/g;s%^(\+\+\+) [^\t]+%\1 ${file}%g"
printf "\0"
)
if [[ "$count" == 0 ]]; then
err "No change made to 'compose.yml'."
err "No change made to '$file'."
return 1
fi
if [[ "$count" != 1 ]]; then
err "compose file change request seems dubious and was refused."
if [ -n "$DEBUG" ]; then
e "$diff" | prefix " | "
fi
err "compose file change request seems dubious and was refused:"
e "$diff" | prefix " | " >&2
return 1
fi
echo Applying: >&2
@ -133,7 +144,7 @@ compose:file:value-change() {
patch <<<"$diff"
) || exit 1
}
export -f compose:file:value-change
export -f yaml:file:value-change
type:is-mailcow() {

Loading…
Cancel
Save