#!/bin/bash
set -u

IPMAN_LIB_PATH="$(dirname ${BASH_SOURCE[0]})/../lib/lwr/ipman"
source ${IPMAN_LIB_PATH}/events.sh

ipman_init() {
    mkdir -p $(dirname ${IPMAN_CONFIG_CHANGED_FILE})
    touch ${IPMAN_CONFIG_CHANGED_FILE}
    touch ${IPMAN_STATUS_CHANGED_FILE}

    ${IPMAN_LIB_PATH}/ipman-apply "${@}"
    ret=$?
    touch ${IPMAN_INIT_DONE_FILE} #init-done signals the end of init (even if it was a failure)

    if [[ ${ret} -ne 0 ]]; then
        echo "Could not init with parameters: "${@}"!"
        return 1
    fi
}

ipman_init "${@}"