-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvm-command-run.in
executable file
·89 lines (72 loc) · 1.43 KB
/
vm-command-run.in
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
#!/bin/sh -efu
[ -z "@MKLOCAL@" ] ||
export PATH="@PREFIX@/libshell:${PATH#@PREFIX@/libshell:}"
case "${VM_HELP-}" in
USAGE)
printf 'run <profile>\n'
;;
SUMMARY)
printf 'Starts a virtual machine according to specified profile\n'
;;
DESCRIPTION)
;;
OPTIONS)
;;
esac
[ -z "${VM_HELP-}" ] ||
exit 0
if [ -z "${vm_profile-}" ]; then
[ "$#" -gt 0 ] ||
show_usage "Profile name required"
vm_profile="$1"
shift
export vm_profile
fi
. shell-git-config
. "@PREFIX@/vm-sh-config"
debug_exec() {
printf '%s \\\n' "$1"; shift
opt=
for a; do
if [ -z "${a##-*}" ]; then
[ -z "$opt" ] || printf '\\\n'
printf '\t%s ' "$a"
opt=1
else
printf '"%s" \\\n' "$a"
opt=
fi
done
printf '\t#\n'
}
vm_read_profile_config
vm_check_kernel_config
vm_profiles=
git_config_get vm_profiles "$vm_config_file" "vm.profiles"
rootfs=
git_config_get rootfs "$vm_config_file" "vm.$vm_profile.rootfs"
subst_globals rootfs "$rootfs"
dest_dir="$vm_profiles/$vm_profile"
mkdir $verbose -p -- "$dest_dir"
set --
i=0
while [ "$i" -lt "$qemu_args" ]; do
eval "v=\"\$qemu_args_$i\""
i=$(($i + 1))
set -- "$@" "$v"
done
if [ -n "$qemu_logfile" ]; then
subst_globals qemu_logfile "$qemu_logfile"
buf="$workdir/qemu.exec.buf"
{
rc=0
${vm_dryrun:+debug_exec} "$qemu_exec" "$@" ||
rc=$?
printf '%s\n' "$rc" > "$buf"
} |
tee "$qemu_logfile"
read rc < "$buf"
rm -f -- "$buf"
exit $rc
fi
${vm_dryrun:+debug_exec} "$qemu_exec" "$@"