Revised exit status generation.
This commit is contained in:
parent
f3dd1edb12
commit
dd9231f834
1 changed files with 23 additions and 7 deletions
30
wled
30
wled
|
@ -10,6 +10,10 @@ NAME="wled.sh"
|
||||||
COMMAND="wled"
|
COMMAND="wled"
|
||||||
VERSION="0.1.2"
|
VERSION="0.1.2"
|
||||||
|
|
||||||
|
# Make the exit status of command pipelines the status of the last command
|
||||||
|
# with non-zero exit status - if supported by this shell.
|
||||||
|
(set -o pipefail 2>/dev/null) && set -o pipefail
|
||||||
|
|
||||||
print_usage() {
|
print_usage() {
|
||||||
echo "\
|
echo "\
|
||||||
Usage: $COMMAND -f(norcenter)|-w(wohnzimmer)|-a(ll) [on|off]
|
Usage: $COMMAND -f(norcenter)|-w(wohnzimmer)|-a(ll) [on|off]
|
||||||
|
@ -29,7 +33,13 @@ commands:
|
||||||
on|off switch on/off
|
on|off switch on/off
|
||||||
[1-17] switch preset
|
[1-17] switch preset
|
||||||
l, list list presets
|
l, list list presets
|
||||||
-b,--brightness [1-255] set brightness"
|
-b,--brightness [1-255] set brightness
|
||||||
|
|
||||||
|
exit status:
|
||||||
|
0 no failure
|
||||||
|
1 operating error
|
||||||
|
2 child command error
|
||||||
|
4 unexpected API response"
|
||||||
}
|
}
|
||||||
|
|
||||||
curl_fetch() {
|
curl_fetch() {
|
||||||
|
@ -54,6 +64,7 @@ active_preset() {
|
||||||
arg_inst="$1"
|
arg_inst="$1"
|
||||||
arg_cmnd="$2"
|
arg_cmnd="$2"
|
||||||
arg_param="$3"
|
arg_param="$3"
|
||||||
|
exit_code=0
|
||||||
|
|
||||||
# Clear positional arguments.
|
# Clear positional arguments.
|
||||||
set --
|
set --
|
||||||
|
@ -132,6 +143,7 @@ for wled_host; do
|
||||||
# Prepend description and mark active preset.
|
# Prepend description and mark active preset.
|
||||||
sed --sandbox -e "1i\\Presets on $wled_host:" \
|
sed --sandbox -e "1i\\Presets on $wled_host:" \
|
||||||
-e "s/^ \?$active_ps:.*/& */"
|
-e "s/^ \?$active_ps:.*/& */"
|
||||||
|
|
||||||
;;
|
;;
|
||||||
"") # Missing command.
|
"") # Missing command.
|
||||||
echo "Error: missing command." >&2
|
echo "Error: missing command." >&2
|
||||||
|
@ -145,15 +157,19 @@ for wled_host; do
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# Check curl exit status
|
# Check curl (or maybe sed) exit status
|
||||||
curl_exit=$?
|
child_exit=$?
|
||||||
if test $curl_exit -ne 0; then
|
if test $child_exit -ne 0; then
|
||||||
echo "Error: curl exited with exit code $curl_exit." >&2
|
echo "Error: curl or sed exited with exit code $child_exit." >&2
|
||||||
|
exit_code=$((exit_code|2))
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check API responce.
|
# Check API response.
|
||||||
if test -n "$api_resp" && echo "$api_resp" | grep -qv '{\s*"success"\s*:\s*true\s*}'; then
|
if test -n "$api_resp" && echo "$api_resp" | grep -qv '{\s*"success"\s*:\s*true\s*}'; then
|
||||||
echo "Warning: unexpected responce from WLED API." >&2
|
echo "Warning: unexpected response from WLED API." >&2
|
||||||
|
exit_code=$((exit_code|4))
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
exit $exit_code
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue