#!/bin/bash set -e . /etc/wb_env.sh wb_source "of" if of_machine_match "wirenboard,wirenboard-8xx"; then CONF_SUFFIX="wb8" elif of_machine_match "wirenboard,wirenboard-74x"; then CONF_SUFFIX="wb74" elif of_machine_match "wirenboard,wirenboard-720"; then CONF_SUFFIX="wb7" elif of_machine_match "contactless,imx6ul-wirenboard60"; then CONF_SUFFIX="wb6" elif of_machine_match "contactless,imx28-wirenboard50"; then CONF_SUFFIX="wb5" else CONF_SUFFIX="default" fi BOARD_CONF="/usr/share/wb-mqtt-homeui/config.${CONF_SUFFIX}.json" CONFFILE="/etc/wb-webui.conf" function convert_config() { TMPFILE=`mktemp` mqtt-get-dump "/config/#" > $TMPFILE NEW_CONFFILE=`mktemp` /usr/lib/wb-mqtt-homeui/convert_config_v1v2 $TMPFILE $NEW_CONFFILE if [ -e $CONFFILE ] && ! `cmp --silent $CONFFILE $NEW_CONFFILE`; then mv $CONFFILE $CONFFILE.bak fi mv $NEW_CONFFILE $CONFFILE rm $TMPFILE } function install_default_config() { ucf --debconf-ok $BOARD_CONF $CONFFILE } function is_config_untouched() { for fname in $(ls /usr/share/wb-mqtt-homeui/config.*.json); do diff -q $CONFFILE $fname && return 0 done return 1 } case "$1" in configure) OLD_VERSION="$2" if [ "$OLD_VERSION" = "" ]; then # fresh install # if conffile (i.e. v2) is present, do nothing if [ ! -e "$CONFFILE" ]; then #check if old config is present if [ ! `mqtt-get-dump '/config/#' | wc -l` = "0" ]; then convert_config else install_default_config fi fi else if `dpkg --compare-versions "${OLD_VERSION}" "lt" "2.0~beta9"`; then convert_config else if is_config_untouched; then cp $BOARD_CONF $CONFFILE else install_default_config fi fi fi ;; esac exit 0