qemush : suppression de la variable function
, suppression d'un shift inutile
This commit is contained in:
parent
0f6582be0a
commit
9cd6634528
1 changed files with 14 additions and 6 deletions
20
bin/qemush
20
bin/qemush
|
@ -1,5 +1,5 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# version=0.7.0
|
# version=0.8.0
|
||||||
|
|
||||||
# Re-exec the script as qemu via sudo (only if needed)
|
# Re-exec the script as qemu via sudo (only if needed)
|
||||||
[ "$(whoami)" != qemu ] && exec sudo -E -H -u qemu -- "$0" "$@"
|
[ "$(whoami)" != qemu ] && exec sudo -E -H -u qemu -- "$0" "$@"
|
||||||
|
@ -9,6 +9,7 @@ PATH="${HOME}/launchers:${HOME}/bin:${PATH}"
|
||||||
|
|
||||||
# Aliases
|
# Aliases
|
||||||
alias ls='ls --color=auto'
|
alias ls='ls --color=auto'
|
||||||
|
alias exec='exec '
|
||||||
shopt -s expand_aliases
|
shopt -s expand_aliases
|
||||||
|
|
||||||
# Set a restrictive umask to make sure qemu user files are private
|
# Set a restrictive umask to make sure qemu user files are private
|
||||||
|
@ -192,15 +193,22 @@ public_spice() {
|
||||||
socat TCP-LISTEN:"${port},reuseaddr,fork" UNIX-CLIENT:"$(pathof spice)"
|
socat TCP-LISTEN:"${port},reuseaddr,fork" UNIX-CLIENT:"$(pathof spice)"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Retrieve user requested function
|
function_exists() {
|
||||||
function="$1"
|
declare -F \
|
||||||
shift
|
| cut -d \ -f 3- \
|
||||||
|
| grep '^public_' \
|
||||||
|
| sed 's/^public_//' \
|
||||||
|
| grep -q "^${1}\$"
|
||||||
|
}
|
||||||
|
|
||||||
# Defauts to `active` if no function is supplied; else checks for a public
|
# Defauts to `active` if no function is supplied; else checks for a public
|
||||||
# function named after the argument; else fails
|
# function named after the argument; else fails
|
||||||
if [ -z "$function" ]; then
|
if [ -z "$1" ]; then
|
||||||
public_running
|
public_running
|
||||||
elif declare -F | cut -d \ -f 3- | grep '^public_' | sed 's/^public_//' | grep -q "^${function}$"; then
|
elif function_exists "$1"; then
|
||||||
|
function=$1
|
||||||
|
shift
|
||||||
|
|
||||||
"public_${function}" "$@"
|
"public_${function}" "$@"
|
||||||
else
|
else
|
||||||
error_usage
|
error_usage
|
||||||
|
|
Loading…
Reference in a new issue