Compare commits
No commits in common. "37a1ed9296e871c7333afd0f19ccccaa79c85c49" and "849f6de9bd5761cdc5a64469671614c3c495bf92" have entirely different histories.
37a1ed9296
...
849f6de9bd
2 changed files with 27 additions and 28 deletions
|
@ -47,7 +47,8 @@ need it
|
||||||
- `bash` - the `qemush` interpreter
|
- `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
|
- `source-highlight` - for syntax highlighting when displaying launching
|
||||||
|
scripts
|
||||||
- `diskpath` and `sockpath` - see [Installation
|
- `diskpath` and `sockpath` - see [Installation
|
||||||
instructions](#installation-instructions)
|
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
|
||||||
|
|
52
bin/qemush
52
bin/qemush
|
@ -15,14 +15,24 @@ exec_as() {
|
||||||
# Exec the script as qemu
|
# Exec the script as qemu
|
||||||
exec_as qemu "$@"
|
exec_as qemu "$@"
|
||||||
|
|
||||||
|
# Directories used in the program
|
||||||
|
bin="${HOME}/launchers"
|
||||||
|
images="${HOME}/disks"
|
||||||
|
sockets="${HOME}/sockets"
|
||||||
|
|
||||||
# Environment
|
# Environment
|
||||||
PATH="${HOME}/launchers:${HOME}/bin:${PATH}"
|
PATH="${bin}:${HOME}/bin:${PATH}"
|
||||||
EDITOR="${EDITOR:-nvim}"
|
EDITOR="${EDITOR:-nvim}"
|
||||||
export QEMUSH_NAME
|
export QEMUSH_NAME
|
||||||
|
|
||||||
# Aliases
|
# Aliases
|
||||||
alias ls='ls --color=auto'
|
alias ls='ls --color=auto'
|
||||||
alias exec='exec '
|
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
|
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
|
||||||
|
@ -36,7 +46,7 @@ perror() {
|
||||||
# Function to show the usage
|
# Function to show the usage
|
||||||
public_help() {
|
public_help() {
|
||||||
local name
|
local name
|
||||||
name=$(basename "$0")
|
name="$(basename "$0")"
|
||||||
|
|
||||||
exec cat << EOF
|
exec cat << EOF
|
||||||
${name}: usage:
|
${name}: usage:
|
||||||
|
@ -66,11 +76,9 @@ error_usage() {
|
||||||
# Function to start a virtual machine
|
# Function to start a virtual machine
|
||||||
public_start() {
|
public_start() {
|
||||||
QEMUSH_NAME="$1"
|
QEMUSH_NAME="$1"
|
||||||
|
shift
|
||||||
|
|
||||||
if ! "$@"; then
|
"$QEMUSH_NAME" "$@" || perror "error launching virtual machine \"${QEMUSH_NAME}\""
|
||||||
perror "error launching virtual machine \"${QEMUSH_NAME}\""
|
|
||||||
return 2
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Attach to a running virtual machine output, the latest opened if no
|
# Attach to a running virtual machine output, the latest opened if no
|
||||||
|
@ -84,22 +92,21 @@ public_watch() {
|
||||||
|
|
||||||
# List running virtual machines
|
# List running virtual machines
|
||||||
public_active() {
|
public_active() {
|
||||||
cd || return
|
|
||||||
echo "Running machines:"
|
echo "Running machines:"
|
||||||
exec ls -t sockets
|
exec ls -t "$sockets"
|
||||||
}
|
}
|
||||||
|
|
||||||
# List available virtual machines entrypoints
|
# List available virtual machines entrypoints
|
||||||
public_ls() {
|
public_ls() {
|
||||||
cd || return
|
|
||||||
echo "Available machines:"
|
echo "Available machines:"
|
||||||
exec ls launchers
|
exec ls "$bin"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Create a copy-on-write disk for a virtual machine
|
# Create a copy-on-write disk for a virtual machine
|
||||||
public_diskadd() {
|
public_diskadd() {
|
||||||
QEMUSH_NAME="$1"
|
QEMUSH_NAME="$1"
|
||||||
shift
|
shift
|
||||||
|
|
||||||
exec qemu-img create -f qcow2 "$(diskpath)" "$1"
|
exec qemu-img create -f qcow2 "$(diskpath)" "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,29 +114,26 @@ public_diskadd() {
|
||||||
public_diskrm() {
|
public_diskrm() {
|
||||||
QEMUSH_NAME="$1"
|
QEMUSH_NAME="$1"
|
||||||
shift
|
shift
|
||||||
|
|
||||||
exec rm -vi -- "$(diskpath)"
|
exec rm -vi -- "$(diskpath)"
|
||||||
}
|
}
|
||||||
|
|
||||||
# List available disks
|
# List available disks
|
||||||
public_diskls() {
|
public_diskls() {
|
||||||
cd || return
|
|
||||||
echo "Available disks:"
|
echo "Available disks:"
|
||||||
exec ls disks
|
exec ls "$images"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Edit a virtual machine entrypoint with a text editor
|
# Edit a virtual machine entrypoint with a text editor
|
||||||
public_edit() {
|
public_edit() {
|
||||||
cd || return
|
local file="${bin}/${1}"
|
||||||
local file="launchers/${1}"
|
|
||||||
|
|
||||||
"$EDITOR" "$file"
|
"$EDITOR" "$file"
|
||||||
[ -f "$file" ] && exec chmod u+x "$file"
|
[ -f "$file" ] && exec chmod u+x "$file"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Delete a virtual machine entrypoint
|
# Delete a virtual machine entrypoint
|
||||||
public_rm() {
|
public_rm() {
|
||||||
cd || return
|
exec rm -vi -- "${bin}/${1}"
|
||||||
exec rm -vi -- "launchers/${1}"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Invoke bash as qemu user in its home directory
|
# 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
|
# Output the content of an entrypoint, with coloration if on a virtual
|
||||||
# terminal
|
# terminal
|
||||||
public_cat() {
|
public_cat() {
|
||||||
cat "launchers/${1}"
|
pretty_cat "${bin}/${1}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Copy a file in entrypoints folder
|
# Copy a file in entrypoints folder
|
||||||
|
@ -150,15 +154,9 @@ public_add() {
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
local name
|
local name
|
||||||
if [ -n "$2" ]; then
|
name="${2:-$(basename "$1")}"
|
||||||
name="$2"
|
cp -v -i -- "$1" "${bin}/${2}"
|
||||||
else
|
chmod 740 "${bin}/${name}"
|
||||||
name=$(basename "$1")
|
|
||||||
fi
|
|
||||||
name="${HOME}/launchers/${name}"
|
|
||||||
|
|
||||||
cp -vi -- "$1" "$name"
|
|
||||||
chmod 740 "$name"
|
|
||||||
|
|
||||||
set +e
|
set +e
|
||||||
trap - EXIT
|
trap - EXIT
|
||||||
|
|
Loading…
Reference in a new issue