-
Notifications
You must be signed in to change notification settings - Fork 105
/
post-config-resources.sh
executable file
·93 lines (83 loc) · 2.04 KB
/
post-config-resources.sh
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
#!/bin/bash
PROG="$(basename "${0}")"
SCRIPT_DIR="$(cd "$(dirname "${0}")" && pwd)"
VMNAME=""
POST_CONFIG_RESOURCES_FILE=""
VBOXMANAGE=`which vboxmanage`
usage() {
echo -e "USAGE: ${PROG} [--vm-name <VMNAME>]\n"
}
help_exit() {
usage
echo "This is a utility script for post configure vm.
Options:
-v, --vm-name VMNAME
Name of VistualBox vm.
-r, --post-config-resources POST_CONFIG_RESOURCES_FILE
Path to an post config resources data file.
-h, --help Output this help message.
"
exit 0
}
assign() {
key="${1}"
value="${key#*=}"
if [[ "${value}" != "${key}" ]]; then
# key was of the form 'key=value'
echo "${value}"
return 0
elif [[ "x${2}" != "x" ]]; then
echo "${2}"
return 2
else
output "Required parameter for '-${key}' not specified.\n"
usage
exit 1
fi
keypos=$keylen
}
while [[ $# -ge 1 ]]; do
key="${1}"
case $key in
-*)
keylen=${#key}
keypos=1
while [[ $keypos -lt $keylen ]]; do
case ${key:${keypos}} in
v|-vm-name)
VMNAME=$(assign "${key:${keypos}}" "${2}")
if [[ $? -eq 2 ]]; then shift; fi
keypos=$keylen
;;
r|-post-config-resources)
POST_CONFIG_RESOURCES_FILE=$(assign "${key:${keypos}}" "${2}")
if [[ $? -eq 2 ]]; then shift; fi
keypos=$keylen
;;
h*|-help)
help_exit
;;
*)
output "Unknown option '${key:${keypos}}'.\n"
usage
exit 1
;;
esac
((keypos++))
done
;;
esac
shift
done
if [[ -z ${VMNAME} ]]; then
echo "VM name not found"
exit 1
fi
if [[ -z ${POST_CONFIG_RESOURCES_FILE} || ! -f ${POST_CONFIG_RESOURCES_FILE} ]]; then
echo "Post config resources data file, not found"
exit 1
fi
PROCESSORS=`cat ${POST_CONFIG_RESOURCES_FILE} | shyaml get-value processors`
MEMORY=`cat ${POST_CONFIG_RESOURCES_FILE} | shyaml get-value memory`
${VBOXMANAGE} modifyvm ${VMNAME} --cpuhotplug off
${VBOXMANAGE} modifyvm ${VMNAME} --cpus ${PROCESSORS} --memory ${MEMORY} --vram 33