-
Notifications
You must be signed in to change notification settings - Fork 8
/
makefile
167 lines (136 loc) · 7.73 KB
/
makefile
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
###
### makefile
###
SHELL := /bin/bash
## HOSTIP
THIS_HOSTIP := $(shell ifconfig | egrep 'inet ' | awk '{ print $$2 }' | egrep -v '^172.|^10.|^127.' | head -1)
###
### VARIABLES
###
## HZN
HZN_ORG_ID ?= $(if $(wildcard HZN_ORG_ID),$(shell v=$$(cat HZN_ORG_ID) && echo "** SPECIFIED: HZN_ORG_ID: $${v}" > /dev/stderr && echo "$${v}"),$(shell v=$${USER} && echo "!! UNSPECIFIED: HZN_ORG_ID unset; default: $${v}" > /dev/stderr && echo "$${v}"))
HZN_USER_ID ?= $(if $(wildcard HZN_USER_ID),$(shell v=$$(cat HZN_USER_ID) && echo "** SPECIFIED: HZN_USER_ID: $${v}" > /dev/stderr && echo "$${v}"),$(shell v=$${USER} && echo "!! UNSPECIFIED: HZN_USER_ID unset; default: $${v}" > /dev/stderr && echo "$${v}"))
HZN_EXCHANGE_APIKEY ?= $(if $(wildcard HZN_EXCHANGE_APIKEY),$(shell v=$$(cat HZN_EXCHANGE_APIKEY) && echo "** SPECIFIED: HZN_EXCHANGE_APIKEY: $${v}" > /dev/stderr && echo "$${v}"),$(shell v='whocares' && echo "!! UNSPECIFIED: HZN_EXCHANGE_APIKEY unset; default: $${v}" > /dev/stderr && echo "$${v}"))
## EXCHANGE
EXCHANGE_HOSTNAME ?= $(if $(wildcard EXCHANGE_HOSTNAME),$(shell v=$$(cat EXCHANGE_HOSTNAME) && echo "** SPECIFIED: EXCHANGE_HOSTNAME: $${v}" > /dev/stderr && echo "$${v}"),$(shell v=$(THIS_HOSTIP) && echo "!! UNSPECIFIED: EXCHANGE_HOSTNAME unset; default: $${v}" > /dev/stderr && echo "$${v}"))
EXCHANGE_NAMESPACE ?= $(if $(wildcard EXCHANGE_NAMESPACE),$(shell v=$$(cat EXCHANGE_NAMESPACE) && echo "** SPECIFIED: EXCHANGE_NAMESPACE: $${v}" > /dev/stderr && echo "$${v}"),$(shell v='oh' && echo "!! UNSPECIFIED: EXCHANGE_NAMESPACE unset; default: $${v}" > /dev/stderr && echo "$${v}"))
EXCHANGE_NETWORK ?= $(if $(wildcard EXCHANGE_NETWORK),$(shell v=$$(cat EXCHANGE_NETWORK) && echo "** SPECIFIED: EXCHANGE_NETWORK: $${v}" > /dev/stderr && echo "$${v}"),$(shell v='hznnet' && echo "!! UNSPECIFIED: EXCHANGE_NETWORK unset; default: $${v}" > /dev/stderr && echo "$${v}"))
EXCHANGE_NETWORK_DRIVER ?= $(if $(wildcard EXCHANGE_NETWORK_DRIVER),$(shell v=$$(cat EXCHANGE_NETWORK_DRIVER) && echo "** SPECIFIED: EXCHANGE_NETWORK_DRIVER: $${v}" > /dev/stderr && echo "$${v}"),$(shell v='bridge' && echo "!! UNSPECIFIED: EXCHANGE_NETWORK_DRIVER unset; default: $${v}" > /dev/stderr && echo "$${v}"))
EXCHANGE_ROOT ?= $(if $(wildcard EXCHANGE_ROOT),$(shell v=$$(cat EXCHANGE_ROOT) && echo "** SPECIFIED: EXCHANGE_ROOT: $${v}" > /dev/stderr && echo "$${v}"),$(shell v='root' && echo "!! UNSPECIFIED: EXCHANGE_ROOT unset; default: $${v}" > /dev/stderr && echo "$${v}"))
EXCHANGE_PASSWORD ?= $(if $(wildcard EXCHANGE_PASSWORD),$(shell cat EXCHANGE_PASSWORD),$(shell jq -r '.services.exchange.password' exchange/config.json.tmpl))
# dependent on previous
HZN_EXCHANGE_URL ?= $(if $(wildcard HZN_EXCHANGE_URL),$(shell v=$$(cat HZN_EXCHANGE_URL) && echo "** SPECIFIED: HZN_EXCHANGE_URL: $${v}" > /dev/stderr && echo "$${v}"),$(shell v="http://${EXCHANGE_HOSTNAME}:3090/v1/" && echo "!! UNSPECIFIED: HZN_EXCHANGE_URL unset; default: $${v}" > /dev/stderr && echo "$${v}"))
HZN_FSS_CSSURL ?= $(if $(wildcard HZN_FSS_CSSURL),$(shell v=$$(cat HZN_FSS_CSSURL) && echo "** SPECIFIED: HZN_FSS_CSSURL: $${v}" > /dev/stderr && echo "$${v}"),$(shell v="http://${EXCHANGE_HOSTNAME}:9443/css/" && echo "!! UNSPECIFIED: HZN_FSS_CSSURL unset; default: $${v}" > /dev/stderr && echo "$${v}"))
## VERSIONS
# EXCHANGE
EXCHANGE_TAG ?= $(if $(wildcard EXCHANGE_TAG),$(shell v=$$(cat EXCHANGE_TAG) && echo "** SPECIFIED: EXCHANGE_TAG: $${v}" > /dev/stderr && echo "$${v}"),$(shell v=$$(jq -r '.services.exchange.stable' exchange/config.json.tmpl) && echo "!! UNSPECIFIED: EXCHANGE_TAG unset; default: $${v}" > /dev/stderr && echo "$${v}"))
# CSS
CSS_TAG ?= $(if $(wildcard CSS_TAG),$(shell v=$$(cat CSS_TAG) && echo "** SPECIFIED: CSS_TAG: $${v}" > /dev/stderr && echo "$${v}"),$(shell v=$$(jq -r '.services.css.stable' exchange/config.json.tmpl) && echo "!! UNSPECIFIED: CSS_TAG unset; default: $${v}" > /dev/stderr && echo "$${v}"))
# AGBOT
AGBOT_TAG ?= $(if $(wildcard AGBOT_TAG),$(shell v=$$(cat AGBOT_TAG) && echo "** SPECIFIED: AGBOT_TAG: $${v}" > /dev/stderr && echo "$${v}"),$(shell v=$$(jq -r '.services.agbot.stable' exchange/config.json.tmpl) && echo "!! UNSPECIFIED: AGBOT_TAG unset; default: $${v}" > /dev/stderr && echo "$${v}"))
###
### TARGETS
###
ACTIONS := tidy clean
default:
@echo 'These are the targets: exchange, agent, services, all, tidy, and clean; run "make all" to setup everything'
all: exchange agent services
${ACTIONS}:
@${MAKE} -C exchange $@
@${MAKE} -C services $@
build:
@${MAKE} -C services $@
## EXCHANGE
exchange: exchange/config.json
@echo "making $@"
${MAKE} -C $@ all up
@echo -n 'Waiting for exchange '
@while [ -z "$$(curl -qsSL 127.0.0.1:3090/v1/admin/version 2> /dev/null)" ]; do echo -n '.'; sleep 5; done && echo -n ' operational' || echo ' non-operational'
${MAKE} -C $@ prime
@echo 'Now install agent using script sh/get.horizon.sh'
exchange/config.json: exchange/config.json.tmpl
@echo "making $@"
@export \
EXCHANGE_HOSTNAME="$(EXCHANGE_HOSTNAME)" \
EXCHANGE_NAMESPACE="${EXCHANGE_NAMESPACE}" \
EXCHANGE_NETWORK="${EXCHANGE_NETWORK}" \
EXCHANGE_NETWORK_DRIVER="${EXCHANGE_NETWORK_DRIVER}" \
EXCHANGE_TAG="$(EXCHANGE_TAG)" \
CSS_TAG="$(CSS_TAG)" \
AGBOT_TAG="$(AGBOT_TAG)" \
HZN_FSS_CSSURL="$(HZN_FSS_CSSURL)" \
HZN_EXCHANGE_URL="$(HZN_EXCHANGE_URL)" \
HZN_EXCHANGE_APIKEY="$(HZN_EXCHANGE_APIKEY)" \
HZN_ORG_ID="$(HZN_ORG_ID)" \
HZN_USER_ID="$(HZN_USER_ID)" \
&& cat $< \
| envsubst \
| jq '.services.exchange.password="'"${EXCHANGE_PASSWORD}"'"' \
| jq '.services.exchange.encoded="$(shell htpasswd -bnBC 10 "" "$(EXCHANGE_PASSWORD)" | tr -d ':\n' | sed 's/$$2y/$$2a/')"' > $@
## AGENT
agent: exchange/config.json
@echo "making $@"
sudo ./sh/get.horizon.sh ${HZN_EXCHANGE_URL} ${HZN_FSS_CSSURL}
## SERVICES
services/HZN_EXCHANGE_APIKEY: makefile
@echo ${HZN_EXCHANGE_APIKEY} > $@
services/HZN_ORG_ID: makefile
@echo ${HZN_ORG_ID} > $@
services/HZN_USER_ID: makefile
@echo ${HZN_USER_ID} > $@
services/HZN_EXCHANGE_URL: makefile
@echo ${HZN_EXCHANGE_URL} > $@
HZN_VARIABLES := \
services/HZN_EXCHANGE_URL \
services/HZN_EXCHANGE_APIKEY \
services/HZN_ORG_ID \
services/HZN_USER_ID
services: ${HZN_VARIABLES}
@echo "making $@"
@export \
HZN_EXCHANGE_URL="$(HZN_EXCHANGE_URL)" \
HZN_ORG_ID="$(HZN_ORG_ID)" \
HZN_USER_ID="$(HZN_USER_ID)" \
&& ${MAKE} -C $@ push publish
hznmonitor: ${HZN_VARIABLES} KAFKA_APIKEY MQTT_HOST MQTT_USERNAME MQTT_PASSWORD
@echo "making $@"
@export \
BASES='base-ubuntu apache-ubuntu' \
SERVICES='hznmonitor' \
HZN_EXCHANGE_URL="$(HZN_EXCHANGE_URL)" \
HZN_ORG_ID="$(HZN_ORG_ID)" \
HZN_USER_ID="$(HZN_USER_ID)" \
&& ${MAKE} -C services push
${MAKE} -C services/hznmonitor
yolo4motion: ${HZN_VARIABLES} MQTT_HOST MQTT_USERNAME MQTT_PASSWORD
@echo "making $@"
@export \
BASES='base-ubuntu apache-ubuntu' \
SERVICES='yolo mqtt yolo4motion' \
HZN_EXCHANGE_URL="$(HZN_EXCHANGE_URL)" \
HZN_ORG_ID="$(HZN_ORG_ID)" \
HZN_USER_ID="$(HZN_USER_ID)" \
&& ${MAKE} -C services push
${MAKE} -C services/$@
face4motion: ${HZN_VARIABLES} MQTT_HOST MQTT_USERNAME MQTT_PASSWORD
@echo "making $@"
@export \
BASES='base-ubuntu apache-ubuntu' \
SERVICES='face mqtt face4motion' \
HZN_EXCHANGE_URL="$(HZN_EXCHANGE_URL)" \
HZN_ORG_ID="$(HZN_ORG_ID)" \
HZN_USER_ID="$(HZN_USER_ID)" \
&& ${MAKE} -C services push
${MAKE} -C services/$@
alpr4motion: ${HZN_VARIABLES} MQTT_HOST MQTT_USERNAME MQTT_PASSWORD
@echo "making $@"
@export \
BASES='base-ubuntu apache-ubuntu' \
SERVICES='alpr mqtt alpr4motion' \
HZN_EXCHANGE_URL="$(HZN_EXCHANGE_URL)" \
HZN_ORG_ID="$(HZN_ORG_ID)" \
HZN_USER_ID="$(HZN_USER_ID)" \
&& ${MAKE} -C services push
${MAKE} -C services/$@
## ADMINISTRIVIA
.PHONY: default exchange/config.json $(ACTIONS) services exchange agent all build hznmonitor yolo4motion face4motion alpr4motion vosk4motion