mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-12-22 13:03:16 +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}"
|
||||
|
||||
# disable error on exit behavior temporarily while we run the command
|
||||
set +e
|
||||
|
||||
if [[ ${target_user} != "root" ]]; then
|
||||
stream-prefix-command-output su --preserve-environment "${target_user}" --shell /bin/bash --command "${*}"
|
||||
else
|
||||
stream-prefix-command-output "${@}"
|
||||
fi
|
||||
|
||||
# capture exit code
|
||||
exit_code=$?
|
||||
|
||||
# re-enable exit code handling
|
||||
set -e
|
||||
|
||||
if [[ $exit_code != 0 ]]; then
|
||||
log-error "${error_message_color}❌ Error!${color_clear}"
|
||||
|
||||
return "$exit_code"
|
||||
fi
|
||||
|
||||
log-info-stderr "${success_message_color}✅ OK!${color_clear}"
|
||||
|
||||
return "$exit_code"
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue