#!/bin/sh
#
# Copyright (C) 2015 - 2016 devolo AG
#

if [ -f /lib/ar71xx.sh ]; then
        PLATFORM=ar71xx
        . /lib/ar71xx.sh
elif [ -f /lib/ipq806x.sh ]; then
        PLATFORM=ipq806x
        . /lib/ipq806x.sh
fi

. /lib/functions.sh
MIG_AVAIL=0
if [ -e /rom/lib/migration/migration.sh ]; then
    MIG_AVAIL=1
    cp -af /rom/lib/migration/migration.sh /lib/migration/migration.sh
    . /lib/migration/migration.sh
fi

# install config sections. Add new sections here so options can be added
# by other scripts with a simple "uci set delos.section.option=val"
uci -q get delos.uci_defaults || {
    uci set delos.uci_defaults=uci_defaults
    uci -q get delos.delos.version || {
        uci set delos.delos=configuration
        uci set delos.delos.version=$(cat /etc/delos-version | 
                                      grep CONFIG_VERSION |
                                      awk -F'=' '{print $2}')
    }
}
uci -q get delos.error || uci set delos.error=error

[ "$(uci changes delos | wc -l)" = "0" ] || uci commit delos

board=$(${PLATFORM}_board_name)

case "$board" in
dlan*|\
dvl-*|\
ew7479cap|\
ap-dk07.1-c1)
   uci_set_state delos error state 0
   [ "$MIG_AVAIL" = "1" ] && updateUciDefaultsScript
   ;;
esac

exit 0