#!/bin/sh

[ -f /etc/customization.sh ] && . /etc/customization.sh

. /lib/functions.sh
. /lib/delos-functions.sh

ARG_FORCE="$1"

apply_configured_variant() {
    local execute="$1"

    local configured="$(uci_get customization config active_variant)"
    local current="$_DVL_ACTIVE_VARIANT"

    [ -n "$configured" ] && [ "$configured" != "$current" ] && execute=1

    if [ -n "$execute" ]; then
        local srcdir=/usr/share/delos-customization/variant-"$configured"
        [ -f "$srcdir"/customization.sh ] && . "$srcdir"/customization.sh

        ln -sf "$srcdir"/customization.sh /etc
        ln -sf "$srcdir"/webui/customization.css /www

        dvl_insert_customization_info "$srcdir"/webui customization.json /www
        dvl_insert_customization_info /etc device_info
        dvl_insert_customization_info /etc banner

        [ -d /www/licenses ] || mkdir -p /www/licenses
        ln -sf /usr/share/licenses/oss-license-info-"$_DVL_OSS_LICENSE_INFO".html /www/licenses/oss-license-info.html
    fi
}

apply_configured_variant "$ARG_FORCE"

exit 0
