[type/__uci_commit] Fail when uci(1) reports errors
This commit is contained in:
parent
cc599dab15
commit
3ef638a611
1 changed files with 29 additions and 8 deletions
|
@ -45,16 +45,37 @@ then
|
||||||
exit 1
|
exit 1
|
||||||
fi >&2
|
fi >&2
|
||||||
|
|
||||||
rollback() {
|
check_errors() {
|
||||||
uci changes \\
|
# reads stdin and forwards non-empty lines to stderr.
|
||||||
| sed -e 's/\..*\$//' -e 's/^-//' \\
|
# returns 0 if stdin is empty, else 1.
|
||||||
| while read -r package
|
! grep -e . >&2
|
||||||
do
|
|
||||||
uci revert "\${package}"
|
|
||||||
done
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uci batch <<'EOF' && uci commit || rollback
|
commit() {
|
||||||
|
uci commit
|
||||||
|
}
|
||||||
|
|
||||||
|
rollback() {
|
||||||
|
echo >&2
|
||||||
|
echo 'An error occurred when trying to commit transaction ${transaction_name}!' >&2
|
||||||
|
|
||||||
|
uci changes \\
|
||||||
|
| sed -e 's/^-//' -e 's/\..*\$//' \\
|
||||||
|
| sort -u \\
|
||||||
|
| while read -r _package
|
||||||
|
do
|
||||||
|
uci revert "\${_package}"
|
||||||
|
echo "\${_package}" # for logging
|
||||||
|
done \\
|
||||||
|
| awk '
|
||||||
|
BEGIN { printf "Reverted changes in: " }
|
||||||
|
{ printf "%s%s", (FNR > 1 ? ", " : ""), \$0 }
|
||||||
|
END { printf "\\n" }' >&2
|
||||||
|
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
uci batch <<'EOF' 2>&1 | check_errors && commit || rollback
|
||||||
$(cat "${batchfile}")
|
$(cat "${batchfile}")
|
||||||
EOF
|
EOF
|
||||||
CODE
|
CODE
|
||||||
|
|
Loading…
Reference in a new issue