#!/bin/sh

# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2009-2014 Stephan Raue (stephan@openelec.tv)

# creating initial settings file
  if [ ! -f /storage/.cache/connman/settings ]; then
    mkdir -p /storage/.cache/connman
      cp /usr/share/connman/settings /storage/.cache/connman
  fi

# set variable for connman main.conf location
  if [ -f /storage/.config/connman_main.conf ]; then
    export CONNMAN_MAIN="--config=/storage/.config/connman_main.conf"
  else
    export CONNMAN_MAIN="--config=/etc/connman/main.conf"
  fi

# switch resolv.conf management to connman and use current contents
# as a fallback
if [ -f /run/libreelec/resolv.conf ]; then
  cat /run/libreelec/resolv.conf > /run/connman/resolv.conf
fi
rm -f /run/libreelec/resolv.conf
ln -s /run/connman/resolv.conf /run/libreelec/resolv.conf
