From bcdc33d33c2f6fdfd1877e85f28d221de1181995 Mon Sep 17 00:00:00 2001 From: Ahurac Date: Sun, 21 Jan 2024 00:20:51 +0100 Subject: [PATCH] diskpath : remplacement du script par pathof --- README.md | 5 ++--- bin/qemush | 15 +++++++++++---- qemu/bin/diskpath | 2 -- qemu/bin/pathof | 20 ++++++++++++++++++++ qemu/launchers/windows10 | 15 ++++++++++----- 5 files changed, 43 insertions(+), 14 deletions(-) delete mode 100755 qemu/bin/diskpath create mode 100755 qemu/bin/pathof diff --git a/README.md b/README.md index b632277..8c73099 100644 --- a/README.md +++ b/README.md @@ -51,8 +51,7 @@ need it - `screen` - for process supervision - `source-highlight` - for syntax highlighting when displaying launching scripts -- `diskpath` - see [Add `qemush` modules in -`~qemu/bin`](#add-qemush-modules-in-qemubin) +- `pathof` - see [Installation instructions](#installation-instructions) - any text editor - used for builtin function to edit launching scripts You can run `qemush depcheck` to check if all dependencies are met. @@ -91,7 +90,7 @@ by the `Makefile` for the installation process. ### Manual installation (what does the `Makefile` do) -- Create `images`, `launchers` and `bin` directories in `~qemu` +- Create `disks`, `launchers` and `bin` directories in `~qemu` - Copy `qemush` scripts parts from `qemu/bin` in `~qemu/bin` with mode `740` - Compile C programs from `src` in `~qemu/bin` with mode `740` diff --git a/bin/qemush b/bin/qemush index 5931e7e..546d450 100755 --- a/bin/qemush +++ b/bin/qemush @@ -13,9 +13,10 @@ exec_as() { exec_as qemu "$@" bin="${HOME}/launchers" -images="${HOME}/images" +images="${HOME}/disks" PATH="${bin}:${HOME}/bin:${PATH}" EDITOR="${EDITOR:-nvim}" +export QEMUSH_NAME alias ls='ls --color=auto' alias exec='exec ' if [ -t 1 ]; then @@ -59,7 +60,7 @@ error_usage() { } public_start() { - local vm_name="$1" + QEMUSH_NAME="$1" shift exec screen -S "$vm_name" "$vm_name" "$@" @@ -79,11 +80,17 @@ public_ls() { } public_diskadd() { - exec qemu-img create -f qcow2 "$(diskpath "$1")" "$2" + QEMUSH_NAME="$1" + shift + + exec qemu-img create -f qcow2 "$(pathof disk)" "$1" } public_diskrm() { - exec rm -vi -- "$(diskpath "$1")" + QEMUSH_NAME="$1" + shift + + exec rm -vi -- "$(pathof disk)" } public_diskls() { diff --git a/qemu/bin/diskpath b/qemu/bin/diskpath deleted file mode 100755 index 98e5dd7..0000000 --- a/qemu/bin/diskpath +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -printf '%s/%s.qcow2\n' ~/images "$1" diff --git a/qemu/bin/pathof b/qemu/bin/pathof new file mode 100755 index 0000000..d3bc759 --- /dev/null +++ b/qemu/bin/pathof @@ -0,0 +1,20 @@ +#!/bin/sh -e + +# Check if QEMUSH_NAME variable is initialized, abort if not +[ -n "$QEMUSH_NAME" ] + +# Choose the base dir to print according to argv[1] +case "$1" in + socket) + path=/run/qemush + ;; + disk) + path="${HOME}/disks" + ;; + *) + false + ;; +esac + +# Print the base dir and the name of the VM +printf %s/%s\\n "$path" "$QEMUSH_NAME" diff --git a/qemu/launchers/windows10 b/qemu/launchers/windows10 index 2c5d333..7a021e6 100755 --- a/qemu/launchers/windows10 +++ b/qemu/launchers/windows10 @@ -1,9 +1,14 @@ #!/bin/sh -x -name="$(basename "$0")" + +# Store VM name in environment variable +export QEMUSH_NAME +[ -z "$QEMUSH_NAME" ] && QEMUSH_NAME=$(basename "$0") + +# Launch the virtual machine exec kvm-spice \ - -monitor stdio \ - -drive file="$(diskpath "$name")",if=virtio \ - -net user,hostname="${name}" \ + -monitor "unix:$(pathof socket)" \ + -drive file="$(pathof disk)",if=virtio \ + -net user,hostname="${QEMUSH_NAME}" \ -usbdevice tablet \ - -name "$name" \ + -name "$QEMUSH_NAME" \ "$@"