forked from cmu-sei/foundry-appliance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-appliance
executable file
·36 lines (31 loc) · 983 Bytes
/
build-appliance
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
#!/bin/bash
#
# Copyright 2021 Carnegie Mellon University.
# Released under a BSD (SEI)-style license, please see LICENSE.md in the
# project root or contact [email protected] for full terms.
# Parse target hypervisors into Packer -only option syntax
if [[ $1 != -* ]]; then
IFS=',' read -ra TARGETS <<< "$1"
for i in "${TARGETS[@]}"; do
ONLY_VAR+="$i*,"
done
ONLY_VAR=${ONLY_VAR%?}
shift 1
fi
if git rev-parse --git-dir > /dev/null 2>&1; then
VERSION_TAG=$(git tag --points-at HEAD 'v*')
GIT_BRANCH=$(git branch --show-current)
GIT_HASH=$(git rev-parse --short HEAD)
fi
if [ -n "$VERSION_TAG" ]; then
BUILD_VERSION=$VERSION_TAG
elif [ -n "$GIT_HASH" ]; then
BUILD_VERSION=$GIT_BRANCH-$GIT_HASH
else
BUILD_VERSION="custom-$(date '+%Y%m%d')"
fi
if [ -n "$ONLY_VAR" ]; then
packer build -only=$ONLY_VAR -var "appliance_version=$BUILD_VERSION" $@ .
else
packer build -var "appliance_version=$BUILD_VERSION" $@ .
fi