#!/bin/sh
#
# Copyright (C) 2018 devolo AG
#

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

# configure logging 1:
mkdir -p /www/app/components/status/logs

# If no root password has been set, give root an empty password.
# This allows SSH access after factory reset (if bootenv variable
# Ssh=1 is set).
grep '^root::' /etc/shadow && { echo -en "\n\n" | passwd root; }

# if basic configuration was already applied, exit
[ "$(uci -q get delos.uci_defaults.system)" = "" ] || exit 0

. /lib/functions.sh

# default hostname
PREFIX="${_DVL_HOSTNAME_PREFIX:-devolo-}"
SN=$(uci_get_state delos baptization SerialNumber)
if [ -n "$SN" ]; then
    uci set system.@system[0].hostname=${PREFIX}${SN:$((-3))}
else
    uci set system.@system[0].hostname=${PREFIX}
fi

# change default timezone from UTC to Europe/Berlin (should match zone definition of webui)
uci set system.@system[0].zonename='Europe/Berlin'
uci set system.@system[0].timezone='CET-1CEST,M3.5.0,M10.5.0/3'

# configure logging 2:
uci set system.@system[0].log_buffer_size=512
uci set system.@system[0].log_type=circular_file
uci set system.@system[0].log_webui=/www/app/components/status/logs/log
uci commit system

# set basic config done flag
uci set delos.uci_defaults.system=1
uci commit delos

exit 0