init-vm.sh 713 B

123456789101112131415161718192021222324252627282930
  1. #!/usr/bin/env bash
  2. # Create a fresh VM disk and copy the toolkit image into the VM directory.
  3. set -euo pipefail
  4. ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  5. VM_DIR="${VM_DIR:-$HOME/.HHD/PCLPoC-VM}"
  6. FORCE=0
  7. if [[ "${1:-}" == "--force" ]]; then
  8. FORCE=1
  9. fi
  10. if [[ ! -f "$ROOT/toolkit.img" ]]; then
  11. "$ROOT/build-toolkit.sh"
  12. fi
  13. if [[ -e "$VM_DIR/disk.qcow2" && "$FORCE" -ne 1 ]]; then
  14. echo "$VM_DIR/disk.qcow2 already exists; use --force to replace it" >&2
  15. exit 1
  16. fi
  17. mkdir -p "$VM_DIR"
  18. if [[ "$FORCE" -eq 1 ]]; then
  19. rm -f "$VM_DIR/disk.qcow2"
  20. fi
  21. qemu-img create -f qcow2 "$VM_DIR/disk.qcow2" 60G
  22. cp -f "$ROOT/toolkit.img" "$VM_DIR/toolkit.img"
  23. echo "VM_DIR: $VM_DIR"
  24. ls -lh "$VM_DIR"