Skip to content
Permalink
master
Switch branches/tags
Go to file
 
 
Cannot retrieve contributors at this time
executable file 100 lines (83 sloc) 2.13 KB
#!/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