#!/bin/bash
#
# .---. . .
# | | |
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
#
# Freedom in the Cloud
#
# Select the mesh routing protocol
#
# License
# =======
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see .
PROJECT_NAME='freedombone'
export TEXTDOMAIN=${PROJECT_NAME}-mesh-routing
export TEXTDOMAINDIR="/usr/share/locale"
source /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-wifi
source /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-mesh
bmx6_peers=$(avahi-browse -at | grep routing | grep bmx6 | wc -l)
olsr2_peers=$(avahi-browse -at | grep routing | grep olsr2 | wc -l)
data=$(zenity --list 1 $"BMX6 ($bmx6_peers)" 2 $"OLSR2 ($olsr2_peers)" $"Select Mesh Protocol" --column="id" --title $"Mesh Protocol" --column=$"Choose the mesh protocol:" --hide-column=1 --print-column=1 --height=150)
sel=$?
case $sel in
1) exit 1;;
255) exit 1;;
esac
echo '#!/bin/bash' > /tmp/change_routing
echo "echo '$1' > $MESH_DEFAULT_PROTOCOL" >> /tmp/change_routing
echo "echo '$1' > $MESH_CURRENT_PROTOCOL" >> /tmp/change_routing
echo "sed -i 's|.*|_${1}._tcp|g' /etc/avahi/services/routing.service" >> /tmp/change_routing
echo 'systemctl restart avahi-daemon' >> /tmp/change_routing
chmod +x /tmp/change_routing
clear
echo ''
echo $'Authentication to change mesh protocol'
echo ''
case $data in
1) sudo /tmp/change_routing 'bmx6'
sudo systemctl stop bmx7
sudo systemctl disable bmx7
sudo systemctl stop olsr2
sudo systemctl disable olsr2
sudo systemctl enable bmx6
sudo systemctl start bmx6
;;
2) sudo /tmp/change_routing 'olsr2'
sudo systemctl stop bmx7
sudo systemctl disable bmx7
sudo systemctl stop bmx6
sudo systemctl disable bmx6
sudo systemctl enable olsr2
sudo systemctl start olsr2
;;
esac
rm /tmp/change_routing
exit 0