diff options
author | Awnrt <roman.levikoff@gmail.com> | 2024-04-30 00:24:08 +0300 |
---|---|---|
committer | Awnrt <roman.levikoff@gmail.com> | 2024-04-30 00:24:08 +0300 |
commit | d35d66a53af7d55b3f0ef86c42a910e968f754da (patch) | |
tree | 95c2268cc15125134efb92e387ec48bc897d077d /Hooks/qemu | |
parent | bad1ffed05c49b452da3d120687e4d47dbf36dbe (diff) |
upload
Diffstat (limited to 'Hooks/qemu')
-rw-r--r-- | Hooks/qemu | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/Hooks/qemu b/Hooks/qemu new file mode 100644 index 0000000..79203c7 --- /dev/null +++ b/Hooks/qemu @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +# +# Author: SharkWipf +# +# Copy this file to /etc/libvirt/hooks, make sure it's called "qemu". +# After this file is installed, restart libvirt. +# From now on, you can easily add per-guest qemu hooks. +# Add your hooks in /etc/libvirt/hooks/qemu.d/vm_name/hook_name/state_name. +# For a list of available hooks, please refer to https://www.libvirt.org/hooks.html +# + +GUEST_NAME="$1" +HOOK_NAME="$2" +STATE_NAME="$3" +MISC="${@:4}" + +BASEDIR="$(dirname $0)" + +HOOKPATH="$BASEDIR/qemu.d/$GUEST_NAME/$HOOK_NAME/$STATE_NAME" + +set -e # If a script exits with an error, we should as well. + +# check if it's a non-empty executable file +if [ -f "$HOOKPATH" ] && [ -s "$HOOKPATH" ] && [ -x "$HOOKPATH" ]; then + eval \"$HOOKPATH\" "$@" +elif [ -d "$HOOKPATH" ]; then + while read file; do + # check for null string + if [ ! -z "$file" ]; then + eval \"$file\" "$@" + fi + done <<< "$(find -L "$HOOKPATH" -maxdepth 1 -type f -executable -print;)" +fi + |