-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbuild
executable file
·72 lines (56 loc) · 1.91 KB
/
build
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/bash
#
# Build script for the Dreambox.
#
set -e;
# Help text.
function show_help() {
cat <<EOT
Usage:
./$(basename "$0") [virtualbox|vmware]
If no option is passed, both will be built.
EOT
}
ONLY=false;
IS_VIRTUALBOX=false;
IS_VMWARE=false;
if [[ $# -gt 0 ]]; then
# Test for known flags.
for OPT in "${@}";
do
case "${OPT}" in
virtualbox) ONLY=true; IS_VIRTUALBOX=true ;; # Suppresses installing packages.
vmware) ONLY=true; IS_VMWARE=true ;;
*) echo -e "Warning: invalid option \`${OPT}\`\n" && show_help && exit ;;
esac
done;
fi;
vagrant destroy;
# Remove from VirtualBox.
# Useful for quickly re-running failed builds.
if $IS_VIRTUALBOX; then
VM_ID=$(vboxmanage list runningvms | grep -oP "dreambox\"\s{(.*)}.*" | sed -E 's/.*{(.*)}/\1/');
if [[ -n $VM_ID ]]; then
vboxmanage controlvm $VM_ID poweroff && vboxmanage unregistervm $VM_ID --delete;
fi;
fi;
# Remove the output directories
rm -rf output-vmware-iso/;
rm -rf output-virtualbox-iso/;
if [[ ! -d '_builds' ]]; then
# Create the _builds directory.
mkdir '_builds';
fi;
# Remove the box from Vagrant to avoid collisions.
[[ $(vagrant box remove --force --all dreambox_pre/virtualbox 2> /dev/null) ]] || echo 'No Vagrant box to remove...';
[[ $(vagrant box remove --force --all dreambox_pre/vmware 2> /dev/null) ]] || echo 'No Vagrant box to remove...';
# Build and add the box(es) to vagrant as 'dreambox_pre'.
if $ONLY; then
packer build -only=${@}-iso -force -parallel=false -var-file=templates/common.json templates/dreambox.json;
vagrant box add --force dreambox_pre/${@} _builds/dreambox.${@}.*.box;
else
packer build -force -parallel=false -var-file=templates/common.json templates/dreambox.json;
vagrant box add --force dreambox_pre/virtualbox _builds/dreambox.virtualbox.*.box;
vagrant box add --force dreambox_pre/vmware _builds/dreambox.vmware.*.box;
fi;
exit $?;