OpenMTC/ipes/CUL868IPE/docker/configure-cul868ipe-and-start
2018-10-14 17:03:08 +02:00

68 lines
1.8 KiB
Bash
Executable File

#!/usr/bin/env bash
CONFIG_FILE="/etc/openmtc/cul868ipe/config.json"
NAME=${NAME-"CUL868IPE"}
EP=${EP-"http://localhost:8000"}
CSE_BASE=${CSE_BASE-"onem2m"}
POAS=${POAS-'["http://auto:28728"]'}
ORIGINATOR_PRE=${ORIGINATOR_PRE-"//openmtc.org/mn-cse-1"}
SSL_CRT=${SSL_CRT-"/etc/openmtc/certs/cul868ipe.cert.pem"}
SSL_KEY=${SSL_KEY-"/etc/openmtc/certs/cul868ipe.key.pem"}
SSL_CA=${SSL_CA-"/etc/openmtc/certs/ca-chain.cert.pem"}
SIM=${SIM-false}
SIM_PERIOD=${SIM_PERIOD-300}
CUL_DEVICE=${CUL_DEVICE-"/dev/ttyACM0"}
DEVICES=${DEVICES-'["s300th:1", "fs20:16108-1"]'}
DEVICE_MAPPINGS=${DEVICE_MAPPINGS-'{}'}
# defaults logging
LOGGING_FILE=${LOGGING_FILE-"/var/log/openmtc/cul868ipe.log"}
LOGGING_LEVEL=${LOGGING_LEVEL-"ERROR"}
# ensure correct level
case ${LOGGING_LEVEL} in
FATAL|ERROR|WARN|INFO|DEBUG)
;;
*)
LOGGING_LEVEL="ERROR"
;;
esac
# local ip
LOCAL_IP=$(ip r get 8.8.8.8 | awk 'NR==1 {print $NF}')
# set hostname
HOST_NAME=${EXTERNAL_IP-${LOCAL_IP}}
# Configuration of the service.
CONFIG_TEMP=${CONFIG_FILE}".tmp"
echo -n "Configuring M2M cul868ipe..."
JQ_STRING='.'
# basics
JQ_STRING=${JQ_STRING}' |
.name = "'${NAME}'" |
.ep = "'${EP}'" |
.device_mappings = '''${DEVICE_MAPPINGS}''' |
.cse_base = "'${CSE_BASE}'" |
.poas = '${POAS}' |
.originator_pre = "'${ORIGINATOR_PRE}'" |
.ssl_certs.cert_file = "'${SSL_CRT}'" |
.ssl_certs.key_file = "'${SSL_KEY}'" |
.ssl_certs.ca_certs = "'${SSL_CA}'" |
.sim = '${SIM}' |
.sim_period = "'${SIM_PERIOD}'" |
.cul_device = "'${CUL_DEVICE}'" |
.devices = '${DEVICES}' |
.logging.file |= "'${LOGGING_FILE}'" |
.logging.level |= "'${LOGGING_LEVEL}'"
'
cat ${CONFIG_FILE} | jq -M "${JQ_STRING}"> ${CONFIG_TEMP}
mv ${CONFIG_TEMP} ${CONFIG_FILE}
echo "done"
exec python3 -m cul868ipe $@