Makefile upped, dumbap not working yet, easymesh now checks enable flag

main
Jason Hawks 10 months ago
parent f7521c5bb5
commit 8795a06651

@ -7,7 +7,7 @@ include $(TOPDIR)/rules.mk
LUCI_TITLE:=LuCI Support for easymesh
LUCI_DEPENDS:= +kmod-cfg80211 +batctl-default +kmod-batman-adv +dawn +bash
PKG_VERSION:=2.8.6
PKG_VERSION:=2.8.7
include $(TOPDIR)/feeds/luci/luci.mk

@ -0,0 +1,105 @@
#!/bin/bash
set_apmode() {
AP_MODE=$(uci -q get easymesh.config.ap_mode)
if [ "$AP_MODE" = 1 ]; then
# Set a flag to indicate that we are in AP mode
# When we go to disable easymesh, we will check this flag and if it was set we restore settings
uci set easymesh.config.ap_mode_enabled=1
# Backup our configs
rm /etc/config/*.meshbak
cp /etc/config/wireless /etc/config/wireless.meshbak
cp /etc/config/network /etc/config/network.meshbak
cp /etc/config/dhcp /etc/config/dhcp.meshbak
# Disabling and stopping services not needed
for service in firewall dnsmasq odhcpd; do
if /etc/init.d/$service enabled; then
echo "Disabling and stopping $service..."
/etc/init.d/$service disable
/etc/init.d/$service stop
else
echo "$service is not enabled, skipping..."
fi
done
# Set LAN interface to DHCP client
uci del network.lan.ipaddr
uci del network.lan.netmask
uci set network.lan.proto='dhcp'
uci del network.wan
uci del network.wan6
# Fix firewall to be disabled
uci del firewall.lan.network
uci del firewall.wan.network
# Fix dhcp to be disabled
uci set dhcp.lan.ignore='1'
uci del dhcp.wan
# Fix this for proper variable name
HOSTNAME=$(uci -q get easymesh.config.hostname)
# Set netmask and gateway (assuming $netmask and $dns didn't break more stuff)
uci set system.@system[0].hostname=$HOSTNAME
# Retrieve the list of ports for network.@device[0]
LAN_PORTS=$(uci get network.@device[0].ports)
# Check if 'wan' is already in the list of ports
if echo "$LAN_PORTS" | grep -q -w 'wan'; then
echo "'wan' is already in the list of ports for lan."
else
echo "'wan' is not in the list. Adding it to lan ports..."
uci add_list network.@device[0].ports='wan'
fi
# Get the radio to be used for mesh from the config
AP_RADIO=$(uci -q get easymesh.config.apRadio)
# # Loop through the selected radios
# for CURRENT_RADIO in $AP_RADIO; do
# echo "Multiple Radio Setup, Current Radio: $CURRENT_RADIO"
# # Extact the radio number from the radio name
# wifi_num="${cur_radio#CURRENT_RADIO}"
# uci set wireless.wifinet${wifi_num}.network="lan private_router_batman"
# done
uci commit
# Tell openwrt to reload the configs
reload_config
/etc/init.d/network reload
else
# Set a flag to indicate that we are in AP mode
uci set easymesh.config.ap_mode_enabled=0
# Restore our configs
[ -f /etc/config/wireless.meshbak ] && {
mv /etc/config/wireless /etc/config/wireless.dumbap
cp /etc/config/wireless.meshbak /etc/config/wireless
}
[ -f /etc/config/network.meshbak ] && {
mv /etc/config/network /etc/config/network.dumbap
cp /etc/config/network.meshbak /etc/config/network
}
[ -f /etc/config/dhcp.meshbak ] && {
mv /etc/config/dhcp /etc/config/dhcp.dumbap
cp /etc/config/dhcp.meshbak /etc/config/dhcp
}
# Enable and start services not needed
for service in firewall dnsmasq odhcpd; do
if /etc/init.d/$service disabled; then
echo "Enabling and starting $service..."
/etc/init.d/$service enable
/etc/init.d/$service start
else
echo "$service is not disabled, skipping..."
fi
done
reload_config
/etc/init.d/network reload
fi
}

@ -4,62 +4,41 @@ clear_mesh_radio() {
# Get the radio to be used for mesh from the config
AP_RADIO=$(uci -q get easymesh.config.apRadio)
# Get the mesh name from the UCI configuration
MESH_NAME=$(uci -q get easymesh.config.mesh_id)
OLD_MESH_NAME=$(uci -q get easymesh.config.old_mesh_id)
# Check if MESH_NAME is not empty
if [ -z "$MESH_NAME" ]; then
echo "Mesh name is not set. Please check the easymesh configuration."
exit 1
if [ -z "$OLD_MESH_NAME" ]; then
echo "Old mesh name is not set. None to clear."
return;
fi
# Get the output from uci show wireless
uci_output=$(uci show wireless)
# Find the mesh network with the matching mesh_id and delete it
mesh_id=$(echo "$uci_output" | grep -o "wireless\.mesh_radio[0-9]*\.mesh_id='$MESH_NAME'")
mesh_id=$(echo "$uci_output" | grep -o "wireless\.mesh_radio[0-9]*\.mesh_id='$OLD_MESH_NAME'")
if [ ! -z "$mesh_id" ]; then
# Extract the number from the interface name
mesh_num=$(echo "$mesh_id" | grep -o "[0-9]*")
if [ "$AP_RADIO" == "all" ]; then
# Loop through all of the radios and delete the mesh networks
for radio in $(uci -X show wireless | grep wifi-device | awk -F'[.=]' '{print $2}'); do
mesh_radio=$(echo "$mesh_id" | grep -o "radio[0-9]*")
# Loop through radios and delete the mesh networks
for radio in $AP_RADIO; do
# Delete the network
uci del wireless.mesh_$radio
echo "Deleted mesh network with mesh_id '$MESH_NAME' on radio$radio"
echo "Deleted mesh network with mesh_id '$OLD_MESH_NAME' on $radio"
done
## Delete the network
#uci del wireless.mesh_radio$mesh_num
#echo "Deleted mesh network with mesh_id '$MESH_NAME' on radio$mesh_num"
elif [ "$mesh_num" == `echo "$AP_RADIO" | grep -o "[0-9]*"` ]; then
# Delete the network
uci del wireless.mesh_$mesh_num
echo "Deleted mesh network with mesh_id '$MESH_NAME' on radio$mesh_num"
else
echo "Skipping mesh network with mesh_id '$MESH_NAME' on radio$mesh_num"
fi
fi
# Find the wireless network with the matching ssid and delete it
ssid=$(echo "$uci_output" | grep -o "wireless\.wifinet[0-9]*\.ssid='$MESH_NAME'")
ssid=$(echo "$uci_output" | grep -o "wireless\.wifinet[0-9]*\.ssid='$OLD_MESH_NAME'")
if [ ! -z "$ssid" ]; then
# Extract the number from the interface name
ssid_num=$(echo "$ssid" | grep -o "[0-9]*")
if [ "$AP_RADIO" == "all" ]; then
# Loop through all of the radios and delete the wireless networks
for radio in $(uci -X show wireless | grep wifi-device | awk -F'[.=]' '{print $2}'); do
# Loop through radios and delete the wireless networks
for radio in $AP_RADIO; do
# Get the number from the radio name
radio_num="${radio#radio}"
# Delete the network
uci del wireless.wifinet$radio_num
echo "Deleted wireless network with ssid '$MESH_NAME' on radio$radio_num"
echo "Deleted wireless network with ssid '$OLD_MESH_NAME' on radio$radio_num"
done
elif [ "$ssid_num" == "`echo "$AP_RADIO" | grep -o "[0-9]*"`" ]; then
# Delete the network
uci del wireless.wifinet$ssid_num
echo "Deleted wireless network with ssid '$MESH_NAME' on radio$ssid_num"
else
echo "Skipping wireless network with ssid '$MESH_NAME' on radio$ssid_num"
fi
fi
# Commit changes to make sure the wireless configuration is updated
@ -141,17 +120,8 @@ process_radios() {
exit 1
fi
# Determine which radios to process
if [ "$AP_RADIO" == "all" ]; then
# If 'all' is specified, get all the radios
RADIO_LIST=$(uci -X show wireless | grep wifi-device | awk -F'[.=]' '{print $2}')
else
# If a specific radio is specified, use only that radio
RADIO_LIST=$AP_RADIO
fi
# Loop through the selected radios
for CURRENT_RADIO in $RADIO_LIST; do
for CURRENT_RADIO in $AP_RADIO; do
echo "Setting up mesh networks for: $CURRENT_RADIO"
setup_mesh_radio $CURRENT_RADIO
done
@ -275,18 +245,11 @@ restart_and_reload() {
exit 1
fi
# Check to make sure if "all" is passed or a single radio
if [ "$AP_RADIO" == "all" ]; then
# If 'all' is specified, enable all radios
for radio in $(uci -X show wireless | grep wifi-device | awk -F'[.=]' '{print $2}'); do
# Enable radios
for radio in $AP_RADIO; do
echo "Enabling $radio..."
uci set wireless.$radio.disabled=0
done
else
# If a specific radio is specified, enable only that radio
echo "Enabling $AP_RADIO..."
uci set wireless.$AP_RADIO.disabled=0
fi
uci commit wireless
@ -319,135 +282,31 @@ disable_batman_interfaces() {
echo "Network configuration reloaded."
}
set_apmode() {
AP_MODE=$(uci -q get easymesh.config.ap_mode)
if [ "$AP_MODE" = 1 ]; then
# Set a flag to indicate that we are in AP mode
# When we go to disable easymesh, we will check this flag and if it was set we restore settings
uci set easymesh.config.ap_mode_enabled=1
# Backup our configs
rm /etc/config/*.meshbak
cp /etc/config/wireless /etc/config/wireless.meshbak
cp /etc/config/network /etc/config/network.meshbak
cp /etc/config/dhcp /etc/config/dhcp.meshbak
# Disabling and stopping services not needed
for service in firewall dnsmasq odhcpd; do
if /etc/init.d/$service enabled; then
echo "Disabling and stopping $service..."
/etc/init.d/$service disable
/etc/init.d/$service stop
else
echo "$service is not enabled, skipping..."
fi
done
# Set LAN interface to DHCP client
uci del network.lan.ipaddr
uci del network.lan.netmask
uci set network.lan.proto='dhcp'
uci del network.wan
uci del network.wan6
# Fix firewall to be disabled
uci del firewall.lan.network
uci del firewall.wan.network
# Fix dhcp to be disabled
uci set dhcp.lan.ignore='1'
uci del dhcp.wan
# Fix this for proper variable name
HOSTNAME=$(uci -q get easymesh.config.hostname)
# Set netmask and gateway (assuming $netmask and $dns didn't break more stuff)
uci set system.@system[0].hostname=$HOSTNAME
# Retrieve the list of ports for network.@device[0]
LAN_PORTS=$(uci get network.@device[0].ports)
# Check if 'wan' is already in the list of ports
if echo "$LAN_PORTS" | grep -q -w 'wan'; then
echo "'wan' is already in the list of ports for lan."
else
echo "'wan' is not in the list. Adding it to lan ports..."
uci add_list network.@device[0].ports='wan'
fi
# Get the radio to be used for mesh from the config
AP_RADIO=$(uci -q get easymesh.config.apRadio)
# Determine which radios to process
if [ "$AP_RADIO" == "all" ]; then
# If 'all' is specified, get all the radios
RADIO_LIST=$(uci -X show wireless | grep wifi-device | awk -F'[.=]' '{print $2}')
else
# If a specific radio is specified, use only that radio
RADIO_LIST=$AP_RADIO
fi
# # Loop through the selected radios
# for CURRENT_RADIO in $RADIO_LIST; do
# echo "Multiple Radio Setup, Current Radio: $CURRENT_RADIO"
# # Extact the radio number from the radio name
# wifi_num="${cur_radio#CURRENT_RADIO}"
# uci set wireless.wifinet${wifi_num}.network="lan private_router_batman"
# done
uci commit
# Tell openwrt to reload the configs
reload_config
/etc/init.d/network reload
else
# Set a flag to indicate that we are in AP mode
uci set easymesh.config.ap_mode_enabled=0
# Restore our configs
[ -f /etc/config/wireless.meshbak ] && {
mv /etc/config/wireless /etc/config/wireless.dumbap
cp /etc/config/wireless.meshbak /etc/config/wireless
}
[ -f /etc/config/network.meshbak ] && {
mv /etc/config/network /etc/config/network.dumbap
cp /etc/config/network.meshbak /etc/config/network
}
[ -f /etc/config/dhcp.meshbak ] && {
mv /etc/config/dhcp /etc/config/dhcp.dumbap
cp /etc/config/dhcp.meshbak /etc/config/dhcp
}
# Enable and start services not needed
for service in firewall dnsmasq odhcpd; do
if /etc/init.d/$service disabled; then
echo "Enabling and starting $service..."
/etc/init.d/$service enable
/etc/init.d/$service start
else
echo "$service is not disabled, skipping..."
fi
done
reload_config
/etc/init.d/network reload
fi
}
# Enable easymesh
enable_easymesh() {
# Clear old radios then set "old values"
clear_mesh_radio
uci set easymesh.config.old_mesh_id="$(uci -q get easymesh.config.mesh_id)"
create_batman_network
process_radios
restart_and_reload
# Set at end to be sure it worked
uci set easymesh.config.running=1
}
# Disable easymesh
disable_easymesh() {
# Clear old radios then clear "old values"
clear_mesh_radio
uci del easymesh.config.old_mesh_id
disable_batman_interfaces
# Set at end to be sure it worked
uci del easymesh.config.running
}
# Check if enabled
if [ "$(uci -q get easymesh.config.enabled)" = 0 ]; then
echo "Easymesh is disabled, exiting."
exit 1
if [ "$(uci -q get easymesh.config.enabled)" = 1 ]; then
enable_easymesh
else
disable_easymesh
fi

Loading…
Cancel
Save