-
Notifications
You must be signed in to change notification settings - Fork 5
/
entrypoint.sh
executable file
·120 lines (97 loc) · 2.86 KB
/
entrypoint.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
#!/usr/bin/env bash
if [[ ! -z "$DEBUG_ENTRY" ]]; then
set -x
fi
cleanup() {
if [[ $pid -gt 0 ]]; then
kill $pid
fi
service bluetooth stop
service dbus stop
exec echo
}
trap "cleanup" EXIT INT TERM
service dbus start
service bluetooth start
touch "${PREF_CONFIG_DIR}/.public_name_cache"
# create config files
## address_blacklist
if [[ ! -f "/${PREF_CONFIG_DIR}/address_blacklist" ]]; then
tee "/${PREF_CONFIG_DIR}/address_blacklist" > /dev/null <<EOF
#LIST MAC ADDRESSES TO IGNORE, ONE PER LINE:
${ADDRESS_BLACKLIST}
EOF
fi
## behavior_preferences
if [[ ! -f "/${PREF_CONFIG_DIR}/behavior_preferences" ]]; then
tee "/${PREF_CONFIG_DIR}/behavior_preferences" > /dev/null <<EOF
# ---------------------------
#
# BEHAVIOR PREFERENCES
#
# ---------------------------
# Note: For docker by default we will just expect these to be container environment variables
EOF
fi
## known_beacon_addresses
if [[ ! -f "/${PREF_CONFIG_DIR}/known_beacon_addresses" ]]; then
tee "/${PREF_CONFIG_DIR}/known_beacon_addresses" > /dev/null <<EOF
# ---------------------------
#
# BEACON MAC ADDRESS LIST; REQUIRES NAME
#
# Format: 00:00:00:00:00:00 Nickname #comments
# ---------------------------
${KNOWN_BEACON_ADDRESSES}
EOF
fi
## known_static_addresses
if [[ ! -f "/${PREF_CONFIG_DIR}/known_static_addresses" ]]; then
tee "/${PREF_CONFIG_DIR}/known_static_addresses" > /dev/null <<EOF
# ---------------------------
#
# STATIC MAC ADDRESS LIST
#
# 00:00:00:00:00:00 Alias #comment
# ---------------------------
${KNOWN_STATIC_ADDRESSES}
EOF
fi
## known_static_addresses
if [[ ! -f "/${PREF_CONFIG_DIR}/mqtt_preferences" ]]; then
tee "/${PREF_CONFIG_DIR}/mqtt_preferences" > /dev/null <<EOF
# ---------------------------
#
# MOSQUITTO PREFERENCES
#
# ---------------------------
# IP ADDRESS OR HOSTNAME OF MQTT BROKER
mqtt_address="\${MQTT_ADDRESS}"
# MQTT BROKER USERNAME
mqtt_user="\${MQTT_USER}"
# MQTT BROKER PASSWORD
mqtt_password="\${MQTT_PASSWORD}"
# MQTT PUBLISH TOPIC ROOT
mqtt_topicpath="\${MQTT_TOPICPATH}"
# PUBLISHER IDENTITY
mqtt_publisher_identity="\${MQTT_PUBLISHER_IDENTITY}"
# MQTT PORT
mqtt_port="\${MQTT_PORT}"
# MQTT CERTIFICATE FILE
mqtt_certificate_path="\${MQTT_CERTIFICATE_PATH}"
#MQTT VERSION (EXAMPLE: 'mqttv311')
mqtt_version="\${MQTT_VERSION}"
EOF
fi
# write out the timestamp of the last msg received
date +%s > last_msg
while true; do [[ -e main_pipe ]] && read line < main_pipe && date +%s > last_msg; done &
# if first parameter is a valid command, then we will execute that
# otherwise we will just send all the parameters to monitor.sh
if [[ ! -z "$1" ]] && [[ ${1:0:1} != "-" ]] && ( [[ -f "$1" ]] || command -v "$1" &> /dev/null ); then
"${@}"
exit $?
else
monitor "${@}"
exit $?
fi