mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 06:21:27 +00:00
improve error handling for [run-command-as] helper
This commit is contained in:
parent
027f858d85
commit
5a43d7a65d
1 changed files with 9 additions and 0 deletions
|
@ -91,20 +91,29 @@ function run-command-as()
|
||||||
|
|
||||||
log-info-stderr "${notice_message_color}👷 Running [${*}] as [${target_user}]${color_clear}"
|
log-info-stderr "${notice_message_color}👷 Running [${*}] as [${target_user}]${color_clear}"
|
||||||
|
|
||||||
|
# disable error on exit behavior temporarily while we run the command
|
||||||
|
set +e
|
||||||
|
|
||||||
if [[ ${target_user} != "root" ]]; then
|
if [[ ${target_user} != "root" ]]; then
|
||||||
stream-prefix-command-output su --preserve-environment "${target_user}" --shell /bin/bash --command "${*}"
|
stream-prefix-command-output su --preserve-environment "${target_user}" --shell /bin/bash --command "${*}"
|
||||||
else
|
else
|
||||||
stream-prefix-command-output "${@}"
|
stream-prefix-command-output "${@}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# capture exit code
|
||||||
exit_code=$?
|
exit_code=$?
|
||||||
|
|
||||||
|
# re-enable exit code handling
|
||||||
|
set -e
|
||||||
|
|
||||||
if [[ $exit_code != 0 ]]; then
|
if [[ $exit_code != 0 ]]; then
|
||||||
log-error "${error_message_color}❌ Error!${color_clear}"
|
log-error "${error_message_color}❌ Error!${color_clear}"
|
||||||
|
|
||||||
return "$exit_code"
|
return "$exit_code"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
log-info-stderr "${success_message_color}✅ OK!${color_clear}"
|
log-info-stderr "${success_message_color}✅ OK!${color_clear}"
|
||||||
|
|
||||||
return "$exit_code"
|
return "$exit_code"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue