You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
194 lines
5.4 KiB
Plaintext
194 lines
5.4 KiB
Plaintext
4 years ago
|
#!/bin/sh
|
||
|
|
||
|
#TODO: debugging
|
||
|
#logfile="/tmp/`basename $0`.log"
|
||
|
#exec 3<> "$logfile"
|
||
|
#exec >&3
|
||
|
#exec 2>&3
|
||
|
|
||
|
#set -x
|
||
|
|
||
|
. /lib/functions.sh
|
||
|
. /usr/lib/configsync_lib.sh
|
||
|
|
||
|
SERVICE=wireless
|
||
|
PSERVICE=${CS_PREFIX}${SERVICE}
|
||
|
RADIO=wifi
|
||
|
CS_SERVICE=$1; shift
|
||
|
|
||
|
my_logger() {
|
||
|
logger -t configsync_executor "${CS_SERVICE}" "${@}"
|
||
|
}
|
||
|
|
||
|
configsync_to_system()
|
||
|
{
|
||
|
my_logger "This is ${0}/configsync_to_system()!"
|
||
|
|
||
|
CS_RADIO=$1
|
||
|
CS_HWMODE=$2
|
||
|
|
||
|
# === radio options ===
|
||
|
|
||
|
hwmode=
|
||
|
I=0
|
||
|
while uci_tmp get ${PSERVICE}."$RADIO"$I >/dev/null 2>&1
|
||
|
do
|
||
|
device="$RADIO"$I
|
||
|
if [ "$( uci_tmp get ${PSERVICE}.$device.hwmode )" = $CS_HWMODE ] ; then
|
||
|
hwmode=$CS_HWMODE
|
||
|
break
|
||
|
fi
|
||
|
|
||
|
I=$((I+1))
|
||
|
done
|
||
|
|
||
|
if [ -z "$hwmode" ] ; then
|
||
|
my_logger "INFO: no $CS_RADIO GHz radio found. Exiting."
|
||
|
return 1
|
||
|
fi
|
||
|
|
||
|
# make working copy and get values from there step by step
|
||
|
uci_tmp revert $CS_SERVICE
|
||
|
uci_cs export $CS_SERVICE | uci_tmp import $CS_SERVICE
|
||
|
|
||
|
# Note: UCI lists are not supported by this construct. They are
|
||
|
# awkward in handling anyways and thus should not be used if
|
||
|
# possible.
|
||
|
# TODO: complete the set of options
|
||
|
synced_options="htmode
|
||
|
disabled
|
||
|
cfg_disabled
|
||
|
country"
|
||
|
for synced_option in $synced_options; do
|
||
|
VALUE="$( uci_tmp get ${CS_SERVICE}.radio.$synced_option )"
|
||
|
uci_tmp set ${PSERVICE}.$device.$synced_option="$VALUE"
|
||
|
done
|
||
|
|
||
|
|
||
|
# === iface options ===
|
||
|
|
||
|
synced_options="device
|
||
|
disabled
|
||
|
ssid
|
||
|
encryption
|
||
|
key
|
||
|
dvl_main
|
||
|
dvl_guest
|
||
|
network
|
||
|
mode
|
||
|
wds
|
||
|
ieee80211w
|
||
|
wps_config
|
||
|
uapsd
|
||
|
rrm
|
||
|
wnm
|
||
|
rsn_preauth
|
||
|
ieee80211r
|
||
|
hidden
|
||
|
isolate
|
||
|
maxassoc
|
||
|
wps_config"
|
||
|
|
||
|
# Note: UCI lists are not supported by this construct
|
||
|
# TODO: check the set of options
|
||
|
|
||
|
# loop system configuration: delete deleted interfaces (SSID|MODE)
|
||
|
J=0
|
||
|
while uci_tmp get ${PSERVICE}.@wifi-iface[$J]
|
||
|
do
|
||
|
DELETE=1
|
||
|
P_SSID="$( uci_tmp get ${PSERVICE}.@wifi-iface[$J].ssid )"
|
||
|
P_MODE="$( uci_tmp get ${PSERVICE}.@wifi-iface[$J].mode )"
|
||
|
iface_device="$( uci_tmp get ${PSERVICE}.@wifi-iface[$J].device )"
|
||
|
|
||
|
if [ "$device" = "$iface_device" ]; then
|
||
|
I=0
|
||
|
while uci_tmp get ${CS_SERVICE}.@wifi-iface[$I]
|
||
|
do
|
||
|
CS_SSID="$( uci_tmp get ${CS_SERVICE}.@wifi-iface[$I].ssid )"
|
||
|
CS_MODE="$( uci_tmp get ${CS_SERVICE}.@wifi-iface[$I].mode )"
|
||
|
if [ "${P_SSID}" = "${CS_SSID}" ] && [ "${P_MODE}" = "${CS_MODE}" ]; then
|
||
|
DELETE=0
|
||
|
break
|
||
|
fi
|
||
|
I=$((I+1))
|
||
|
done
|
||
|
else
|
||
|
DELETE=0
|
||
|
fi
|
||
|
|
||
|
if [ $DELETE -eq 1 ]; then
|
||
|
uci_tmp delete $PSERVICE.@wifi-iface[$J]
|
||
|
else
|
||
|
J=$((J+1))
|
||
|
fi
|
||
|
done
|
||
|
|
||
|
|
||
|
# loop cs configuration: and merge known interfaces and add new interfaces (SSID|MODE)
|
||
|
I=0
|
||
|
while uci_tmp get ${CS_SERVICE}.@wifi-iface[$I]
|
||
|
do
|
||
|
CS_SSID="$( uci_tmp get ${CS_SERVICE}.@wifi-iface[$I].ssid )"
|
||
|
CS_MODE="$( uci_tmp get ${CS_SERVICE}.@wifi-iface[$I].mode )"
|
||
|
|
||
|
# loop temp configuration
|
||
|
FOUND=0
|
||
|
J=0
|
||
|
while uci_tmp get ${PSERVICE}.@wifi-iface[$J]
|
||
|
do
|
||
|
iface_device="$( uci_tmp get ${PSERVICE}.@wifi-iface[$J].device )"
|
||
|
|
||
|
# delete interface if device not available (corrupt configuration)
|
||
|
if [ "$iface_device" = "" ]; then
|
||
|
uci_tmp delete $PSERVICE.@wifi-iface[$J]
|
||
|
continue
|
||
|
fi
|
||
|
|
||
|
# search interface in temp configuration
|
||
|
if [ "$device" = "$iface_device" ]; then
|
||
|
P_SSID="$( uci_tmp get ${PSERVICE}.@wifi-iface[$J].ssid )"
|
||
|
P_MODE="$( uci_tmp get ${PSERVICE}.@wifi-iface[$J].mode )"
|
||
|
if [ "${P_SSID}" = "${CS_SSID}" ] && [ "${P_MODE}" = "${CS_MODE}" ]; then
|
||
|
# if ssid found -> merge
|
||
|
for synced_option in $synced_options; do
|
||
|
VALUE="$( uci_tmp get ${CS_SERVICE}.@wifi-iface[$I].$synced_option )"
|
||
|
uci_tmp set ${PSERVICE}.@wifi-iface[$J].$synced_option="$VALUE"
|
||
|
done
|
||
|
FOUND=1
|
||
|
break
|
||
|
fi
|
||
|
fi
|
||
|
J=$((J+1))
|
||
|
done
|
||
|
|
||
|
if [ $FOUND -eq 0 ]; then
|
||
|
# if ssid not found -> add
|
||
|
local entry=$(uci_tmp add ${PSERVICE} wifi-iface)
|
||
|
for synced_option in $synced_options; do
|
||
|
VALUE="$( uci_tmp get ${CS_SERVICE}.@wifi-iface[$I].$synced_option )"
|
||
|
uci_tmp set ${PSERVICE}.$entry.$synced_option="$VALUE"
|
||
|
done
|
||
|
fi
|
||
|
I=$((I+1))
|
||
|
done
|
||
|
|
||
|
add_to_list $CS_IMPORTSERVICELIST ${SERVICE}
|
||
|
}
|
||
|
|
||
|
dynamic_update()
|
||
|
{
|
||
|
my_logger "This is ${0}/dynamic_update()!"
|
||
|
}
|
||
|
|
||
|
init()
|
||
|
{
|
||
|
my_logger "This is ${0}/init()!"
|
||
|
}
|
||
|
|
||
|
if [ "${1}" = "init" ] || [ "${1}" = "configsync_to_system" ] || [ "${1}" = "dynamic_update" ]; then
|
||
|
"${@}"
|
||
|
else
|
||
|
my_logger "Unknown command ${1} in ${0}!"
|
||
|
fi
|