#!/bin/sh
parodus_port=16014
aker_port=16015
mocktr181_port=16016

if [[ -z "${URL}" ]]; then
    URL="http://petasos:6400"
fi

if [[ -z "${FIRMWARE}" ]]; then
    FIRMWARE="mock-rdkb-firmware"
fi

if [[ -z "${BOOT_TIME}" ]]; then
    BOOT_TIME=`date +%s`
fi

if [[ -z "${HW_MANUFACTURER}" ]]; then
    HW_MANUFACTURER="Example Inc."
fi

if [[ -z "${REBOOT_REASON}" ]]; then
    REBOOT_REASON="unknown"
fi

if [[ -z "${SERIAL_NUMBER}" ]]; then
    SERIAL_NUMBER="mock-rdkb-simulator"
fi

if [[ -z "${PARTNER_ID}" ]]; then
    PARTNER_ID="comcast"
fi

if [[ -z "${CMAC}" ]]; then
    CMAC="112233445566"
fi

#In this docker-compose cluster, themis has mtls disabled so
#feel free to ignore the --client-cert-path flag value
#it is required by parodus to fetch a token

parodus --hw-model=aker-testing \
        --ssl-cert-path=/etc/ssl/certs/ca-certificates.crt \
        --client-cert-path=/etc/ssl/certs/ca-certificates.crt \
        --hw-serial-number=$SERIAL_NUMBER \
        --hw-manufacturer=$HW_MANUFACTURER \
        --hw-mac=$CMAC \
        --hw-last-reboot-reason=$REBOOT_REASON \
        --fw-name=$FIRMWARE \
        --boot-time=$BOOT_TIME \
        --partner-id=$PARTNER_ID \
        --parodus-local-url=tcp://127.0.0.1:$parodus_port \
        --webpa-ping-timeout=60 \
        --token-server-url=http://themis:6501/issue \
        --webpa-backoff-max=2 \
        --webpa-interface-used=eth0 \
        --webpa-url=$URL \
        --force-ipv4  &
P1=$!

aker -p tcp://127.0.0.1:$parodus_port \
     -c tcp://127.0.0.1:$aker_port \
     -w echo \
     -d /tmp/aker-data.msgpack \
     -f /tmp/aker-data.msgpack.md5 \
     -m 128 > /dev/null &
P2=$!

mock_tr181 -p $parodus_port \
           -c $mocktr181_port \
           -d /etc/mock_tr181.json > /dev/null &
P3=$!

wait $P1 $P2 $P3
