-
Notifications
You must be signed in to change notification settings - Fork 0
/
dobi.sh
executable file
·89 lines (80 loc) · 3.16 KB
/
dobi.sh
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
#!/bin/bash
# Downloads dobi in specific version and for target OS
download_dobi() {
if [[ "$OSTYPE" == "linux-gnu"* || "$OSTYPE" == "cygwin" ]]; then
dobi_dltarget=linux
elif [[ "$OSTYPE" == "darwin"* ]]; then
dobi_dltarget=darwin
elif [[ "$OSTYPE" == "msys" || "$OSTYPE" == "win32" ]]; then
dobi_dltarget=windows
fi
if [[ ! -z ${dobi-dltarget} && -x $(which curl) ]]; then
mkdir -p .dobi
curl -L --progress-bar --fail -o ${1} "https://github.com/dnephin/dobi/releases/download/v${DOWNLOAD_VERSION_DOBI}/dobi-${dobi_dltarget}"
if [[ ${?} -ne 0 ]]; then
echo "Download of dobi failed. Check specified version in env variable \"DOWNLOAD_VERSION_DOBI\"".
exit 1
else
chmod +x ${1}
fi
else
echo "\"dobi\" not found. Please install \"dobi\": https://github.com/dnephin/dobi/releases"
exit 1
fi
}
# Extracts version number out of '--version' string
dobi_version() {
local DOBI_VERSION=$(${1} --version | grep -oP "\K\d+\.\d+\.\d+")
echo "${DOBI_VERSION}"
}
# load and export env files
set -o allexport
source default.env
set +o allexport
# check for docker
if [[ $(docker version &>/dev/null; echo $?) -ne 0 ]]; then
echo "docker is not running"
exit 1
fi
# Check for dobi
DOBI_THIS_PROJECT=".dobi/dobi"
if [[ ! -f ${DOBI_THIS_PROJECT} ]]; then
# Case: dobi not present in this project
if [[ -x $(which dobi) ]]; then
# Case: dobi present in system e.g. /usr/local/bin/dobi
dobi=$(which dobi)
PRESENT_DOBI_VERSION=$(dobi_version ${dobi})
if [[ ${PRESENT_DOBI_VERSION} != *${DOWNLOAD_VERSION_DOBI}* ]]; then
# Case: Version mismatch between 'requested' and 'present in system'
echo "Found incorrect version for '$(which dobi)': ${PRESENT_DOBI_VERSION}. Downloading version ${DOWNLOAD_VERSION_DOBI}."
download_dobi ${DOBI_THIS_PROJECT} ${DOWNLOAD_VERSION_DOBI}
dobi=${DOBI_THIS_PROJECT}
fi
else
# Case: dobi not present in system, download requested version to project
echo "dobi not found. Downloading version '${DOWNLOAD_VERSION_DOBI}'."
download_dobi ${DOBI_THIS_PROJECT} ${DOWNLOAD_VERSION_DOBI}
dobi=${DOBI_THIS_PROJECT}
fi
else
# Case: dobi present in this project
dobi=${DOBI_THIS_PROJECT}
PRESENT_DOBI_VERSION=$(dobi_version ${dobi})
if [[ ${PRESENT_DOBI_VERSION} != *${DOWNLOAD_VERSION_DOBI}* ]]; then
# Case: Version mismatch between 'requested' and 'present in project'
echo "Found incorrect version for '${DOBI_THIS_PROJECT}': ${PRESENT_DOBI_VERSION}. Downloading version ${DOWNLOAD_VERSION_DOBI}."
download_dobi ${DOBI_THIS_PROJECT} ${DOWNLOAD_VERSION_DOBI}
fi
fi
# generate actual version files
${dobi} --filename meta.yaml version
# check argument count
if [ -z ${1} ]; then
echo "no arguments!"
${dobi} --filename meta.yaml list
exit 1
fi
# load generated version infos
source gen/gitversion/env/gitversion.env
# execute dobi with meta as default
exec ${dobi} --filename meta.yaml ${@}