#!/bin/sh

. /lib/functions.sh

# Get Manufacturer OUI.
oui=$(db -q get device.deviceinfo.ManufacturerOUI)
oui=$(echo "${oui}" | tr 'a-f' 'A-F')

# Get system serial number.
serial=$(db -q get device.deviceinfo.SerialNumber)

username="${oui}-${serial}"
password="iopsys"

# Get userid values
config_load obuspa
config_get user global username ""
config_get pass global password ""

# Only set if they are empty or not same
if [ -z "${user}" ] || [ "${user}" != "${username}" ]; then
    uci -q set obuspa.global.username="${username}"
fi

if [ -z "${pass}" ] || [ "${pass}" != "${password}" ]; then
    uci -q set obuspa.global.password="${password}"
fi

# No need for commit here, it is done by uci_apply_defaults().
