-
Notifications
You must be signed in to change notification settings - Fork 25
/
databox-install-component
executable file
·100 lines (83 loc) · 2.13 KB
/
databox-install-component
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
94
95
96
97
98
99
100
#!/bin/bash
#include helper functions
source ./scripts/utils.sh
## check we have the tools
if ! [ -x "$(command -v git)" ]
then
die 1 "git is not installed;"`
`"see https://git-scm.com/"
fi
if ! [ -x "$(command -v curl)" ]
then
die 1 "curl is not installed;"`
`"https://curl.haxx.se"
fi
CPU_ARCH=$(uname -m)
if [[ "${CPU_ARCH}" = "x86_64" ]]
then
DATABOX_ARCH="amd64"
DATABOX_DOCKER_FILE="Dockerfile"
fi
if [[ "${CPU_ARCH}" = "aarch64" ]]
then
DATABOX_ARCH="arm64v8"
DATABOX_DOCKER_FILE="Dockerfile-arm64v8"
fi
usage() {
echo ""
echo "Please invoke this script with the component you would like to install."
echo "Usage: databox-install-component [OPTION...] [GITHUB-USER/COMPONENT-NAME] [DATABOX_REPO_TAG] [DATABOX_VERSION]"
echo "Flags:"
echo "-h This help message"
echo ""
exit 1
}
seedManifest() {
echo ""
echo "Don't forget to upload the manifest ;-)"
echo ""
}
buildImage() {
cd ./build/${1}
CONT_NAME=${1}
CONT_NAME=${CONT_NAME//_/-}
log "Starting build ${1} ..."
OUTPUT=$(docker build -t ${2}/${CONT_NAME}-${DATABOX_ARCH}:${3} -f ${DATABOX_DOCKER_FILE} .)
test_assert $? 0 "Build ${CONT_NAME}" "$OUTPUT"
cd ../..
}
pullChanges() {
cd ./build/${1}
log "Pulling Changes ${1} ..."
OUTPUT=$(git pull)
test_assert $? 0 "Git pull ${1}" "$OUTPUT"
cd ../..
}
if [[ $# < 3 ]] || [[ "$1" == "-h" ]] # Must have more than 1 args.
then
usage
fi
COMPONENT=$1
DATABOX_REPO_TAG=$2
DATABOX_VERSION=$3
if [[ ${COMPONENT} != *"/"* ]]; then
COMPONENT="me-box/${COMPONENT}"
fi
oIFS="$IFS"
IFS=/ arr=( ${COMPONENT} )
IFS="$oIFS"
USER=${arr[0]}
COMPONENT_NAME=${arr[1]}
mkdir -p ./build
if [ ! -d "./build/$COMPONENT_NAME" ]; then
log "Getting the code..... "
OUTPUT=$(cd build && git clone "https://github.com/${COMPONENT}.git")
test_assert $? 0 "Pulling the code from https://github.com/${COMPONENT}.git \n\n ${OUTPUT}"
buildImage ${COMPONENT_NAME}
seedManifest ${COMPONENT_NAME}
else
log "${COMPONENT_NAME} already installed, rebuilding and reseeding"
pullChanges ${COMPONENT_NAME}
buildImage ${COMPONENT_NAME} ${DATABOX_REPO_TAG} ${DATABOX_VERSION}
seedManifest ${COMPONENT_NAME}
fi