#!/bin/sh
[ -f "$UCI_CONFIG_DIR/stunnel" ] || exit 0

. /lib/functions.sh

change_options() {
    uci_rename "stunnel" "${1}" "_cipher_type" "cipher_type"
    config_get connect "$1" "connect" ""
    config_get _connect "$1" "_connect" ""
    if [ -z "$connect" ]; then
        uci_rename "stunnel" "${1}" "_connect" "connect"
    else
        [ -n "$_connect" ] && uci_remove "stunnel" "$1" "_connect"
    fi
}

config_load "stunnel"
config_foreach change_options "service"
uci_commit stunnel
