#!/bin/sh

. /lib/functions.sh

find_action() {
	local sec="$1" name="$2"

	config_get action "$sec" "action"
	[ -n "$action" ] && [ "$action" = "$name" ] && eval "action_${name}=1"
}

config_load "sms_utils"
config_foreach find_action "rule" "userdefaults"

[ -z "$action_userdefaults" ] && {
	uci_add "sms_utils" "rule"
	uci_set "sms_utils" "$CONFIG_SECTION" "action" "userdefaults"
	uci_set "sms_utils" "$CONFIG_SECTION" "enabled" "1"
	uci_set "sms_utils" "$CONFIG_SECTION" "smstext" "userdefaults"
	uci_set "sms_utils" "$CONFIG_SECTION" "authorization" "password"
	uci_set "sms_utils" "$CONFIG_SECTION" "allowed_phone" "all"
	uci_set "sms_utils" "$CONFIG_SECTION" "to_other_phone" "0"
	uci_commit sms_utils
}

exit 0