imporved option parsing and GUI detection
This commit is contained in:
parent
a8d4304076
commit
67cbc09f43
1 changed files with 20 additions and 4 deletions
|
@ -44,7 +44,7 @@ log() {
|
||||||
|
|
||||||
if [[ -t 1 ]] && $gui && [[ -n $(type -p zenity) ]] ; then
|
if [[ -t 1 ]] && $gui && [[ -n $(type -p zenity) ]] ; then
|
||||||
case "$level" in
|
case "$level" in
|
||||||
ERROR)
|
ERROR|WARNING)
|
||||||
zenity --error --text="$msg"
|
zenity --error --text="$msg"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
|
@ -58,6 +58,10 @@ error() {
|
||||||
log ERROR "$@"
|
log ERROR "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
warning() {
|
||||||
|
log WARNING "$@"
|
||||||
|
}
|
||||||
|
|
||||||
info() {
|
info() {
|
||||||
log INFO "$@"
|
log INFO "$@"
|
||||||
}
|
}
|
||||||
|
@ -447,9 +451,16 @@ do_stop() {
|
||||||
# Arguments
|
# Arguments
|
||||||
|
|
||||||
operation=
|
operation=
|
||||||
|
no_more_options=false
|
||||||
|
|
||||||
for arg in "$@" ; do
|
for arg in "$@" ; do
|
||||||
case "$arg" in
|
case "$arg" in
|
||||||
|
--)
|
||||||
|
no_more_options=true
|
||||||
|
;;
|
||||||
|
--*)
|
||||||
|
"$no_more_options" && { gui=false error "Option arguments may not preceed non-option arguments." ; exit 1 ; }
|
||||||
|
;;&
|
||||||
--debug)
|
--debug)
|
||||||
debug_cmdline=true
|
debug_cmdline=true
|
||||||
;;
|
;;
|
||||||
|
@ -460,11 +471,11 @@ for arg in "$@" ; do
|
||||||
help_cmdline=true
|
help_cmdline=true
|
||||||
;;
|
;;
|
||||||
start|stop|restart|setup|status)
|
start|stop|restart|setup|status)
|
||||||
[[ -z $operation ]] || { error "Multiple operations are not supported." ; exit 1 ; }
|
[[ -z $operation ]] || { gui=false error "Multiple operations are not supported." ; exit 1 ; }
|
||||||
operation=$arg
|
operation=$arg
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
error "Unsupported argument (try \"--help\")"
|
gui=false error "Unsupported argument (try \"--help\")"
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
@ -489,6 +500,12 @@ fi
|
||||||
|
|
||||||
if [[ $gui_cmdline = false ]] ; then
|
if [[ $gui_cmdline = false ]] ; then
|
||||||
gui=false
|
gui=false
|
||||||
|
elif [[ -z $(type -p zenity) ]] ; then
|
||||||
|
gui=false
|
||||||
|
warning "Disabling GUI support, because command \"zenity\" was not found."
|
||||||
|
elif ! [[ -v DISPLAY ]] && ! [[ -v XDG_SESSION_TYPE ]] ; then
|
||||||
|
gui=false
|
||||||
|
warning "Disabling GUI support, because neither \"DISPLAY\" not \"XDG_SESSION_TYPE\ is set."
|
||||||
else
|
else
|
||||||
gui=true
|
gui=true
|
||||||
fi
|
fi
|
||||||
|
@ -523,7 +540,6 @@ else
|
||||||
fi
|
fi
|
||||||
|
|
||||||
required_cmds=( jq pactl ssh )
|
required_cmds=( jq pactl ssh )
|
||||||
"$gui" && required_cmds+=( zenity )
|
|
||||||
|
|
||||||
for exe in "${required_cmds[@]}" ; do
|
for exe in "${required_cmds[@]}" ; do
|
||||||
if [[ -z $(type -p "$exe") ]] ; then
|
if [[ -z $(type -p "$exe") ]] ; then
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue