diskpath : remplacement du script par pathof

This commit is contained in:
Ahurac 2024-01-21 00:20:51 +01:00
parent 8fccf7343f
commit bcdc33d33c
5 changed files with 43 additions and 14 deletions

View file

@ -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`

View file

@ -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() {

View file

@ -1,2 +0,0 @@
#!/bin/sh
printf '%s/%s.qcow2\n' ~/images "$1"

20
qemu/bin/pathof Executable file
View file

@ -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"

View file

@ -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" \
"$@"