Advertisement
Guest User

Qemu Script

a guest
Jan 14th, 2023
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.03 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # Author: SharkWipf
  4. #
  5. # Copy this file to /etc/libvirt/hooks, make sure it's called "qemu".
  6. # After this file is installed, restart libvirt.
  7. # From now on, you can easily add per-guest qemu hooks.
  8. # Add your hooks in /etc/libvirt/hooks/qemu.d/vm_name/hook_name/state_name.
  9. # For a list of available hooks, please refer to https://www.libvirt.org/hooks.html
  10. #
  11.  
  12. echo "runngin vm with hooks : $1; $2; $3; $4"
  13. GUEST_NAME="$1"
  14. HOOK_NAME="$2"
  15. STATE_NAME="$3"
  16. MISC="${@:4}"
  17.  
  18. BASEDIR="$(dirname $0)"
  19.  
  20. HOOKPATH="$BASEDIR/qemu.d/$GUEST_NAME/$HOOK_NAME/$STATE_NAME"
  21.  
  22. set -e # If a script exits with an error, we should as well.
  23.  
  24. # check if it's a non-empty executable file
  25. if [ -f "$HOOKPATH" ] && [ -s "$HOOKPATH" ] && [ -x "$HOOKPATH" ]; then
  26.     eval \"$HOOKPATH\" "$@"
  27. elif [ -d "$HOOKPATH" ]; then
  28.     while read file; do
  29.         # check for null string
  30.         if [ ! -z "$file" ]; then
  31.           eval \"$file\" "$@"
  32.         fi
  33.     done <<< "$(find -L "$HOOKPATH" -maxdepth 1 -type f -executable -print;)"
  34. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement