Compare commits

..

No commits in common. "37a1ed9296e871c7333afd0f19ccccaa79c85c49" and "849f6de9bd5761cdc5a64469671614c3c495bf92" have entirely different histories.

2 changed files with 27 additions and 28 deletions

View file

@ -47,7 +47,8 @@ need it
- `bash` - the `qemush` interpreter
- `coreutils` - used for basic OS operations
- `sudo` - execute commands as `qemu`
- `socat` - monitor machines via Unix sockets
- `source-highlight` - for syntax highlighting when displaying launching
scripts
- `diskpath` and `sockpath` - see [Installation
instructions](#installation-instructions)
- any text editor - used for builtin function to edit launching scripts

View file

@ -15,14 +15,24 @@ exec_as() {
# Exec the script as qemu
exec_as qemu "$@"
# Directories used in the program
bin="${HOME}/launchers"
images="${HOME}/disks"
sockets="${HOME}/sockets"
# Environment
PATH="${HOME}/launchers:${HOME}/bin:${PATH}"
PATH="${bin}:${HOME}/bin:${PATH}"
EDITOR="${EDITOR:-nvim}"
export QEMUSH_NAME
# Aliases
alias ls='ls --color=auto'
alias exec='exec '
if [ -t 1 ]; then
alias pretty_cat='source-highlight --failsafe -f esc --style-file=esc.style -i'
else
alias pretty_cat=cat
fi
shopt -s expand_aliases
# Set a restrictive umask to make sure qemu user files are private
@ -36,7 +46,7 @@ perror() {
# Function to show the usage
public_help() {
local name
name=$(basename "$0")
name="$(basename "$0")"
exec cat << EOF
${name}: usage:
@ -66,11 +76,9 @@ error_usage() {
# Function to start a virtual machine
public_start() {
QEMUSH_NAME="$1"
shift
if ! "$@"; then
perror "error launching virtual machine \"${QEMUSH_NAME}\""
return 2
fi
"$QEMUSH_NAME" "$@" || perror "error launching virtual machine \"${QEMUSH_NAME}\""
}
# Attach to a running virtual machine output, the latest opened if no
@ -84,22 +92,21 @@ public_watch() {
# List running virtual machines
public_active() {
cd || return
echo "Running machines:"
exec ls -t sockets
exec ls -t "$sockets"
}
# List available virtual machines entrypoints
public_ls() {
cd || return
echo "Available machines:"
exec ls launchers
exec ls "$bin"
}
# Create a copy-on-write disk for a virtual machine
public_diskadd() {
QEMUSH_NAME="$1"
shift
exec qemu-img create -f qcow2 "$(diskpath)" "$1"
}
@ -107,29 +114,26 @@ public_diskadd() {
public_diskrm() {
QEMUSH_NAME="$1"
shift
exec rm -vi -- "$(diskpath)"
}
# List available disks
public_diskls() {
cd || return
echo "Available disks:"
exec ls disks
exec ls "$images"
}
# Edit a virtual machine entrypoint with a text editor
public_edit() {
cd || return
local file="launchers/${1}"
local file="${bin}/${1}"
"$EDITOR" "$file"
[ -f "$file" ] && exec chmod u+x "$file"
}
# Delete a virtual machine entrypoint
public_rm() {
cd || return
exec rm -vi -- "launchers/${1}"
exec rm -vi -- "${bin}/${1}"
}
# Invoke bash as qemu user in its home directory
@ -141,7 +145,7 @@ public_shell() {
# Output the content of an entrypoint, with coloration if on a virtual
# terminal
public_cat() {
cat "launchers/${1}"
pretty_cat "${bin}/${1}"
}
# Copy a file in entrypoints folder
@ -150,15 +154,9 @@ public_add() {
set -e
local name
if [ -n "$2" ]; then
name="$2"
else
name=$(basename "$1")
fi
name="${HOME}/launchers/${name}"
cp -vi -- "$1" "$name"
chmod 740 "$name"
name="${2:-$(basename "$1")}"
cp -v -i -- "$1" "${bin}/${2}"
chmod 740 "${bin}/${name}"
set +e
trap - EXIT