This repository has been archived by the owner on Feb 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vthena
executable file
·94 lines (84 loc) · 3.14 KB
/
vthena
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
# This wrapper allows easy use of my QEMU VM scripts
###TODO:
### external disks
### qemu help message passthrough
### experiment script
set -eo pipefail
trap cleanup SIGINT SIGTERM ERR EXIT
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)
#fetch defaults
[[ -f $script_dir/vthena.d/.env ]] && source $script_dir/vthena.d/.env
# prints a help message
help() {
echo "
Usage: vthena command
Deletes VMs and rebases their children if necessary
Available commands:
help ex: vthena help; Prints this message.
clone ex: vthena clone test; Clones a vm.
create, new ex: vthena create linux.iso; Creates _master vm.
list, ls ex: vthena ls; Lists all created vms (cool tree coming?).
remove, rm ex: vthena rm ubuntu test Removes all provided vms.
rename, name ex: vthena name _master ubuntu; Renames a given vm.
start, up ex: vthena start ubuntu; Starts the given vm.
"
exit 1
}
# very cheap error logging
die() {
echo "$*" >&2
exit 2
}
# safely exits in the middle of the script
cleanup() {
# don't let them quit the quit cleaner
trap - SIGINT SIGTERM ERR EXIT
# remove instance marker
echo "Leaving"
exit
}
# returns all parameters, minus the given command
removeCommand() {
args=$(
for param in ${@:2}; do
[[ $param != $1 ]] && echo $param
done
)
echo $args
return 0
}
##MAIN
# if they ran this without args, they don't know what this does
[[ $# < 1 ]] && help
# demand non root so disks don't clog /root
([[ $USER == root ]] || [[ $HOME == /root ]]) && \
die "Using this as root can seriously mess up your system depending on partitions. Switch users."
# VTHENA_DIR is mandatory
[[ -z $VTHENA_DIR ]] && export VTHENA_DIR=$HOME/vthena
[[ ! -d $VTHENA_DIR ]] && (mkdir -p $VTHENA_DIR || die "couldn't make directory:$VTHENA_DIR")
# KVM enjoyers only
[[ -z $(id -nG "$USER" | grep kvm) ]] || #&& \
die "You need to be a member of the kvm group to use these utilities! Check that you are on Linux and are a part of the kvm group"
# check each parameter
for param in $@; do
# compare it to command list
case $param in
# if it starts with a hyphen it's an option, ignore it
-* ) continue ;;
# otherwise if it's a known command, run the appropriate script
start ) $script_dir/vthena.d/startVM.sh $(removeCommand $param $@) && exit ;;
create | new ) $script_dir/vthena.d/createVM.sh $(removeCommand $param $@) && exit ;;
rename | name ) $script_dir/vthena.d/setMasterImg.sh $(removeCommand $param $@) && exit ;;
clone ) $script_dir/vthena.d/cloneVM.sh $(removeCommand $param $@) && exit ;;
remove | rm) $script_dir/vthena.d/removeVM.sh $(removeCommand $param $@) && exit ;;
list | ls) $script_dir/vthena.d/util/listVMs.sh && exit ;;
run | test ) $script_dir/vthena.d/runExperiment.sh $(removeCommand $param $@) && exit ;;
key | keygen ) $script_dir/vthena.d/genVMKey.sh $(removeCommand $param $@) && exit ;;
help ) help ;;
# else print help message
? ) help ;;
esac
done
# Good Job!
exit 0