Compare commits

...

7 commits

Author SHA1 Message Date
Hippolyte Chauvin
21643ed7f8 qemush : alias pour ls 2023-11-29 14:42:47 +01:00
Hippolyte Chauvin
c09ea3ec38 qemush : suppression de la fonction exec_as 2023-11-29 14:41:10 +01:00
Hippolyte Chauvin
48790fec0d qemush : ajout de la variable images 2023-11-29 14:39:09 +01:00
Hippolyte Chauvin
9bdc1eef3d qemush : modification de la fonction rm 2023-11-29 14:36:57 +01:00
Hippolyte Chauvin
f24e2a6568 qemush : utilisation de la variable bin 2023-11-29 14:34:25 +01:00
Hippolyte Chauvin
85e31307ec qemush : fonction add -> edit, ouverture d'un editor à la place 2023-11-29 14:33:20 +01:00
Hippolyte Chauvin
fd8cb0c2c6 qemush : fonction list -> ls 2023-11-29 14:30:12 +01:00

View file

@ -1,18 +1,18 @@
#!/bin/bash #!/bin/bash
exec_as() { if [ "$(whoami)" != root ]; then
local user="$1" exec sudo -u qemu "$0" "$@"
shift
if [ "$(whoami)" != "$user" ]; then
exec sudo -u "$user" "$0" "$@"
else else
cd || return cd || exit
fi fi
}
exec_as qemu "$@" || exit bin=bin
PATH="./bin:${PATH}" images=images
PATH="./${bin}:${PATH}"
alias ls='ls --color=auto'
shopt -s expand_aliases
perror() { perror() {
>&2 printf '\033[1;31mERROR:\033[0m \033[1m%s\033[0m\n' "$*" >&2 printf '\033[1;31mERROR:\033[0m \033[1m%s\033[0m\n' "$*"
@ -26,7 +26,7 @@ ${name}: usage:
${name} active - (default behaviour) list active VMs ${name} active - (default behaviour) list active VMs
${name} start <VM name> - start a VM ${name} start <VM name> - start a VM
${name} watch <VM name> - attach VM screen session ${name} watch <VM name> - attach VM screen session
${name} list - list available VMs ${name} ls - list available VMs
${name} add <VM name> <template> - add launch script based on template ${name} add <VM name> <template> - add launch script based on template
${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
@ -58,13 +58,13 @@ public_active() {
screen -ls screen -ls
} }
public_list() { public_ls() {
echo "Available machines:" echo "Available machines:"
ls --color=auto bin ls "$bin"
} }
diskpath() { diskpath() {
printf 'images/%s.qcow2' "$1" printf "%s.qcow2" "${images}/${1}"
} }
public_diskadd() { public_diskadd() {
@ -77,15 +77,15 @@ public_diskrm() {
public_diskls() { public_diskls() {
echo "Available disks:" echo "Available disks:"
ls --color=auto images ls "$images"
} }
public_add() { public_edit() {
ln -vs "$2" "bin/${1}" "$EDITOR" "${bin}/${1}"
} }
public_rm() { public_rm() {
unlink "bin/${1}" rm -vi -- "${bin}/${1}"
} }
public_shell() { public_shell() {