2018-06-30 16:20:54 +02:00
|
|
|
package runtime
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
|
|
|
|
"github.com/FreifunkBremen/freifunkmanager/ssh"
|
|
|
|
)
|
|
|
|
|
2018-08-10 17:17:00 +02:00
|
|
|
func (n *Node) SSHUpdate(sshmgmt *ssh.Manager) bool {
|
2018-07-26 14:14:23 +02:00
|
|
|
client, err := sshmgmt.ConnectTo(n.GetAddress())
|
2018-06-30 16:20:54 +02:00
|
|
|
if err != nil {
|
2018-08-10 17:17:00 +02:00
|
|
|
return false
|
2018-06-30 16:20:54 +02:00
|
|
|
}
|
|
|
|
defer client.Close()
|
|
|
|
|
2018-08-10 13:46:18 +02:00
|
|
|
if n.Hostname != n.HostnameRespondd {
|
2018-07-26 14:14:23 +02:00
|
|
|
ssh.Execute(n.Address, client, fmt.Sprintf(`
|
2018-06-30 16:20:54 +02:00
|
|
|
uci set system.@system[0].hostname='%s';
|
|
|
|
uci commit; echo $(uci get system.@system[0].hostname) > /proc/sys/kernel/hostname;`,
|
|
|
|
n.Hostname))
|
|
|
|
}
|
2018-08-10 13:46:18 +02:00
|
|
|
if n.Owner != n.OwnerRespondd {
|
2018-07-26 14:14:23 +02:00
|
|
|
ssh.Execute(n.Address, client, fmt.Sprintf(`
|
2018-06-30 16:20:54 +02:00
|
|
|
uci set gluon-node-info.@owner[0].contact='%s';
|
|
|
|
uci commit gluon-node-info;`,
|
|
|
|
n.Owner))
|
|
|
|
}
|
2018-08-10 13:46:18 +02:00
|
|
|
if !locationEqual(n.Location, n.LocationRespondd) {
|
2018-07-26 14:14:23 +02:00
|
|
|
ssh.Execute(n.Address, client, fmt.Sprintf(`
|
2018-06-30 16:20:54 +02:00
|
|
|
uci set gluon-node-info.@location[0].latitude='%f';
|
|
|
|
uci set gluon-node-info.@location[0].longitude='%f';
|
|
|
|
uci set gluon-node-info.@location[0].share_location=1;
|
|
|
|
uci commit gluon-node-info;`,
|
|
|
|
n.Location.Latitude, n.Location.Longitude))
|
|
|
|
|
|
|
|
}
|
|
|
|
runWifi := false
|
|
|
|
defer func() {
|
|
|
|
if runWifi {
|
2018-07-26 14:14:23 +02:00
|
|
|
ssh.Execute(n.Address, client, "wifi")
|
2018-06-30 16:20:54 +02:00
|
|
|
// send warning for running wifi, because it kicks clients from node
|
|
|
|
log.Warn("[cmd] wifi ", n.NodeID)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2018-07-26 14:14:23 +02:00
|
|
|
result, err := ssh.Run(n.Address, client, `
|
2018-06-30 16:20:54 +02:00
|
|
|
if [ "$(uci get wireless.radio0.hwmode | grep -c g)" -ne 0 ]; then
|
|
|
|
echo "radio0";
|
|
|
|
elif [ "$(uci get wireless.radio1.hwmode | grep -c g)" -ne 0 ]; then
|
|
|
|
echo "radio1";
|
|
|
|
fi;`)
|
|
|
|
if err != nil {
|
2018-08-10 17:17:00 +02:00
|
|
|
return true
|
2018-06-30 16:20:54 +02:00
|
|
|
}
|
|
|
|
radio := ssh.SSHResultToString(result)
|
2018-07-15 20:00:18 +02:00
|
|
|
ch := GetChannel(n.Wireless.Channel24)
|
2018-07-26 14:14:23 +02:00
|
|
|
if radio != "" && ch != nil {
|
2018-08-10 13:46:18 +02:00
|
|
|
if n.Wireless.TxPower24 != n.WirelessRespondd.TxPower24 {
|
2018-07-26 14:14:23 +02:00
|
|
|
ssh.Execute(n.Address, client, fmt.Sprintf(`
|
2018-06-30 16:20:54 +02:00
|
|
|
uci set wireless.%s.txpower='%d';
|
|
|
|
uci commit wireless;`,
|
|
|
|
radio, n.Wireless.TxPower24))
|
2018-09-01 17:46:51 +02:00
|
|
|
//runWifi = true
|
2018-06-30 16:20:54 +02:00
|
|
|
}
|
2018-08-10 13:46:18 +02:00
|
|
|
if n.Wireless.Channel24 != n.WirelessRespondd.Channel24 {
|
2018-08-24 23:34:02 +02:00
|
|
|
//ubus call hostapd.%s switch_chan '{"freq":%d}'
|
2018-07-26 14:14:23 +02:00
|
|
|
ssh.Execute(n.Address, client, fmt.Sprintf(`
|
2018-06-30 16:20:54 +02:00
|
|
|
uci set wireless.%s.channel='%d';
|
|
|
|
uci commit wireless;`,
|
2018-08-24 23:34:02 +02:00
|
|
|
//strings.Replace(radio, "radio", "client", 1), ch.Frequency,
|
2018-06-30 16:20:54 +02:00
|
|
|
radio, n.Wireless.Channel24))
|
2018-08-24 23:34:02 +02:00
|
|
|
runWifi = true
|
2018-07-15 20:00:18 +02:00
|
|
|
|
2018-06-30 16:20:54 +02:00
|
|
|
}
|
|
|
|
}
|
2018-07-26 14:14:23 +02:00
|
|
|
result, err = ssh.Run(n.Address, client, `
|
2018-06-30 16:20:54 +02:00
|
|
|
if [ "$(uci get wireless.radio0.hwmode | grep -c a)" -ne 0 ]; then
|
|
|
|
echo "radio0";
|
|
|
|
elif [ "$(uci get wireless.radio1.hwmode | grep -c a)" -ne 0 ]; then
|
|
|
|
echo "radio1";
|
|
|
|
fi;`)
|
|
|
|
if err != nil {
|
2018-08-10 17:17:00 +02:00
|
|
|
return true
|
2018-06-30 16:20:54 +02:00
|
|
|
}
|
|
|
|
radio = ssh.SSHResultToString(result)
|
2018-07-15 20:00:18 +02:00
|
|
|
ch = GetChannel(n.Wireless.Channel5)
|
2018-07-26 14:14:23 +02:00
|
|
|
if radio != "" && ch != nil {
|
2018-08-10 13:46:18 +02:00
|
|
|
if n.Wireless.TxPower5 != n.WirelessRespondd.TxPower5 {
|
2018-07-26 14:14:23 +02:00
|
|
|
ssh.Execute(n.Address, client, fmt.Sprintf(`
|
2018-06-30 16:20:54 +02:00
|
|
|
uci set wireless.%s.txpower='%d';
|
|
|
|
uci commit wireless;`,
|
|
|
|
radio, n.Wireless.TxPower5))
|
2018-09-01 17:46:51 +02:00
|
|
|
//runWifi = true
|
2018-06-30 16:20:54 +02:00
|
|
|
}
|
2018-08-10 13:46:18 +02:00
|
|
|
if n.Wireless.Channel5 != n.WirelessRespondd.Channel5 {
|
2018-08-24 23:34:02 +02:00
|
|
|
//ubus call hostapd.%s switch_chan '{"freq":%d}'
|
2018-07-26 14:14:23 +02:00
|
|
|
ssh.Execute(n.Address, client, fmt.Sprintf(`
|
2018-06-30 16:20:54 +02:00
|
|
|
uci set wireless.%s.channel='%d';
|
|
|
|
uci commit wireless;`,
|
2018-08-24 23:34:02 +02:00
|
|
|
//strings.Replace(radio, "radio", "client", 1), ch.Frequency,
|
2018-06-30 16:20:54 +02:00
|
|
|
radio, n.Wireless.Channel5))
|
2018-08-24 23:34:02 +02:00
|
|
|
runWifi = true
|
2018-06-30 16:20:54 +02:00
|
|
|
}
|
|
|
|
}
|
2018-08-10 17:17:00 +02:00
|
|
|
return true
|
2018-06-30 16:20:54 +02:00
|
|
|
}
|