-#!/bin/bash
+#!/bin/bash -r
# We follow the GNU license recommendations at
# https://www.gnu.org/licenses/license-recommendations.en.html. They
# recommend that small programs, < 300 lines, be licensed under the
## Managed by Ansible, changes will be overwritten ##
-
-
set -eE -o pipefail
trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
+regex='^[a-z. ]*$'
+
# restricted ssh does not allow arguments, but they exist in this env variable.
-if [[ $SSH_ORIGINAL_COMMAND ]]; then
- set -- ${SSH_ORIGINAL_COMMAND#* }
-fi
+# The var comes with a leading space, remove it.
+args="${SSH_ORIGINAL_COMMAND#* }"
-if [[ $# != 2 ]]; then
- echo "error: bad argument" >&2; exit 1
+if [[ ! $args =~ $regex ]]; then
+ echo "error: bad argument. args=$args" >&2; exit 1
fi
-case "$1" in
- list|console|reboot|reset|start|destroy) true ;;
+arg1="${args%% *}"
+
+case "$arg1" in
+ list)
+ virsh list --name
+ exit 0
+ ;;
+ console|reboot|reset|start|destroy) true ;;
*)
echo "error: bad argument" >&2; exit 1
;;
esac
-case "$2" in
- *.savannah.gnu.org|debbugs2p.gnu.org|debbugs.gnu.org|emacsconfmedia0p.gnu.org|jitsi*.fsf.org|sourcehut.gnu.org)
+# just 2 args, so split the space.
+arg2="${args## *}"
+
+
+case "$arg2" in
+ *.savannah.gnu.org|debbugs2p.gnu.org|debbugs.gnu.org|emacsconfmedia0p.gnu.org|jitsi*.fsf.org|verandah.gnu.org)
true ;;
*)
echo "error: bad argument" >&2; exit 1
;;
esac
-virsh "$1" "$2"
+virsh "$arg1" "$arg2"