-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththermo.sh
executable file
·199 lines (167 loc) · 3.94 KB
/
thermo.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/usr/bin/env bash
SELF="$0"
. "$(dirname ${SELF})/.env"
function logStr() {
SEVERITY=$1
MESSAGE=$2
Color_Off='\033[0m'
IWhite='\033[0;97m'
echo -e "${IWhite}[${SEVERITY}]\t${Color_Off}${MESSAGE}"
# remoe later ?
echo ""
}
function debug() {
logStr " DBG " "$1"
}
function warn() {
logStr " WRN " "$1"
}
function error() {
logStr " ERR " "$1"
}
function checkDocker() {
local DOCKER_BIN=$(which docker)
if [[ -z "${DOCKER_BIN}" ]]; then
error "Docker not found. Please install it running 'curl -L get.docker.com | bash'"
exit 1
fi
}
# Save current dir
CUR_DIR=$(pwd)
# Pather placeholders
PROJ_DIR=$(dirname $0) && cd ${PROJ_DIR} && PROJ_DIR=$(pwd)
chmod -Rf 0777 .
CLI_DIR=${PROJ_DIR}/cli
ENV_DIR=${CLI_DIR}/env
A_CLI_SRC_DIR=${PROJ_DIR}/build-tools/src
ARDUINO_DIR=build-tools/arduino
initOS() {
OS=$(uname -s)
case "$OS" in
Linux*) OS='Linux' ;;
Darwin*) OS='macOS' ;;
MINGW*) OS='Windows' ;;
MSYS*) OS='Windows' ;;
esac
echo "$OS"
}
function getCLI() {
OS=$(initOS)
local CLI_EXECUTABLE_BINARY=""
case "$OS" in
'Linux')
CLI_EXECUTABLE_BINARY="${A_CLI_SRC_DIR}/dist/arduino_cli_linux_amd64/arduino-cli"
;;
'macOS')
CLI_EXECUTABLE_BINARY="${A_CLI_SRC_DIR}/dist/arduino_cli_osx_darwin_amd64/arduino-cli"
;;
'Windows')
CLI_EXECUTABLE_BINARY="${A_CLI_SRC_DIR}/dist/arduino_cli_windows_amd64/arduino-cli.exe"
;;
esac
echo ${CLI_EXECUTABLE_BINARY}
}
CLI_EXECUTABLE_BINARY=$(getCLI)
function checkDependencies() {
local DEP_UTILS="git grep cut tar curl readlink dirname"
for DEPENDENCY in $DEP_UTILS; do
if [[ -z "$(which $DEPENDENCY)" ]]; then
error "Dependency ${DEPENDENCY} not found. Please install first!"
exit 1
fi
done
}
function pConsole() {
${CLI_DIR}/app.sh $@
if [[ 0 -lt $? ]]; then
exit $?
fi
}
function tryGetArduinoCli() {
if [[ ! -d "${A_CLI_SRC_DIR}" ]]; then
local A_CLI_REPO="arduino/arduino-cli"
pConsole arduino:deploy ${A_CLI_REPO}
fi
}
function buildArduinoCli() {
local BUILDER_TAG="arduino/cli:builder"
if [[ -z "$(docker images -q ${BUILDER_TAG})" ]]; then
cd "${A_CLI_SRC_DIR}/Dockerfiles/builder"
docker build -t=${BUILDER_TAG} .
fi
echo Moving to ${A_CLI_SRC_DIR}
cd ${A_CLI_SRC_DIR}
sleep 3
docker run --rm -v $PWD:/arduino-cli -w /arduino-cli -e PACKAGE_NAME_PREFIX='snapshot' ${BUILDER_TAG} goreleaser --rm-dist --snapshot --skip-publish
}
function boot() {
checkDocker
checkDependencies
}
function init() {
tryGetArduinoCli
buildArduinoCli
}
boot
if [[ ! -f "${CLI_EXECUTABLE_BINARY}" ]]; then
init
fi
if [[ ! -d ${ARDUINO_DIR} ]]; then
debug "Creating directory ARDUINO_DIR=${ARDUINO_DIR}"
mkdir -p "${ARDUINO_DIR}"
if [[ 0 != $? ]]; then
debug "Failed creating directory ${ARDUINO_DIR}"
cd ${PROJ_DIR}
ls -lah
exit 1
fi
NEED_BOARD_INSTALL="1"
fi
pConsole arduino:config ${ARDUINO_DIR}
cd ${PROJ_DIR}
chmod -Rf 0777 ./build-tools
A_CLI="${CLI_EXECUTABLE_BINARY} --config-file ${PROJ_DIR}/build-tools/arduino-cli.yaml"
A_CLI="${CLI_EXECUTABLE_BINARY}"
if [[ "$1" == "reset" ]]; then
debug "Resetting..."
rm -rf ${PROJ_DIR}/build-tools
rm -rf ${PROJ_DIR}/cli/vendor
debug "Done."
exit 0
fi
function initArduino() {
${SELF} core update-index
}
function addBoard() {
${SELF} core download "$1"
${SELF} core install "$1"
}
if [[ "$1" == 'init-arduino-dir' ]]; then
chmod -Rf 0777 "${PROJ_DIR}"
initArduino
${SELF} add-board esp32:esp32
${SELF} add-board esp8266:esp8266
exit $?
fi
if [[ "$1" == 'add-board' ]]; then
shift
addBoard $1
exit $?
fi
if [[ ${NEED_BOARD_INSTALL} == "1" ]]; then
${SELF} init-arduino-dir
fi
if [[ "$1" == "build" ]]; then
${SELF} compile --fqbn esp32:esp32:esp32
exit $?
fi
if [[ "$1" == "install-external-libraries" ]]; then
for i in $(cat ./dependencies.txt); do
if [[ ! -z "$i" ]]; then
debug "Installing library: ${i}"
./cli/app.sh ext-lib:install "${i}"
fi
done
exit 0
fi
${A_CLI} $@