configure-node.sh 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/bin/bash
  2. function cmd()
  3. {
  4. echo "$@" | nc -q1 192.168.1.1 23 > /dev/null
  5. }
  6. hostname=$1
  7. owner=$2
  8. latitude=$3
  9. longitude=$4
  10. [ -z "$hostname" ] && { echo "USAGE: $0 <hostname> <owner> [<latitude> <longitude>]"; exit 1; }
  11. [ -z "$owner" ] && { echo "ERROR: need at least hostname and owner as params"; exit 1; }
  12. if [ "$IDid" != "ReadTheScript" ]; then
  13. echo "WORK IN PROGRESS: Dieses Skript ist noch nicht fertig und tut nicht was es soll."
  14. echo "Die uci-set Kommandos werden scheinbar nicht ausgeführt!"
  15. exit 42
  16. fi
  17. mac=`echo "lua -e 'print(require(\"gluon.sysconfig\").primary_mac)'" | nc -q1 192.168.1.1 23 | grep -o '^[0-9a-fA-F\:]\{17\}'`
  18. cmd 'uci set fastd.mesh_vpn.enabled=1'
  19. cmd 'uci set fastd.mesh_vpn.secret=$(fastd --generate-key --machine-readable)'
  20. cmd 'uci commit fastd'
  21. public_key=$(echo '/etc/init.d/fastd show_key mesh_vpn' | nc -q1 192.168.1.1 23 | grep -o "[0-9a-f]\{64\}")
  22. cmd "uci set system.@system[0].hostname=${hostname}"
  23. cmd "uci commit system"
  24. loc_string=""
  25. [ "$latitude" == "0" ] && latitude=""
  26. [ "$longitude" == "0" ] && longitude=""
  27. if [ ! -z "$latitude" -a ! -z "$longitude" ]; then
  28. cmd "uci set gluon-node-info.@location[0].share_location=1"
  29. cmd "uci set gluon-node-info.@location[0].latitude=$latitude"
  30. cmd "uci set gluon-node-info.@location[0].longitude=$longitude"
  31. loc_string="# Location: $latitude $longitude"
  32. else
  33. cmd "uci set gluon-node-info.@location[0].share_location=0"
  34. fi
  35. cmd 'uci commit gluon-node-info'
  36. cmd 'uci set gluon-config-mode.@setup-mode[0].configured=1'
  37. cmd 'uci commit gluon-config-mode'
  38. cmd 'uci commit'
  39. #cmd "poweroff"
  40. echo "# Owner: $owner"
  41. echo "# MAC: $mac"
  42. [ ! -z "$loc_string" ] && echo $loc_string
  43. echo "key \"${public_key/\r/}\";"