Compare commits

..

No commits in common. "c35664f7759e8a74019b6a1a9146c4b0e7f23430" and "9cd66345280c151292c6a1660dd62b983a203fd1" have entirely different histories.

2 changed files with 31 additions and 39 deletions

View file

@ -39,23 +39,18 @@ 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
- A POSIX compliant shell - `bash` (POSIX mode), `*ash`, `*ksh` are POSIX shells - `bash` - the `qemush` interpreter
- `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

View file

@ -1,5 +1,5 @@
#!/usr/bin/env sh #!/usr/bin/env bash
# version=0.10.0 # version=0.8.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,6 +10,7 @@ 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
@ -26,19 +27,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} do <shell code> - run shell input as user qemu
${name} spice <running VM> [<TCP port>] - expose a SPICE socket to TCP
${name} help - show this help ${name} help - show this help
${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
EOF EOF
} }
@ -68,19 +69,9 @@ 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 export QEMUSH_NAME="$1"
if [ -n "$1" ]; then exec socat -,rawer,escape=15 "UNIX-CONNECT:$(pathof socket)"
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
@ -202,17 +193,23 @@ public_spice() {
socat TCP-LISTEN:"${port},reuseaddr,fork" UNIX-CLIENT:"$(pathof spice)" socat TCP-LISTEN:"${port},reuseaddr,fork" UNIX-CLIENT:"$(pathof spice)"
} }
case "$1" in function_exists() {
"") declare -F \
public_running | cut -d \ -f 3- \
;; | grep '^public_' \
running|ls|add|edit|start|attach|rm|diskls|diskadd|diskrm|shell|do|spice|help) | sed 's/^public_//' \
function=$1 | grep -q "^${1}\$"
shift }
"public_${function}" "$@" # Defauts to `active` if no function is supplied; else checks for a public
;; # function named after the argument; else fails
*) if [ -z "$1" ]; then
error_usage public_running
;; elif function_exists "$1"; then
esac function=$1
shift
"public_${function}" "$@"
else
error_usage
fi