Compare commits
7 commits
9cd6634528
...
c35664f775
Author | SHA1 | Date | |
---|---|---|---|
c35664f775 | |||
31557740d4 | |||
fd12744058 | |||
ae45b2e057 | |||
8e96494fed | |||
50fba776c8 | |||
7c4e645fa0 |
2 changed files with 39 additions and 31 deletions
|
@ -39,18 +39,23 @@ on disk
|
||||||
- **Process detachment**: you can log out and have your virtual machines
|
- **Process detachment**: you can log out and have your virtual machines
|
||||||
still running, control them via Unix sockets
|
still running, control them via Unix sockets
|
||||||
|
|
||||||
|
## Is it better than `libvirt` ?
|
||||||
|
|
||||||
|
No. `qemush` and `libvirt` are for different use cases. `qemush` will allow you to spin up virtual machines really fast and with as little setup as possible, and aims to be nothing more than a QEMU wrapper, while `libvirt` will offer better out-of-the-box experience, with already existing pre-configurations, associated tools like the `virt-manager` GUI and a friendlier process supervision. You should use `qemush` if you care about controlling every aspect of your virtual machines, and are already used to using bare QEMU without an abstraction layer.
|
||||||
|
|
||||||
## Dependencies
|
## Dependencies
|
||||||
|
|
||||||
|
From version 0.9.0, `qemush` is written in pure POSIX shell! The previous dependency on `bash` was removed in consequence.
|
||||||
|
|
||||||
All dependencies are common packages for a distribution, you'll be able to
|
All dependencies are common packages for a distribution, you'll be able to
|
||||||
grab them from your favorite packages sources.
|
grab them from your favorite packages sources.
|
||||||
|
|
||||||
- `qemu` - this is literally a QEMU wrapper so there's a chance you'll
|
- `qemu` - this is literally a QEMU wrapper so there's a chance you'll
|
||||||
need it
|
need it
|
||||||
- `bash` - the `qemush` interpreter
|
- A POSIX compliant shell - `bash` (POSIX mode), `*ash`, `*ksh` are POSIX shells
|
||||||
- `coreutils` - used for basic OS operations
|
- `coreutils` - used for basic OS operations
|
||||||
- `sudo` - execute commands as `qemu`
|
- `sudo` - execute commands as `qemu`
|
||||||
- `socat` - monitor machines via Unix sockets
|
- `socat` - monitor machines via Unix sockets
|
||||||
- `pathof` - see [Installation instructions](#installation-instructions)
|
|
||||||
- any text editor - used for builtin function to edit launching scripts
|
- any text editor - used for builtin function to edit launching scripts
|
||||||
|
|
||||||
## Installation instructions
|
## Installation instructions
|
||||||
|
|
61
bin/qemush
61
bin/qemush
|
@ -1,5 +1,5 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env sh
|
||||||
# version=0.8.0
|
# version=0.10.0
|
||||||
|
|
||||||
# Re-exec the script as qemu via sudo (only if needed)
|
# Re-exec the script as qemu via sudo (only if needed)
|
||||||
[ "$(whoami)" != qemu ] && exec sudo -E -H -u qemu -- "$0" "$@"
|
[ "$(whoami)" != qemu ] && exec sudo -E -H -u qemu -- "$0" "$@"
|
||||||
|
@ -10,7 +10,6 @@ PATH="${HOME}/launchers:${HOME}/bin:${PATH}"
|
||||||
# Aliases
|
# Aliases
|
||||||
alias ls='ls --color=auto'
|
alias ls='ls --color=auto'
|
||||||
alias exec='exec '
|
alias exec='exec '
|
||||||
shopt -s expand_aliases
|
|
||||||
|
|
||||||
# Set a restrictive umask to make sure qemu user files are private
|
# Set a restrictive umask to make sure qemu user files are private
|
||||||
umask 7027
|
umask 7027
|
||||||
|
@ -27,19 +26,19 @@ public_help() {
|
||||||
exec cat << EOF
|
exec cat << EOF
|
||||||
${name}: usage:
|
${name}: usage:
|
||||||
${name} running - (default behaviour) list running VMs
|
${name} running - (default behaviour) list running VMs
|
||||||
|
${name} ls - list available VMs
|
||||||
|
${name} add <path to script> [<VM name>] - add a launching script
|
||||||
|
${name} edit <VM name> - edit VM launching script
|
||||||
${name} start <VM name> - start a VM
|
${name} start <VM name> - start a VM
|
||||||
${name} attach <VM name> - attach to the VM monitor socket
|
${name} attach <VM name> - attach to the VM monitor socket
|
||||||
${name} ls - list available VMs
|
|
||||||
${name} edit <VM name> - edit VM launching script
|
|
||||||
${name} rm <VM name> - delete launch script
|
${name} rm <VM name> - delete launch script
|
||||||
${name} diskls - list available disk images
|
${name} diskls - list available disk images
|
||||||
${name} diskadd <disk name> <size> - create a disk image
|
${name} diskadd <disk name> <size> - create a disk image
|
||||||
${name} diskrm <disk name> - delete disk image
|
${name} diskrm <disk name> - delete disk image
|
||||||
${name} shell - start a shell as user qemu
|
${name} shell - start a shell as user qemu
|
||||||
${name} help - show this help
|
${name} do <shell code> - run shell input as user qemu
|
||||||
${name} add <path to script> [<VM name>] - add a launching script
|
|
||||||
${name} do <command> - run shell input as user qemu
|
|
||||||
${name} spice <running VM> [<TCP port>] - expose a SPICE socket to TCP
|
${name} spice <running VM> [<TCP port>] - expose a SPICE socket to TCP
|
||||||
|
${name} help - show this help
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,9 +68,19 @@ public_start() {
|
||||||
# Attach to a running virtual machine output, the latest opened if no
|
# Attach to a running virtual machine output, the latest opened if no
|
||||||
# argument is provided
|
# argument is provided
|
||||||
public_attach() {
|
public_attach() {
|
||||||
export QEMUSH_NAME="$1"
|
export QEMUSH_NAME
|
||||||
|
|
||||||
exec socat -,rawer,escape=15 "UNIX-CONNECT:$(pathof socket)"
|
if [ -n "$1" ]; then
|
||||||
|
QEMUSH_NAME=$1
|
||||||
|
socket_path=$(pathof socket)
|
||||||
|
else
|
||||||
|
socket_path=$(find ~/sockets/monitors -type s -printf '%T@ %p\n' | sort -r -n | head -1 | cut -d \ -f 2-)
|
||||||
|
QEMUSH_NAME=$(basename "$socket_path")
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf 'Attaching to \033[1m%s\033[0m, escape with C-d (EOF)\n' "$QEMUSH_NAME"
|
||||||
|
socat -,rawer,escape=4 "UNIX-CONNECT:${socket_path}"
|
||||||
|
echo
|
||||||
}
|
}
|
||||||
|
|
||||||
# List running virtual machines
|
# List running virtual machines
|
||||||
|
@ -193,23 +202,17 @@ public_spice() {
|
||||||
socat TCP-LISTEN:"${port},reuseaddr,fork" UNIX-CLIENT:"$(pathof spice)"
|
socat TCP-LISTEN:"${port},reuseaddr,fork" UNIX-CLIENT:"$(pathof spice)"
|
||||||
}
|
}
|
||||||
|
|
||||||
function_exists() {
|
case "$1" in
|
||||||
declare -F \
|
"")
|
||||||
| cut -d \ -f 3- \
|
public_running
|
||||||
| grep '^public_' \
|
;;
|
||||||
| sed 's/^public_//' \
|
running|ls|add|edit|start|attach|rm|diskls|diskadd|diskrm|shell|do|spice|help)
|
||||||
| grep -q "^${1}\$"
|
function=$1
|
||||||
}
|
shift
|
||||||
|
|
||||||
# Defauts to `active` if no function is supplied; else checks for a public
|
"public_${function}" "$@"
|
||||||
# function named after the argument; else fails
|
;;
|
||||||
if [ -z "$1" ]; then
|
*)
|
||||||
public_running
|
error_usage
|
||||||
elif function_exists "$1"; then
|
;;
|
||||||
function=$1
|
esac
|
||||||
shift
|
|
||||||
|
|
||||||
"public_${function}" "$@"
|
|
||||||
else
|
|
||||||
error_usage
|
|
||||||
fi
|
|
||||||
|
|
Loading…
Reference in a new issue