-
Notifications
You must be signed in to change notification settings - Fork 7
/
build_vm
executable file
·73 lines (63 loc) · 2 KB
/
build_vm
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
#! /bin/sh
set -euo pipefail
PACKER_CACHE_DIR=${PACKER_CACHE_DIR:-./packer_cache}
target=${target:-alt-server}
arch=${arch:-x86_64}
BASE_VERSION=${BASE_VERSION:-9}
TARGET_VERSION=${TARGET_VERSION:-9}
headless=${headless:-false}
VM_TYPE=${VM_TYPE:-qemu}
# on-error may be:
# - abort - stop and leave everything "as is"
# - cleanup - is the default behavior
# - ask - ask what to do
onerror=${onerror:-cleanup}
build_command="packer build -var-file=config/common.json -on-error=${onerror}"
# Check that the variable is set to correct value
# $1 - variable name
# $2 - variable value
# $* - list of all possible values
assert_value() {
variable_name="${1}"
variable_value="${2}"
shift 2
possible_values="$*"
comparison_success=false
echo "CHECKING: ${variable_name}, must be one of: ${possible_values}"
for pval in ${possible_values}; do
if test "${variable_value}" == "${pval}"; then
comparison_success=true
break
fi
done
if test "${comparison_success}" == "true"; then
echo "CHECKING: ${variable_name}, SUCCESS"
return 0
else
echo "CHECKING: ${variable_name}, FAIL"
return 1
fi
}
main() {
assert_value target ${target} alt-server alt-workstation alt-kworkstation
assert_value arch ${arch} i586 x86_64
assert_value headless ${headless} true false
assert_value BASE_VERSION ${BASE_VERSION} '8.2' '8.3' '8sp' '8.1sp' '9' '9.1' 'sisyphus'
assert_value TARGET_VERSION ${TARGET_VERSION} '8.2' '8.3' '8sp' '8.1sp' '9' '9.1' 'sisyphus'
assert_value VM_TYPE ${VM_TYPE} qemu onebula vbox
assert_value onerror ${onerror} ask cleanup abort
if test "${BASE_VERSION}" == "sisyphus"; then
TARGET_VERSION="sisyphus"
fi
env \
PACKER_CACHE_DIR="${PACKER_CACHE_DIR}" \
PACKER_TARGET="${target}" \
PACKER_BASE_VERSION="${BASE_VERSION}" \
PACKER_ARCH="${arch}" \
PACKER_HEADLESS="${headless}" \
PACKER_LOG=1 \
PACKER_TARGET_VERSION="${TARGET_VERSION}" \
PACKER_VM_TYPE="${VM_TYPE}" \
${build_command} -force -var-file=config/${target}-${BASE_VERSION}-${arch}.json -only=${VM_TYPE}-vm build.json
}
main