#!/bin/bash

set -e

if [ $(id -u) -ne 0 ]; then
	echo "Please run as root. - sudo su"
	exit
elif [ $1 == "help" ]; then
    echo "Please input parameter. follow as:"
    echo "Example) Organzation ID=58a311aa-f52a-40e3-af44-cdec82b9d0b7 SerialNumbe=ECN-SJ-TEST-001 Type=ecn"
    exit
fi

echo "If you need help, please enter follow as:"
echo "./init.sh help"
read -p "Organzation ID(58a311aa-f52a-40e3-af44-cdec82b9d0b7): " oid
read -p "Serial Number(ECN-SJ-TEST-001): " acode
read -p "Type(ecn or nodeq): " etype

echo "[INIT] [1] Start equipment registration"
./bwc-init -oid=$oid -acode=$acode
echo "[INIT] [1] Finish equipment registration"

echo "[INIT] [2] Start install device-control"
cd device-control
./install.sh $acode $etype
mkdir -p /usr/local/sdt/app
echo "[INIT] [2] Finish install device-control"

echo "[INIT] [3] Start install device-health"
cd ../device-health
./install.sh $acode
echo "[INIT] [3] Finish install device-health"

echo "[INIT] [4] Start install device-heartbeat"
cd ../heartbeat
./install.sh
echo "[INIT] [4] Finish install device-heartbeat"

echo "[INIT] [5] Start install process-checker"
cd ../process-checker
./install.sh
echo "[INIT] [5] Stop install process-checker"