#!/bin/sh

[ -f "$UCI_CONFIG_DIR/sim_switch" ] || return 1

. /lib/functions.sh

get_modem() {
	[ -z "$modem" ] && config_get modem "$1" "modem" ""
}

set_option() {
	[ "$1" != "mob1s1" ] && [ "$1" != "mob1s2" ] && return 0

	uci_set "sim_switch" "$1" "modem" "$modem"
	if [ "$1" = "mob1s1" ]; then
		uci_set "sim_switch" "$1" "position" "1"
	else
		uci_set "sim_switch" "$1" "position" "2"
	fi
	uci_add "sim_switch" "sim" "$1"
}

config_load "simcard"
config_foreach get_modem "sim"

config_load "sim_switch"
config_foreach set_option "entry"

uci_commit "sim_switch"

exit 0
