#!/bin/sh

# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2016-present Team LibreELEC (https://libreelec.tv)

f="/storage/.kodi/userdata/addon_data/service.system.inadyn/settings.xml"
[ -f "$f" ] && sed -i 's/inadyn_s/inadyn_c/g' "$f"

. /etc/profile
oe_setup_addon service.system.inadyn

if [ "$inadyn_S" == "inadyn.conf" ]; then
  config="$ADDON_HOME/inadyn.conf"
else
  config="$ADDON_HOME/inadyn.temp"
  if [ -z "$inadyn_a" -o -z "$inadyn_p" -o -z "$inadyn_u" ]; then
    rm -fr "$config"
  else
    echo "\
provider $inadyn_S {
   ssl      = $inadyn_c
   username = $inadyn_u
   password = $inadyn_p
   hostname = $inadyn_a
}" >"$config"
  fi
fi

if [ -f "$config" ]; then
  inadyn -f "$config" -l info
fi
